sl@0
|
1 |
// tuple_io.hpp --------------------------------------------------------------
|
sl@0
|
2 |
|
sl@0
|
3 |
// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
|
sl@0
|
4 |
// 2001 Gary Powell (gary.powell@sierra.com)
|
sl@0
|
5 |
//
|
sl@0
|
6 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
7 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
8 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
9 |
// For more information, see http://www.boost.org
|
sl@0
|
10 |
|
sl@0
|
11 |
// ----------------------------------------------------------------------------
|
sl@0
|
12 |
|
sl@0
|
13 |
#ifndef BOOST_TUPLE_IO_HPP
|
sl@0
|
14 |
#define BOOST_TUPLE_IO_HPP
|
sl@0
|
15 |
|
sl@0
|
16 |
|
sl@0
|
17 |
// add to boost/config.hpp
|
sl@0
|
18 |
// for now
|
sl@0
|
19 |
# if defined __GNUC__
|
sl@0
|
20 |
# if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97)
|
sl@0
|
21 |
#define BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
22 |
#endif
|
sl@0
|
23 |
#endif // __GNUC__
|
sl@0
|
24 |
|
sl@0
|
25 |
#if defined BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
26 |
#include <iostream>
|
sl@0
|
27 |
#else
|
sl@0
|
28 |
#include <istream>
|
sl@0
|
29 |
#include <ostream>
|
sl@0
|
30 |
#endif
|
sl@0
|
31 |
|
sl@0
|
32 |
#include "boost/tuple/tuple.hpp"
|
sl@0
|
33 |
|
sl@0
|
34 |
// This is ugly: one should be using twoargument isspace since whitspace can
|
sl@0
|
35 |
// be locale dependent, in theory at least.
|
sl@0
|
36 |
// not all libraries implement have the two-arg version, so we need to
|
sl@0
|
37 |
// use the one-arg one, which one should get with <cctype> but there seem
|
sl@0
|
38 |
// to be exceptions to this.
|
sl@0
|
39 |
|
sl@0
|
40 |
#if !defined (BOOST_NO_STD_LOCALE)
|
sl@0
|
41 |
|
sl@0
|
42 |
#include <locale> // for two-arg isspace
|
sl@0
|
43 |
|
sl@0
|
44 |
#else
|
sl@0
|
45 |
|
sl@0
|
46 |
#include <cctype> // for one-arg (old) isspace
|
sl@0
|
47 |
#include <ctype.h> // Metrowerks does not find one-arg isspace from cctype
|
sl@0
|
48 |
|
sl@0
|
49 |
#endif
|
sl@0
|
50 |
|
sl@0
|
51 |
namespace boost {
|
sl@0
|
52 |
namespace tuples {
|
sl@0
|
53 |
|
sl@0
|
54 |
namespace detail {
|
sl@0
|
55 |
|
sl@0
|
56 |
class format_info {
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
|
sl@0
|
59 |
enum manipulator_type { open, close, delimiter };
|
sl@0
|
60 |
BOOST_STATIC_CONSTANT(int, number_of_manipulators = delimiter + 1);
|
sl@0
|
61 |
private:
|
sl@0
|
62 |
|
sl@0
|
63 |
static int get_stream_index (int m)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
static const int stream_index[number_of_manipulators]
|
sl@0
|
66 |
= { std::ios::xalloc(), std::ios::xalloc(), std::ios::xalloc() };
|
sl@0
|
67 |
|
sl@0
|
68 |
return stream_index[m];
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
format_info(const format_info&);
|
sl@0
|
72 |
format_info();
|
sl@0
|
73 |
|
sl@0
|
74 |
|
sl@0
|
75 |
public:
|
sl@0
|
76 |
|
sl@0
|
77 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
78 |
static char get_manipulator(std::ios& i, manipulator_type m) {
|
sl@0
|
79 |
char c = static_cast<char>(i.iword(get_stream_index(m)));
|
sl@0
|
80 |
|
sl@0
|
81 |
// parentheses and space are the default manipulators
|
sl@0
|
82 |
if (!c) {
|
sl@0
|
83 |
switch(m) {
|
sl@0
|
84 |
case detail::format_info::open : c = '('; break;
|
sl@0
|
85 |
case detail::format_info::close : c = ')'; break;
|
sl@0
|
86 |
case detail::format_info::delimiter : c = ' '; break;
|
sl@0
|
87 |
}
|
sl@0
|
88 |
}
|
sl@0
|
89 |
return c;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
static void set_manipulator(std::ios& i, manipulator_type m, char c) {
|
sl@0
|
93 |
i.iword(get_stream_index(m)) = static_cast<long>(c);
|
sl@0
|
94 |
}
|
sl@0
|
95 |
#else
|
sl@0
|
96 |
template<class CharType, class CharTrait>
|
sl@0
|
97 |
static CharType get_manipulator(std::basic_ios<CharType, CharTrait>& i,
|
sl@0
|
98 |
manipulator_type m) {
|
sl@0
|
99 |
// The manipulators are stored as long.
|
sl@0
|
100 |
// A valid instanitation of basic_stream allows CharType to be any POD,
|
sl@0
|
101 |
// hence, the static_cast may fail (it fails if long is not convertible
|
sl@0
|
102 |
// to CharType
|
sl@0
|
103 |
CharType c = static_cast<CharType>(i.iword(get_stream_index(m)) );
|
sl@0
|
104 |
// parentheses and space are the default manipulators
|
sl@0
|
105 |
if (!c) {
|
sl@0
|
106 |
switch(m) {
|
sl@0
|
107 |
case detail::format_info::open : c = i.widen('('); break;
|
sl@0
|
108 |
case detail::format_info::close : c = i.widen(')'); break;
|
sl@0
|
109 |
case detail::format_info::delimiter : c = i.widen(' '); break;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
}
|
sl@0
|
112 |
return c;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
|
sl@0
|
116 |
template<class CharType, class CharTrait>
|
sl@0
|
117 |
static void set_manipulator(std::basic_ios<CharType, CharTrait>& i,
|
sl@0
|
118 |
manipulator_type m, CharType c) {
|
sl@0
|
119 |
// The manipulators are stored as long.
|
sl@0
|
120 |
// A valid instanitation of basic_stream allows CharType to be any POD,
|
sl@0
|
121 |
// hence, the static_cast may fail (it fails if CharType is not
|
sl@0
|
122 |
// convertible long.
|
sl@0
|
123 |
i.iword(get_stream_index(m)) = static_cast<long>(c);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
126 |
};
|
sl@0
|
127 |
|
sl@0
|
128 |
} // end of namespace detail
|
sl@0
|
129 |
|
sl@0
|
130 |
template<class CharType>
|
sl@0
|
131 |
class tuple_manipulator {
|
sl@0
|
132 |
const detail::format_info::manipulator_type mt;
|
sl@0
|
133 |
CharType f_c;
|
sl@0
|
134 |
public:
|
sl@0
|
135 |
explicit tuple_manipulator(detail::format_info::manipulator_type m,
|
sl@0
|
136 |
const char c = 0)
|
sl@0
|
137 |
: mt(m), f_c(c) {}
|
sl@0
|
138 |
|
sl@0
|
139 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
140 |
void set(std::ios &io) const {
|
sl@0
|
141 |
detail::format_info::set_manipulator(io, mt, f_c);
|
sl@0
|
142 |
}
|
sl@0
|
143 |
#else
|
sl@0
|
144 |
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
145 |
template<class CharType2, class CharTrait>
|
sl@0
|
146 |
void set(std::basic_ios<CharType2, CharTrait> &io) const {
|
sl@0
|
147 |
detail::format_info::set_manipulator(io, mt, f_c);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
#else
|
sl@0
|
150 |
template<class CharTrait>
|
sl@0
|
151 |
void set(std::basic_ios<CharType, CharTrait> &io) const {
|
sl@0
|
152 |
detail::format_info::set_manipulator(io, mt, f_c);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
155 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
156 |
};
|
sl@0
|
157 |
|
sl@0
|
158 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
159 |
inline std::ostream&
|
sl@0
|
160 |
operator<<(std::ostream& o, const tuple_manipulator<char>& m) {
|
sl@0
|
161 |
m.set(o);
|
sl@0
|
162 |
return o;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
inline std::istream&
|
sl@0
|
166 |
operator>>(std::istream& i, const tuple_manipulator<char>& m) {
|
sl@0
|
167 |
m.set(i);
|
sl@0
|
168 |
return i;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
#else
|
sl@0
|
172 |
|
sl@0
|
173 |
template<class CharType, class CharTrait>
|
sl@0
|
174 |
inline std::basic_ostream<CharType, CharTrait>&
|
sl@0
|
175 |
operator<<(std::basic_ostream<CharType, CharTrait>& o, const tuple_manipulator<CharType>& m) {
|
sl@0
|
176 |
m.set(o);
|
sl@0
|
177 |
return o;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
template<class CharType, class CharTrait>
|
sl@0
|
181 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
182 |
operator>>(std::basic_istream<CharType, CharTrait>& i, const tuple_manipulator<CharType>& m) {
|
sl@0
|
183 |
m.set(i);
|
sl@0
|
184 |
return i;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
188 |
|
sl@0
|
189 |
template<class CharType>
|
sl@0
|
190 |
inline tuple_manipulator<CharType> set_open(const CharType c) {
|
sl@0
|
191 |
return tuple_manipulator<CharType>(detail::format_info::open, c);
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
template<class CharType>
|
sl@0
|
195 |
inline tuple_manipulator<CharType> set_close(const CharType c) {
|
sl@0
|
196 |
return tuple_manipulator<CharType>(detail::format_info::close, c);
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
template<class CharType>
|
sl@0
|
200 |
inline tuple_manipulator<CharType> set_delimiter(const CharType c) {
|
sl@0
|
201 |
return tuple_manipulator<CharType>(detail::format_info::delimiter, c);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
|
sl@0
|
208 |
// -------------------------------------------------------------
|
sl@0
|
209 |
// printing tuples to ostream in format (a b c)
|
sl@0
|
210 |
// parentheses and space are defaults, but can be overriden with manipulators
|
sl@0
|
211 |
// set_open, set_close and set_delimiter
|
sl@0
|
212 |
|
sl@0
|
213 |
namespace detail {
|
sl@0
|
214 |
|
sl@0
|
215 |
// Note: The order of the print functions is critical
|
sl@0
|
216 |
// to let a conforming compiler find and select the correct one.
|
sl@0
|
217 |
|
sl@0
|
218 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
219 |
|
sl@0
|
220 |
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
221 |
template<class T1>
|
sl@0
|
222 |
inline std::ostream& print(std::ostream& o, const cons<T1, null_type>& t) {
|
sl@0
|
223 |
return o << t.head;
|
sl@0
|
224 |
}
|
sl@0
|
225 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
226 |
|
sl@0
|
227 |
inline std::ostream& print(std::ostream& o, const null_type&) { return o; }
|
sl@0
|
228 |
|
sl@0
|
229 |
template<class T1, class T2>
|
sl@0
|
230 |
inline std::ostream&
|
sl@0
|
231 |
print(std::ostream& o, const cons<T1, T2>& t) {
|
sl@0
|
232 |
|
sl@0
|
233 |
const char d = format_info::get_manipulator(o, format_info::delimiter);
|
sl@0
|
234 |
|
sl@0
|
235 |
o << t.head;
|
sl@0
|
236 |
|
sl@0
|
237 |
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
238 |
if (tuples::length<T2>::value == 0)
|
sl@0
|
239 |
return o;
|
sl@0
|
240 |
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
241 |
o << d;
|
sl@0
|
242 |
|
sl@0
|
243 |
return print(o, t.tail );
|
sl@0
|
244 |
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
|
sl@0
|
248 |
|
sl@0
|
249 |
#else
|
sl@0
|
250 |
|
sl@0
|
251 |
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
252 |
template<class CharType, class CharTrait, class T1>
|
sl@0
|
253 |
inline std::basic_ostream<CharType, CharTrait>&
|
sl@0
|
254 |
print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, null_type>& t) {
|
sl@0
|
255 |
return o << t.head;
|
sl@0
|
256 |
}
|
sl@0
|
257 |
#endif // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
258 |
|
sl@0
|
259 |
|
sl@0
|
260 |
template<class CharType, class CharTrait>
|
sl@0
|
261 |
inline std::basic_ostream<CharType, CharTrait>&
|
sl@0
|
262 |
print(std::basic_ostream<CharType, CharTrait>& o, const null_type&) {
|
sl@0
|
263 |
return o;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
template<class CharType, class CharTrait, class T1, class T2>
|
sl@0
|
267 |
inline std::basic_ostream<CharType, CharTrait>&
|
sl@0
|
268 |
print(std::basic_ostream<CharType, CharTrait>& o, const cons<T1, T2>& t) {
|
sl@0
|
269 |
|
sl@0
|
270 |
const CharType d = format_info::get_manipulator(o, format_info::delimiter);
|
sl@0
|
271 |
|
sl@0
|
272 |
o << t.head;
|
sl@0
|
273 |
|
sl@0
|
274 |
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
275 |
if (tuples::length<T2>::value == 0)
|
sl@0
|
276 |
return o;
|
sl@0
|
277 |
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
278 |
o << d;
|
sl@0
|
279 |
|
sl@0
|
280 |
return print(o, t.tail);
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
284 |
|
sl@0
|
285 |
} // namespace detail
|
sl@0
|
286 |
|
sl@0
|
287 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
288 |
template<class T1, class T2>
|
sl@0
|
289 |
inline std::ostream& operator<<(std::ostream& o, const cons<T1, T2>& t) {
|
sl@0
|
290 |
if (!o.good() ) return o;
|
sl@0
|
291 |
|
sl@0
|
292 |
const char l =
|
sl@0
|
293 |
detail::format_info::get_manipulator(o, detail::format_info::open);
|
sl@0
|
294 |
const char r =
|
sl@0
|
295 |
detail::format_info::get_manipulator(o, detail::format_info::close);
|
sl@0
|
296 |
|
sl@0
|
297 |
o << l;
|
sl@0
|
298 |
|
sl@0
|
299 |
detail::print(o, t);
|
sl@0
|
300 |
|
sl@0
|
301 |
o << r;
|
sl@0
|
302 |
|
sl@0
|
303 |
return o;
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
#else
|
sl@0
|
307 |
|
sl@0
|
308 |
template<class CharType, class CharTrait, class T1, class T2>
|
sl@0
|
309 |
inline std::basic_ostream<CharType, CharTrait>&
|
sl@0
|
310 |
operator<<(std::basic_ostream<CharType, CharTrait>& o,
|
sl@0
|
311 |
const cons<T1, T2>& t) {
|
sl@0
|
312 |
if (!o.good() ) return o;
|
sl@0
|
313 |
|
sl@0
|
314 |
const CharType l =
|
sl@0
|
315 |
detail::format_info::get_manipulator(o, detail::format_info::open);
|
sl@0
|
316 |
const CharType r =
|
sl@0
|
317 |
detail::format_info::get_manipulator(o, detail::format_info::close);
|
sl@0
|
318 |
|
sl@0
|
319 |
o << l;
|
sl@0
|
320 |
|
sl@0
|
321 |
detail::print(o, t);
|
sl@0
|
322 |
|
sl@0
|
323 |
o << r;
|
sl@0
|
324 |
|
sl@0
|
325 |
return o;
|
sl@0
|
326 |
}
|
sl@0
|
327 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
328 |
|
sl@0
|
329 |
|
sl@0
|
330 |
// -------------------------------------------------------------
|
sl@0
|
331 |
// input stream operators
|
sl@0
|
332 |
|
sl@0
|
333 |
namespace detail {
|
sl@0
|
334 |
|
sl@0
|
335 |
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
sl@0
|
336 |
|
sl@0
|
337 |
inline std::istream&
|
sl@0
|
338 |
extract_and_check_delimiter(
|
sl@0
|
339 |
std::istream& is, format_info::manipulator_type del)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
const char d = format_info::get_manipulator(is, del);
|
sl@0
|
342 |
|
sl@0
|
343 |
#if defined (BOOST_NO_STD_LOCALE)
|
sl@0
|
344 |
const bool is_delimiter = !isspace(d);
|
sl@0
|
345 |
#else
|
sl@0
|
346 |
const bool is_delimiter = (!std::isspace(d, is.getloc()) );
|
sl@0
|
347 |
#endif
|
sl@0
|
348 |
|
sl@0
|
349 |
char c;
|
sl@0
|
350 |
if (is_delimiter) {
|
sl@0
|
351 |
is >> c;
|
sl@0
|
352 |
if (is.good() && c!=d) {
|
sl@0
|
353 |
is.setstate(std::ios::failbit);
|
sl@0
|
354 |
}
|
sl@0
|
355 |
}
|
sl@0
|
356 |
return is;
|
sl@0
|
357 |
}
|
sl@0
|
358 |
|
sl@0
|
359 |
|
sl@0
|
360 |
// Note: The order of the read functions is critical to let a
|
sl@0
|
361 |
// (conforming?) compiler find and select the correct one.
|
sl@0
|
362 |
|
sl@0
|
363 |
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
364 |
template<class T1>
|
sl@0
|
365 |
inline std::istream &
|
sl@0
|
366 |
read (std::istream &is, cons<T1, null_type>& t1) {
|
sl@0
|
367 |
|
sl@0
|
368 |
if (!is.good()) return is;
|
sl@0
|
369 |
|
sl@0
|
370 |
return is >> t1.head ;
|
sl@0
|
371 |
}
|
sl@0
|
372 |
#else
|
sl@0
|
373 |
inline std::istream& read(std::istream& i, const null_type&) { return i; }
|
sl@0
|
374 |
#endif // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
375 |
|
sl@0
|
376 |
template<class T1, class T2>
|
sl@0
|
377 |
inline std::istream&
|
sl@0
|
378 |
read(std::istream &is, cons<T1, T2>& t1) {
|
sl@0
|
379 |
|
sl@0
|
380 |
if (!is.good()) return is;
|
sl@0
|
381 |
|
sl@0
|
382 |
is >> t1.head;
|
sl@0
|
383 |
|
sl@0
|
384 |
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
385 |
if (tuples::length<T2>::value == 0)
|
sl@0
|
386 |
return is;
|
sl@0
|
387 |
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
388 |
|
sl@0
|
389 |
extract_and_check_delimiter(is, format_info::delimiter);
|
sl@0
|
390 |
|
sl@0
|
391 |
return read(is, t1.tail);
|
sl@0
|
392 |
}
|
sl@0
|
393 |
|
sl@0
|
394 |
} // end namespace detail
|
sl@0
|
395 |
|
sl@0
|
396 |
inline std::istream&
|
sl@0
|
397 |
operator>>(std::istream &is, null_type&) {
|
sl@0
|
398 |
|
sl@0
|
399 |
if (!is.good() ) return is;
|
sl@0
|
400 |
|
sl@0
|
401 |
detail::extract_and_check_delimiter(is, detail::format_info::open);
|
sl@0
|
402 |
detail::extract_and_check_delimiter(is, detail::format_info::close);
|
sl@0
|
403 |
|
sl@0
|
404 |
return is;
|
sl@0
|
405 |
}
|
sl@0
|
406 |
|
sl@0
|
407 |
|
sl@0
|
408 |
template<class T1, class T2>
|
sl@0
|
409 |
inline std::istream&
|
sl@0
|
410 |
operator>>(std::istream& is, cons<T1, T2>& t1) {
|
sl@0
|
411 |
|
sl@0
|
412 |
if (!is.good() ) return is;
|
sl@0
|
413 |
|
sl@0
|
414 |
detail::extract_and_check_delimiter(is, detail::format_info::open);
|
sl@0
|
415 |
|
sl@0
|
416 |
detail::read(is, t1);
|
sl@0
|
417 |
|
sl@0
|
418 |
detail::extract_and_check_delimiter(is, detail::format_info::close);
|
sl@0
|
419 |
|
sl@0
|
420 |
return is;
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
|
sl@0
|
424 |
|
sl@0
|
425 |
#else
|
sl@0
|
426 |
|
sl@0
|
427 |
template<class CharType, class CharTrait>
|
sl@0
|
428 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
429 |
extract_and_check_delimiter(
|
sl@0
|
430 |
std::basic_istream<CharType, CharTrait> &is, format_info::manipulator_type del)
|
sl@0
|
431 |
{
|
sl@0
|
432 |
const CharType d = format_info::get_manipulator(is, del);
|
sl@0
|
433 |
|
sl@0
|
434 |
#if defined (BOOST_NO_STD_LOCALE)
|
sl@0
|
435 |
const bool is_delimiter = !isspace(d);
|
sl@0
|
436 |
#elif defined ( __BORLANDC__ )
|
sl@0
|
437 |
const bool is_delimiter = !std::use_facet< std::ctype< CharType > >
|
sl@0
|
438 |
(is.getloc() ).is( std::ctype_base::space, d);
|
sl@0
|
439 |
#else
|
sl@0
|
440 |
const bool is_delimiter = (!std::isspace(d, is.getloc()) );
|
sl@0
|
441 |
#endif
|
sl@0
|
442 |
|
sl@0
|
443 |
CharType c;
|
sl@0
|
444 |
if (is_delimiter) {
|
sl@0
|
445 |
is >> c;
|
sl@0
|
446 |
if (is.good() && c!=d) {
|
sl@0
|
447 |
is.setstate(std::ios::failbit);
|
sl@0
|
448 |
}
|
sl@0
|
449 |
}
|
sl@0
|
450 |
return is;
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
|
sl@0
|
454 |
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
455 |
template<class CharType, class CharTrait, class T1>
|
sl@0
|
456 |
inline std::basic_istream<CharType, CharTrait> &
|
sl@0
|
457 |
read (std::basic_istream<CharType, CharTrait> &is, cons<T1, null_type>& t1) {
|
sl@0
|
458 |
|
sl@0
|
459 |
if (!is.good()) return is;
|
sl@0
|
460 |
|
sl@0
|
461 |
return is >> t1.head;
|
sl@0
|
462 |
}
|
sl@0
|
463 |
#else
|
sl@0
|
464 |
template<class CharType, class CharTrait>
|
sl@0
|
465 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
466 |
read(std::basic_istream<CharType, CharTrait>& i, const null_type&) { return i; }
|
sl@0
|
467 |
|
sl@0
|
468 |
#endif // !BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
469 |
|
sl@0
|
470 |
template<class CharType, class CharTrait, class T1, class T2>
|
sl@0
|
471 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
472 |
read(std::basic_istream<CharType, CharTrait> &is, cons<T1, T2>& t1) {
|
sl@0
|
473 |
|
sl@0
|
474 |
if (!is.good()) return is;
|
sl@0
|
475 |
|
sl@0
|
476 |
is >> t1.head;
|
sl@0
|
477 |
|
sl@0
|
478 |
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
sl@0
|
479 |
if (tuples::length<T2>::value == 0)
|
sl@0
|
480 |
return is;
|
sl@0
|
481 |
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
sl@0
|
482 |
|
sl@0
|
483 |
extract_and_check_delimiter(is, format_info::delimiter);
|
sl@0
|
484 |
|
sl@0
|
485 |
return read(is, t1.tail);
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
} // end namespace detail
|
sl@0
|
489 |
|
sl@0
|
490 |
|
sl@0
|
491 |
template<class CharType, class CharTrait>
|
sl@0
|
492 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
493 |
operator>>(std::basic_istream<CharType, CharTrait> &is, null_type&) {
|
sl@0
|
494 |
|
sl@0
|
495 |
if (!is.good() ) return is;
|
sl@0
|
496 |
|
sl@0
|
497 |
detail::extract_and_check_delimiter(is, detail::format_info::open);
|
sl@0
|
498 |
detail::extract_and_check_delimiter(is, detail::format_info::close);
|
sl@0
|
499 |
|
sl@0
|
500 |
return is;
|
sl@0
|
501 |
}
|
sl@0
|
502 |
|
sl@0
|
503 |
template<class CharType, class CharTrait, class T1, class T2>
|
sl@0
|
504 |
inline std::basic_istream<CharType, CharTrait>&
|
sl@0
|
505 |
operator>>(std::basic_istream<CharType, CharTrait>& is, cons<T1, T2>& t1) {
|
sl@0
|
506 |
|
sl@0
|
507 |
if (!is.good() ) return is;
|
sl@0
|
508 |
|
sl@0
|
509 |
detail::extract_and_check_delimiter(is, detail::format_info::open);
|
sl@0
|
510 |
|
sl@0
|
511 |
detail::read(is, t1);
|
sl@0
|
512 |
|
sl@0
|
513 |
detail::extract_and_check_delimiter(is, detail::format_info::close);
|
sl@0
|
514 |
|
sl@0
|
515 |
return is;
|
sl@0
|
516 |
}
|
sl@0
|
517 |
|
sl@0
|
518 |
#endif // BOOST_NO_TEMPLATED_STREAMS
|
sl@0
|
519 |
|
sl@0
|
520 |
} // end of namespace tuples
|
sl@0
|
521 |
} // end of namespace boost
|
sl@0
|
522 |
|
sl@0
|
523 |
#endif // BOOST_TUPLE_IO_HPP
|
sl@0
|
524 |
|
sl@0
|
525 |
|