1 | // (C) Copyright Gennadiy Rozental 2002-2005. |
---|
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) |
---|
5 | |
---|
6 | // See http://www.boost.org/libs/test for the library home page. |
---|
7 | // |
---|
8 | // File : $RCSfile: wrap_stringstream.hpp,v $ |
---|
9 | // |
---|
10 | // Version : $Revision: 1.9 $ |
---|
11 | // |
---|
12 | // Description : wraps strstream and stringstream (depends with one is present) |
---|
13 | // to provide the unified interface |
---|
14 | // *************************************************************************** |
---|
15 | |
---|
16 | #ifndef BOOST_WRAP_STRINGSTREAM_HPP_071894GER |
---|
17 | #define BOOST_WRAP_STRINGSTREAM_HPP_071894GER |
---|
18 | |
---|
19 | // Boost.Test |
---|
20 | #include <boost/test/detail/config.hpp> |
---|
21 | |
---|
22 | // STL |
---|
23 | #ifdef BOOST_NO_STRINGSTREAM |
---|
24 | #include <strstream> // for std::ostrstream |
---|
25 | #else |
---|
26 | #include <sstream> // for std::ostringstream |
---|
27 | #endif // BOOST_NO_STRINGSTREAM |
---|
28 | |
---|
29 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
30 | |
---|
31 | //____________________________________________________________________________// |
---|
32 | |
---|
33 | namespace boost { |
---|
34 | |
---|
35 | // ************************************************************************** // |
---|
36 | // ************** basic_wrap_stringstream ************** // |
---|
37 | // ************************************************************************** // |
---|
38 | |
---|
39 | template<typename CharT> |
---|
40 | class basic_wrap_stringstream { |
---|
41 | public: |
---|
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; |
---|
46 | #else |
---|
47 | typedef std::basic_ostringstream<CharT> wrapped_stream; |
---|
48 | #endif // BOOST_NO_STRINGSTREAM |
---|
49 | // Access methods |
---|
50 | basic_wrap_stringstream& ref(); |
---|
51 | wrapped_stream& stream(); |
---|
52 | std::basic_string<CharT> const& str(); |
---|
53 | |
---|
54 | private: |
---|
55 | // Data members |
---|
56 | wrapped_stream m_stream; |
---|
57 | std::basic_string<CharT> m_str; |
---|
58 | }; |
---|
59 | |
---|
60 | //____________________________________________________________________________// |
---|
61 | |
---|
62 | template <typename CharT, typename T> |
---|
63 | inline basic_wrap_stringstream<CharT>& |
---|
64 | operator<<( basic_wrap_stringstream<CharT>& targ, T const& t ) |
---|
65 | { |
---|
66 | targ.stream() << t; |
---|
67 | return targ; |
---|
68 | } |
---|
69 | |
---|
70 | //____________________________________________________________________________// |
---|
71 | |
---|
72 | template <typename CharT> |
---|
73 | inline typename basic_wrap_stringstream<CharT>::wrapped_stream& |
---|
74 | basic_wrap_stringstream<CharT>::stream() |
---|
75 | { |
---|
76 | return m_stream; |
---|
77 | } |
---|
78 | |
---|
79 | //____________________________________________________________________________// |
---|
80 | |
---|
81 | template <typename CharT> |
---|
82 | inline basic_wrap_stringstream<CharT>& |
---|
83 | basic_wrap_stringstream<CharT>::ref() |
---|
84 | { |
---|
85 | return *this; |
---|
86 | } |
---|
87 | |
---|
88 | //____________________________________________________________________________// |
---|
89 | |
---|
90 | template <typename CharT> |
---|
91 | inline std::basic_string<CharT> const& |
---|
92 | basic_wrap_stringstream<CharT>::str() |
---|
93 | { |
---|
94 | |
---|
95 | #ifdef BOOST_NO_STRINGSTREAM |
---|
96 | m_str.assign( m_stream.str(), m_stream.pcount() ); |
---|
97 | m_stream.freeze( false ); |
---|
98 | #else |
---|
99 | m_str = m_stream.str(); |
---|
100 | #endif |
---|
101 | |
---|
102 | return m_str; |
---|
103 | } |
---|
104 | |
---|
105 | //____________________________________________________________________________// |
---|
106 | |
---|
107 | template <typename CharT> |
---|
108 | inline basic_wrap_stringstream<CharT>& |
---|
109 | operator<<( basic_wrap_stringstream<CharT>& targ, basic_wrap_stringstream<CharT>& src ) |
---|
110 | { |
---|
111 | targ << src.str(); |
---|
112 | return targ; |
---|
113 | } |
---|
114 | |
---|
115 | //____________________________________________________________________________// |
---|
116 | |
---|
117 | #if !defined(BOOST_NO_STD_LOCALE) && \ |
---|
118 | (!defined(BOOST_MSVC) || BOOST_WORKAROUND(BOOST_MSVC, >= 1310)) && \ |
---|
119 | !defined(__MWERKS__) && !BOOST_WORKAROUND(__GNUC__, < 3) |
---|
120 | |
---|
121 | template <typename CharT> |
---|
122 | inline basic_wrap_stringstream<CharT>& |
---|
123 | operator<<( basic_wrap_stringstream<CharT>& targ, std::ios_base& (BOOST_TEST_CALL_DECL *man)(std::ios_base&) ) |
---|
124 | { |
---|
125 | targ.stream() << man; |
---|
126 | return targ; |
---|
127 | } |
---|
128 | |
---|
129 | //____________________________________________________________________________// |
---|
130 | |
---|
131 | template<typename CharT,typename Elem,typename Tr> |
---|
132 | inline basic_wrap_stringstream<CharT>& |
---|
133 | operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ostream<Elem,Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ostream<Elem, Tr>&) ) |
---|
134 | { |
---|
135 | targ.stream() << man; |
---|
136 | return targ; |
---|
137 | } |
---|
138 | |
---|
139 | //____________________________________________________________________________// |
---|
140 | |
---|
141 | template<typename CharT,typename Elem,typename Tr> |
---|
142 | inline basic_wrap_stringstream<CharT>& |
---|
143 | operator<<( basic_wrap_stringstream<CharT>& targ, std::basic_ios<Elem, Tr>& (BOOST_TEST_CALL_DECL *man)(std::basic_ios<Elem, Tr>&) ) |
---|
144 | { |
---|
145 | targ.stream() << man; |
---|
146 | return targ; |
---|
147 | } |
---|
148 | |
---|
149 | //____________________________________________________________________________// |
---|
150 | |
---|
151 | #endif |
---|
152 | |
---|
153 | // ************************************************************************** // |
---|
154 | // ************** wrap_stringstream ************** // |
---|
155 | // ************************************************************************** // |
---|
156 | |
---|
157 | typedef basic_wrap_stringstream<char> wrap_stringstream; |
---|
158 | typedef basic_wrap_stringstream<wchar_t> wrap_wstringstream; |
---|
159 | |
---|
160 | } // namespace boost |
---|
161 | |
---|
162 | //____________________________________________________________________________// |
---|
163 | |
---|
164 | #include <boost/test/detail/enable_warnings.hpp> |
---|
165 | |
---|
166 | // *************************************************************************** |
---|
167 | // Revision History : |
---|
168 | // |
---|
169 | // $Log: wrap_stringstream.hpp,v $ |
---|
170 | // Revision 1.9 2005/05/13 05:55:46 rogeeff |
---|
171 | // gcc 2.95 fix |
---|
172 | // |
---|
173 | // Revision 1.8 2005/05/08 08:55:09 rogeeff |
---|
174 | // typos and missing descriptions fixed |
---|
175 | // |
---|
176 | // Revision 1.7 2005/04/30 17:55:15 rogeeff |
---|
177 | // disable manipulator output for cw |
---|
178 | // |
---|
179 | // Revision 1.6 2005/02/20 08:27:08 rogeeff |
---|
180 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates |
---|
181 | // |
---|
182 | // Revision 1.5 2005/02/01 06:40:07 rogeeff |
---|
183 | // copyright update |
---|
184 | // old log entries removed |
---|
185 | // minor stilistic changes |
---|
186 | // depricated tools removed |
---|
187 | // |
---|
188 | // Revision 1.4 2005/01/31 07:50:06 rogeeff |
---|
189 | // cdecl portability fix |
---|
190 | // |
---|
191 | // Revision 1.3 2005/01/31 06:02:15 rogeeff |
---|
192 | // BOOST_TEST_CALL_DECL correctness fixes |
---|
193 | // |
---|
194 | // Revision 1.2 2005/01/30 01:43:57 rogeeff |
---|
195 | // warnings suppressed |
---|
196 | // |
---|
197 | // Revision 1.1 2005/01/22 18:21:40 rogeeff |
---|
198 | // moved sharable staff into utils |
---|
199 | // |
---|
200 | // *************************************************************************** |
---|
201 | |
---|
202 | #endif // BOOST_WRAP_STRINGSTREAM_HPP_071894GER |
---|