source: NonGTP/Boost/boost/variant/detail/variant_io.hpp @ 857

Revision 857, 2.4 KB checked in by igarcia, 19 years ago (diff)
Line 
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
23namespace 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< ... >, ... >)
32template <
33      BOOST_TEMPLATED_STREAM_ARGS(E,T)
34    BOOST_TEMPLATED_STREAM_COMMA
35      BOOST_VARIANT_ENUM_PARAMS(typename U)
36    >
37inline 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
42namespace detail { namespace variant {
43
44template <typename OStream>
45class printer
46    : public boost::static_visitor<>
47{
48private: // representation
49
50    OStream& out_;
51
52public: // structors
53
54    explicit printer(OStream& out)
55        : out_( out )
56    {
57    }
58
59public: // visitor interface
60
61    template <typename T>
62    void operator()(const T& operand) const
63    {
64        out_ << operand;
65    }
66
67};
68
69}} // namespace detail::variant
70
71template <
72      BOOST_TEMPLATED_STREAM_ARGS(E,T)
73    BOOST_TEMPLATED_STREAM_COMMA
74      BOOST_VARIANT_ENUM_PARAMS(typename U)
75    >
76inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
77      BOOST_TEMPLATED_STREAM(ostream, E,T)& out
78    , const variant< BOOST_VARIANT_ENUM_PARAMS(U) >& rhs
79    )
80{
81    detail::variant::printer<
82          BOOST_TEMPLATED_STREAM(ostream, E,T)
83        > visitor(out);
84
85    rhs.apply_visitor(visitor);
86
87    return out;
88}
89
90} // namespace boost
91
92#endif // BOOST_VARIANT_DETAIL_VARIANT_IO_HPP
Note: See TracBrowser for help on using the repository browser.