Chris@16
|
1 // (C) Copyright Gennadiy Rozental 2002-2008.
|
Chris@16
|
2 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
3 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 // See http://www.boost.org/libs/test for the library home page.
|
Chris@16
|
7 //
|
Chris@16
|
8 // File : $RCSfile$
|
Chris@16
|
9 //
|
Chris@101
|
10 // Version : $Revision$
|
Chris@16
|
11 //
|
Chris@16
|
12 // Description : wraps strstream and stringstream (depends with one is present)
|
Chris@16
|
13 // to provide the unified interface
|
Chris@16
|
14 // ***************************************************************************
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_WRAP_STRINGSTREAM_HPP_071894GER
|
Chris@16
|
17 #define BOOST_WRAP_STRINGSTREAM_HPP_071894GER
|
Chris@16
|
18
|
Chris@16
|
19 // Boost.Test
|
Chris@16
|
20 #include <boost/test/detail/config.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 // STL
|
Chris@16
|
23 #ifdef BOOST_NO_STRINGSTREAM
|
Chris@16
|
24 #include <strstream> // for std::ostrstream
|
Chris@16
|
25 #else
|
Chris@16
|
26 #include <sstream> // for std::ostringstream
|
Chris@16
|
27 #endif // BOOST_NO_STRINGSTREAM
|
Chris@16
|
28
|
Chris@16
|
29 #include <boost/test/detail/suppress_warnings.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 //____________________________________________________________________________//
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost {
|
Chris@16
|
34
|
Chris@16
|
35 // ************************************************************************** //
|
Chris@16
|
36 // ************** basic_wrap_stringstream ************** //
|
Chris@16
|
37 // ************************************************************************** //
|
Chris@16
|
38
|
Chris@16
|
39 template<typename CharT>
|
Chris@16
|
40 class basic_wrap_stringstream {
|
Chris@16
|
41 public:
|
Chris@16
|
42 #if defined(BOOST_CLASSIC_IOSTREAMS)
|
Chris@16
|
43 typedef std::ostringstream wrapped_stream;
|
Chris@16
|
44 #elif defined(BOOST_NO_STRINGSTREAM)
|
Chris@16
|
45 typedef std::basic_ostrstream<CharT> wrapped_stream;
|
Chris@16
|
46 #else
|
Chris@16
|
47 typedef std::basic_ostringstream<CharT> wrapped_stream;
|
Chris@16
|
48 #endif // BOOST_NO_STRINGSTREAM
|
Chris@16
|
49 // Access methods
|
Chris@16
|
50 basic_wrap_stringstream& ref();
|
Chris@16
|
51 wrapped_stream& stream();
|
Chris@16
|
52 std::basic_string<CharT> const& str();
|
Chris@16
|
53
|
Chris@16
|
54 private:
|
Chris@16
|
55 // Data members
|
Chris@16
|
56 wrapped_stream m_stream;
|
Chris@16
|
57 std::basic_string<CharT> m_str;
|
Chris@16
|
58 };
|
Chris@16
|
59
|
Chris@16
|
60 //____________________________________________________________________________//
|
Chris@16
|
61
|
Chris@16
|
62 template <typename CharT, typename T>
|
Chris@16
|
63 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
64 operator<<( basic_wrap_stringstream<CharT>& targ, T const& t )
|
Chris@16
|
65 {
|
Chris@16
|
66 targ.stream() << t;
|
Chris@16
|
67 return targ;
|
Chris@16
|
68 }
|
Chris@16
|
69
|
Chris@16
|
70 //____________________________________________________________________________//
|
Chris@16
|
71
|
Chris@16
|
72 template <typename CharT>
|
Chris@16
|
73 inline typename basic_wrap_stringstream<CharT>::wrapped_stream&
|
Chris@16
|
74 basic_wrap_stringstream<CharT>::stream()
|
Chris@16
|
75 {
|
Chris@16
|
76 return m_stream;
|
Chris@16
|
77 }
|
Chris@16
|
78
|
Chris@16
|
79 //____________________________________________________________________________//
|
Chris@16
|
80
|
Chris@16
|
81 template <typename CharT>
|
Chris@16
|
82 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
83 basic_wrap_stringstream<CharT>::ref()
|
Chris@16
|
84 {
|
Chris@16
|
85 return *this;
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 //____________________________________________________________________________//
|
Chris@16
|
89
|
Chris@16
|
90 template <typename CharT>
|
Chris@16
|
91 inline std::basic_string<CharT> const&
|
Chris@16
|
92 basic_wrap_stringstream<CharT>::str()
|
Chris@16
|
93 {
|
Chris@16
|
94
|
Chris@16
|
95 #ifdef BOOST_NO_STRINGSTREAM
|
Chris@16
|
96 m_str.assign( m_stream.str(), m_stream.pcount() );
|
Chris@16
|
97 m_stream.freeze( false );
|
Chris@16
|
98 #else
|
Chris@16
|
99 m_str = m_stream.str();
|
Chris@16
|
100 #endif
|
Chris@16
|
101
|
Chris@16
|
102 return m_str;
|
Chris@16
|
103 }
|
Chris@16
|
104
|
Chris@16
|
105 //____________________________________________________________________________//
|
Chris@16
|
106
|
Chris@16
|
107 template <typename CharT>
|
Chris@16
|
108 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
109 operator<<( basic_wrap_stringstream<CharT>& targ, basic_wrap_stringstream<CharT>& src )
|
Chris@16
|
110 {
|
Chris@16
|
111 targ << src.str();
|
Chris@16
|
112 return targ;
|
Chris@16
|
113 }
|
Chris@16
|
114
|
Chris@16
|
115 //____________________________________________________________________________//
|
Chris@16
|
116
|
Chris@16
|
117 #if BOOST_TEST_USE_STD_LOCALE
|
Chris@16
|
118
|
Chris@16
|
119 template <typename CharT>
|
Chris@16
|
120 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
121 operator<<( basic_wrap_stringstream<CharT>& targ, std::ios_base& (BOOST_TEST_CALL_DECL *man)(std::ios_base&) )
|
Chris@16
|
122 {
|
Chris@16
|
123 targ.stream() << man;
|
Chris@16
|
124 return targ;
|
Chris@16
|
125 }
|
Chris@16
|
126
|
Chris@16
|
127 //____________________________________________________________________________//
|
Chris@16
|
128
|
Chris@16
|
129 template<typename CharT,typename Elem,typename Tr>
|
Chris@16
|
130 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
131 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ostream<Elem,Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ostream<Elem, Tr>&) )
|
Chris@16
|
132 {
|
Chris@16
|
133 targ.stream() << man;
|
Chris@16
|
134 return targ;
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 //____________________________________________________________________________//
|
Chris@16
|
138
|
Chris@16
|
139 template<typename CharT,typename Elem,typename Tr>
|
Chris@16
|
140 inline basic_wrap_stringstream<CharT>&
|
Chris@16
|
141 operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ios<Elem, Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ios<Elem, Tr>&) )
|
Chris@16
|
142 {
|
Chris@16
|
143 targ.stream() << man;
|
Chris@16
|
144 return targ;
|
Chris@16
|
145 }
|
Chris@16
|
146
|
Chris@16
|
147 //____________________________________________________________________________//
|
Chris@16
|
148
|
Chris@16
|
149 #endif
|
Chris@16
|
150
|
Chris@16
|
151 // ************************************************************************** //
|
Chris@16
|
152 // ************** wrap_stringstream ************** //
|
Chris@16
|
153 // ************************************************************************** //
|
Chris@16
|
154
|
Chris@16
|
155 typedef basic_wrap_stringstream<char> wrap_stringstream;
|
Chris@16
|
156 typedef basic_wrap_stringstream<wchar_t> wrap_wstringstream;
|
Chris@16
|
157
|
Chris@16
|
158 } // namespace boost
|
Chris@16
|
159
|
Chris@16
|
160 //____________________________________________________________________________//
|
Chris@16
|
161
|
Chris@16
|
162 #include <boost/test/detail/enable_warnings.hpp>
|
Chris@16
|
163
|
Chris@16
|
164 #endif // BOOST_WRAP_STRINGSTREAM_HPP_071894GER
|