Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/optional/optional_io.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright (C) 2005, Fernando Luis Cacciola Carballal.
0002 //
0003 // Use, modification, and distribution is subject to the Boost Software
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/optional for documentation.
0008 //
0009 // You are welcome to contact the author at:
0010 //  fernando_cacciola@hotmail.com
0011 //
0012 #ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
0013 #define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
0014 
0015 #ifndef BOOST_NO_IOSTREAM
0016 #include <istream>
0017 #include <ostream>
0018 
0019 #include "boost/none.hpp"
0020 #include "boost/optional/optional.hpp"
0021 
0022 
0023 namespace boost
0024 {
0025 
0026 template<class CharType, class CharTrait>
0027 inline
0028 std::basic_ostream<CharType, CharTrait>&
0029 operator<<(std::basic_ostream<CharType, CharTrait>& out, none_t)
0030 {
0031   if (out.good())
0032   {
0033     out << "--";
0034   }
0035 
0036   return out;
0037 }
0038 
0039 template<class CharType, class CharTrait, class T>
0040 inline
0041 std::basic_ostream<CharType, CharTrait>&
0042 operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
0043 {
0044   if (out.good())
0045   {
0046     if (!v)
0047          out << "--" ;
0048     else out << ' ' << *v ;
0049   }
0050 
0051   return out;
0052 }
0053 
0054 template<class CharType, class CharTrait, class T>
0055 inline
0056 std::basic_istream<CharType, CharTrait>&
0057 operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
0058 {
0059   if (in.good())
0060   {
0061     int d = in.get();
0062     if (d == ' ')
0063     {
0064       T x;
0065       in >> x;
0066       v = optional_detail::move(x);
0067     }
0068     else
0069     {
0070       if (d == '-')
0071       {
0072         d = in.get();
0073 
0074         if (d == '-')
0075         {
0076           v = none;
0077           return in;
0078         }
0079       }
0080 
0081       in.setstate( std::ios::failbit );
0082     }
0083   }
0084 
0085   return in;
0086 }
0087 
0088 } // namespace boost
0089 
0090 #endif // BOOST_NO_IOSTREAM
0091 #endif