Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:28

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_STRING_PARAM_HPP
0011 #define BOOST_BEAST_STRING_PARAM_HPP
0012 
0013 #if defined(BOOST_BEAST_ALLOW_DEPRECATED) && !defined(BOOST_BEAST_DOXYGEN)
0014 
0015 
0016 #include <boost/beast/core/detail/config.hpp>
0017 #include <boost/beast/core/string.hpp>
0018 #include <boost/beast/core/static_string.hpp>
0019 #include <boost/beast/core/detail/static_ostream.hpp>
0020 #include <boost/optional.hpp>
0021 
0022 namespace boost {
0023 namespace beast {
0024 
0025 /** A function parameter which efficiently converts to string.
0026 
0027     This is used as a function parameter type to allow callers
0028     notational convenience: objects other than strings may be
0029     passed in contexts where a string is expected. The conversion
0030     to string is made using `operator<<` to a non-dynamically
0031     allocated static buffer if possible, else to a `std::string`
0032     on overflow.
0033 
0034     To use it, modify your function signature to accept
0035     `string_param` and then extract the string inside the
0036     function:
0037     @code
0038     void print(string_param s)
0039     {
0040         std::cout << s.str();
0041     }
0042     @endcode
0043 */
0044 class string_param
0045 {
0046     string_view sv_;
0047     char buf_[128];
0048     boost::optional<detail::static_ostream> os_;
0049 
0050     template<class T>
0051     typename std::enable_if<
0052         std::is_integral<T>::value>::type
0053     print(T const&);
0054 
0055     template<class T>
0056     typename std::enable_if<
0057         ! std::is_integral<T>::value &&
0058         ! std::is_convertible<T, string_view>::value
0059     >::type
0060     print(T const&);
0061 
0062     void
0063     print(string_view);
0064 
0065     template<class T>
0066     typename std::enable_if<
0067         std::is_integral<T>::value>::type
0068     print_1(T const&);
0069 
0070     template<class T>
0071     typename std::enable_if<
0072         ! std::is_integral<T>::value>::type
0073     print_1(T const&);
0074 
0075     void
0076     print_n()
0077     {
0078     }
0079 
0080     template<class T0, class... TN>
0081     void
0082     print_n(T0 const&, TN const&...);
0083 
0084     template<class T0, class T1, class... TN>
0085     void
0086     print(T0 const&, T1 const&, TN const&...);
0087 
0088 public:
0089     /// Copy constructor (disallowed)
0090     string_param(string_param const&) = delete;
0091 
0092     /// Copy assignment (disallowed)
0093     string_param& operator=(string_param const&) = delete;
0094 
0095     /** Constructor
0096 
0097         This function constructs a string as if by concatenating
0098         the result of streaming each argument in order into an
0099         output stream. It is used as a notational convenience
0100         at call sites which expect a parameter with the semantics
0101         of a @ref string_view.
0102 
0103         The implementation uses a small, internal static buffer
0104         to avoid memory allocations especially for the case where
0105         the list of arguments to be converted consists of a single
0106         integral type.
0107 
0108         @param args One or more arguments to convert
0109     */
0110     template<class... Args>
0111     string_param(Args const&... args);
0112 
0113     /// Returns the contained string
0114     string_view
0115     str() const
0116     {
0117         return sv_;
0118     }
0119 
0120     /// Implicit conversion to @ref string_view
0121     operator string_view const() const
0122     {
0123         return sv_;
0124     }
0125 };
0126 
0127 } // beast
0128 } // boost
0129 
0130 #include <boost/beast/core/impl/string_param.hpp>
0131 
0132 #endif // defined(BOOST_BEAST_ALLOW_DEPRECATED) && !BOOST_BEAST_DOXYGEN
0133 
0134 #endif