]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/boost/boost/optional/optional_io.hpp
Add subset of boost library headers needed for compilation on PowerPC
[eurobot/public.git] / src / boost / boost / optional / optional_io.hpp
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/libs/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 #include <boost/none.hpp>
29 #include <boost/assert.hpp>
30 #include "boost/optional/optional.hpp"
31 #include "boost/utility/value_init.hpp"
32
33 namespace boost
34 {
35
36 #if defined (BOOST_NO_TEMPLATED_STREAMS)
37 template<class T>
38 inline std::ostream& operator<<(std::ostream& out, optional<T> const& v)
39 #else
40 template<class CharType, class CharTrait, class T>
41 inline
42 std::basic_ostream<CharType, CharTrait>&
43 operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
44 #endif
45 {
46   if ( out.good() )
47   {
48     if ( !v )
49          out << "--" ;
50     else out << ' ' << *v ;
51   }
52
53   return out;
54 }
55
56 #if defined (BOOST_NO_TEMPLATED_STREAMS)
57 template<class T>
58 inline std::istream& operator>>(std::istream& in, optional<T>& v)
59 #else
60 template<class CharType, class CharTrait, class T>
61 inline
62 std::basic_istream<CharType, CharTrait>&
63 operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
64 #endif
65 {
66   if (in.good())
67   {
68     int d = in.get();
69     if (d == ' ')
70     {
71       T x;
72       in >> x;
73       v = x;
74     }
75     else
76     {
77       if (d == '-')
78       {
79         d = in.get();
80
81         if (d == '-')
82         {
83           v = none;
84           return in;
85         }
86       }
87
88       in.setstate( std::ios::failbit );
89     }
90   }
91
92   return in;
93 }
94
95 } // namespace boost
96
97 #endif
98