]> git.lyx.org Git - features.git/blob - 3rdparty/boost/boost/variant/detail/variant_io.hpp
Replace Boost.Signals with Boost.Signals2
[features.git] / 3rdparty / boost / boost / variant / detail / variant_io.hpp
1 //-----------------------------------------------------------------------------
2 // boost variant/detail/variant_io.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
5 //
6 // Copyright (c) 2002-2003
7 // Eric Friedman, Itay Maman
8 //
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13 #ifndef BOOST_VARIANT_DETAIL_VARIANT_IO_HPP
14 #define BOOST_VARIANT_DETAIL_VARIANT_IO_HPP
15
16 #include <iosfwd> // for std::basic_ostream forward declare
17
18 #include "boost/variant/variant_fwd.hpp"
19
20 #include "boost/detail/templated_streams.hpp"
21 #include "boost/variant/static_visitor.hpp"
22
23 namespace boost {
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // function template operator<<
27 //
28 // Outputs the content of the given variant to the given ostream.
29 //
30
31 // forward declare (allows output of embedded variant< variant< ... >, ... >)
32 template <
33       BOOST_TEMPLATED_STREAM_ARGS(E,T)
34     BOOST_TEMPLATED_STREAM_COMMA
35       BOOST_VARIANT_ENUM_PARAMS(typename U)
36     >
37 inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
38       BOOST_TEMPLATED_STREAM(ostream, E,T)& out
39     , const variant< BOOST_VARIANT_ENUM_PARAMS(U) >& rhs
40     );
41
42 namespace detail { namespace variant {
43
44 template <typename OStream>
45 class printer
46     : public boost::static_visitor<>
47 {
48 private: // representation
49
50     OStream& out_;
51
52 public: // structors
53
54     explicit printer(OStream& out)
55         : out_( out )
56     {
57     }
58
59 public: // visitor interface
60
61     template <typename T>
62     void operator()(const T& operand) const
63     {
64         out_ << operand;
65     }
66
67 private:
68     printer& operator=(const printer&);
69
70 };
71
72 }} // namespace detail::variant
73
74 template <
75       BOOST_TEMPLATED_STREAM_ARGS(E,T)
76     BOOST_TEMPLATED_STREAM_COMMA
77       BOOST_VARIANT_ENUM_PARAMS(typename U)
78     >
79 inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
80       BOOST_TEMPLATED_STREAM(ostream, E,T)& out
81     , const variant< BOOST_VARIANT_ENUM_PARAMS(U) >& rhs
82     )
83 {
84     detail::variant::printer<
85           BOOST_TEMPLATED_STREAM(ostream, E,T)
86         > visitor(out);
87
88     rhs.apply_visitor(visitor);
89
90     return out;
91 }
92
93 } // namespace boost
94
95 #endif // BOOST_VARIANT_DETAIL_VARIANT_IO_HPP