1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : wraps strstream and stringstream (depends with one is present)
13 // to provide the unified interface
14 // ***************************************************************************
16 #ifndef BOOST_TEST_UTILS_WRAP_STRINGSTREAM_HPP
17 #define BOOST_TEST_UTILS_WRAP_STRINGSTREAM_HPP
20 #include <boost/test/detail/config.hpp>
23 #ifdef BOOST_NO_STRINGSTREAM
24 #include <strstream> // for std::ostrstream
26 #include <sstream> // for std::ostringstream
27 #endif // BOOST_NO_STRINGSTREAM
29 #include <boost/test/detail/suppress_warnings.hpp>
31 //____________________________________________________________________________//
35 // ************************************************************************** //
36 // ************** basic_wrap_stringstream ************** //
37 // ************************************************************************** //
39 template<typename CharT>
40 class basic_wrap_stringstream {
42 #if defined(BOOST_CLASSIC_IOSTREAMS)
43 typedef std::ostringstream wrapped_stream;
44 #elif defined(BOOST_NO_STRINGSTREAM)
45 typedef std::basic_ostrstream<CharT> wrapped_stream;
47 typedef std::basic_ostringstream<CharT> wrapped_stream;
48 #endif // BOOST_NO_STRINGSTREAM
50 basic_wrap_stringstream& ref();
51 wrapped_stream& stream();
52 std::basic_string<CharT> const& str();
56 wrapped_stream m_stream;
57 std::basic_string<CharT> m_str;
60 //____________________________________________________________________________//
62 template <typename CharT, typename T>
63 inline basic_wrap_stringstream<CharT>&
64 operator<<( basic_wrap_stringstream<CharT>& targ, T const& t )
70 //____________________________________________________________________________//
72 template <typename CharT>
73 inline typename basic_wrap_stringstream<CharT>::wrapped_stream&
74 basic_wrap_stringstream<CharT>::stream()
79 //____________________________________________________________________________//
81 template <typename CharT>
82 inline basic_wrap_stringstream<CharT>&
83 basic_wrap_stringstream<CharT>::ref()
88 //____________________________________________________________________________//
90 template <typename CharT>
91 inline std::basic_string<CharT> const&
92 basic_wrap_stringstream<CharT>::str()
95 #ifdef BOOST_NO_STRINGSTREAM
96 m_str.assign( m_stream.str(), m_stream.pcount() );
97 m_stream.freeze( false );
99 m_str = m_stream.str();
105 //____________________________________________________________________________//
107 template <typename CharT>
108 inline basic_wrap_stringstream<CharT>&
109 operator<<( basic_wrap_stringstream<CharT>& targ, basic_wrap_stringstream<CharT>& src )
115 //____________________________________________________________________________//
117 #if BOOST_TEST_USE_STD_LOCALE
119 template <typename CharT>
120 inline basic_wrap_stringstream<CharT>&
121 operator<<( basic_wrap_stringstream<CharT>& targ, std::ios_base& (BOOST_TEST_CALL_DECL *man)(std::ios_base&) )
123 targ.stream() << man;
127 //____________________________________________________________________________//
129 template<typename CharT,typename Elem,typename Tr>
130 inline basic_wrap_stringstream<CharT>&
131 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ostream<Elem,Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ostream<Elem, Tr>&) )
133 targ.stream() << man;
137 //____________________________________________________________________________//
139 template<typename CharT,typename Elem,typename Tr>
140 inline basic_wrap_stringstream<CharT>&
141 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ios<Elem, Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ios<Elem, Tr>&) )
143 targ.stream() << man;
147 //____________________________________________________________________________//
151 // ************************************************************************** //
152 // ************** wrap_stringstream ************** //
153 // ************************************************************************** //
155 typedef basic_wrap_stringstream<char> wrap_stringstream;
156 typedef basic_wrap_stringstream<wchar_t> wrap_wstringstream;
160 #include <boost/test/detail/enable_warnings.hpp>
162 #endif // BOOST_TEST_UTILS_WRAP_STRINGSTREAM_HPP