1 | // Copyright (C) 2005, Fernando Luis Cacciola Carballal. |
---|
2 | // |
---|
3 | // Use, modification, and distribution is subject to the Boost Software |
---|
4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | // |
---|
7 | // See http://www.boost.org/lib/optional for documentation. |
---|
8 | // |
---|
9 | // You are welcome to contact the author at: |
---|
10 | // fernando_cacciola@hotmail.com |
---|
11 | // |
---|
12 | #ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP |
---|
13 | #define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP |
---|
14 | |
---|
15 | #if defined __GNUC__ |
---|
16 | # if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97) |
---|
17 | # define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS |
---|
18 | # endif |
---|
19 | #endif // __GNUC__ |
---|
20 | |
---|
21 | #if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS |
---|
22 | # include <iostream> |
---|
23 | #else |
---|
24 | # include <istream> |
---|
25 | # include <ostream> |
---|
26 | #endif |
---|
27 | |
---|
28 | |
---|
29 | #include "boost/optional/optional.hpp" |
---|
30 | #include "boost/utility/value_init.hpp" |
---|
31 | |
---|
32 | namespace boost |
---|
33 | { |
---|
34 | |
---|
35 | #if defined (BOOST_NO_TEMPLATED_STREAMS) |
---|
36 | template<class T> |
---|
37 | inline std::ostream& operator<<(std::ostream& out, optional<T> const& v) |
---|
38 | #else |
---|
39 | template<class CharType, class CharTrait, class T> |
---|
40 | inline |
---|
41 | std::basic_ostream<CharType, CharTrait>& |
---|
42 | operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v) |
---|
43 | #endif |
---|
44 | { |
---|
45 | if ( out.good() ) |
---|
46 | { |
---|
47 | if ( !v ) |
---|
48 | out << "--" ; |
---|
49 | else out << ' ' << *v ; |
---|
50 | } |
---|
51 | |
---|
52 | return out; |
---|
53 | } |
---|
54 | |
---|
55 | #if defined (BOOST_NO_TEMPLATED_STREAMS) |
---|
56 | template<class T> |
---|
57 | inline std::istream& operator>>(std::istream& in, optional<T>& v) |
---|
58 | #else |
---|
59 | template<class CharType, class CharTrait, class T> |
---|
60 | inline |
---|
61 | std::basic_istream<CharType, CharTrait>& |
---|
62 | operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v) |
---|
63 | #endif |
---|
64 | { |
---|
65 | if ( in.good() ) |
---|
66 | { |
---|
67 | int d = in.get(); |
---|
68 | if ( d == ' ' ) |
---|
69 | { |
---|
70 | T x ; |
---|
71 | in >> x; |
---|
72 | v = x ; |
---|
73 | } |
---|
74 | else |
---|
75 | v = optional<T>() ; |
---|
76 | } |
---|
77 | |
---|
78 | return in; |
---|
79 | } |
---|
80 | |
---|
81 | } // namespace boost |
---|
82 | |
---|
83 | #endif |
---|
84 | |
---|