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