File indexing completed on 2025-01-18 09:52:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_TEST_UTILS_WRAP_STRINGSTREAM_HPP
0017 #define BOOST_TEST_UTILS_WRAP_STRINGSTREAM_HPP
0018
0019
0020 #include <boost/test/detail/config.hpp>
0021
0022
0023 #ifdef BOOST_NO_STRINGSTREAM
0024 #include <strstream> // for std::ostrstream
0025 #else
0026 #include <sstream> // for std::ostringstream
0027 #endif
0028
0029 #include <boost/test/detail/suppress_warnings.hpp>
0030
0031
0032
0033 namespace boost {
0034
0035
0036
0037
0038
0039 template<typename CharT>
0040 class basic_wrap_stringstream {
0041 public:
0042 #if defined(BOOST_CLASSIC_IOSTREAMS)
0043 typedef std::ostringstream wrapped_stream;
0044 #elif defined(BOOST_NO_STRINGSTREAM)
0045 typedef std::basic_ostrstream<CharT> wrapped_stream;
0046 #else
0047 typedef std::basic_ostringstream<CharT> wrapped_stream;
0048 #endif
0049
0050 basic_wrap_stringstream& ref();
0051 wrapped_stream& stream();
0052 std::basic_string<CharT> const& str();
0053
0054 private:
0055
0056 wrapped_stream m_stream;
0057 std::basic_string<CharT> m_str;
0058 };
0059
0060
0061
0062 template <typename CharT, typename T>
0063 inline basic_wrap_stringstream<CharT>&
0064 operator<<( basic_wrap_stringstream<CharT>& targ, T const& t )
0065 {
0066 targ.stream() << t;
0067 return targ;
0068 }
0069
0070
0071
0072 template <typename CharT>
0073 inline typename basic_wrap_stringstream<CharT>::wrapped_stream&
0074 basic_wrap_stringstream<CharT>::stream()
0075 {
0076 return m_stream;
0077 }
0078
0079
0080
0081 template <typename CharT>
0082 inline basic_wrap_stringstream<CharT>&
0083 basic_wrap_stringstream<CharT>::ref()
0084 {
0085 return *this;
0086 }
0087
0088
0089
0090 template <typename CharT>
0091 inline std::basic_string<CharT> const&
0092 basic_wrap_stringstream<CharT>::str()
0093 {
0094
0095 #ifdef BOOST_NO_STRINGSTREAM
0096 m_str.assign( m_stream.str(), m_stream.pcount() );
0097 m_stream.freeze( false );
0098 #else
0099 m_str = m_stream.str();
0100 #endif
0101
0102 return m_str;
0103 }
0104
0105
0106
0107 template <typename CharT>
0108 inline basic_wrap_stringstream<CharT>&
0109 operator<<( basic_wrap_stringstream<CharT>& targ, basic_wrap_stringstream<CharT>& src )
0110 {
0111 targ << src.str();
0112 return targ;
0113 }
0114
0115
0116
0117 #if BOOST_TEST_USE_STD_LOCALE
0118
0119 template <typename CharT>
0120 inline basic_wrap_stringstream<CharT>&
0121 operator<<( basic_wrap_stringstream<CharT>& targ, std::ios_base& (BOOST_TEST_CALL_DECL *man)(std::ios_base&) )
0122 {
0123 targ.stream() << man;
0124 return targ;
0125 }
0126
0127
0128
0129 template<typename CharT,typename Elem,typename Tr>
0130 inline basic_wrap_stringstream<CharT>&
0131 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ostream<Elem,Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ostream<Elem, Tr>&) )
0132 {
0133 targ.stream() << man;
0134 return targ;
0135 }
0136
0137
0138
0139 template<typename CharT,typename Elem,typename Tr>
0140 inline basic_wrap_stringstream<CharT>&
0141 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ios<Elem, Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ios<Elem, Tr>&) )
0142 {
0143 targ.stream() << man;
0144 return targ;
0145 }
0146
0147
0148
0149 #endif
0150
0151
0152
0153
0154
0155 typedef basic_wrap_stringstream<char> wrap_stringstream;
0156 typedef basic_wrap_stringstream<wchar_t> wrap_wstringstream;
0157
0158 }
0159
0160 #include <boost/test/detail/enable_warnings.hpp>
0161
0162 #endif