1 /*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_QUICKBOOK_COLLECTOR_HPP)
10 #define BOOST_SPIRIT_QUICKBOOK_COLLECTOR_HPP
14 #include <boost/ref.hpp>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/noncopyable.hpp>
17 #include <boost/iostreams/device/back_inserter.hpp>
18 #include <boost/iostreams/filtering_stream.hpp>
24 typedef boost::iostreams::filtering_ostream ostream;
27 string_stream(string_stream const& other);
28 string_stream& operator=(string_stream const& other);
30 std::string const& str() const
33 return *buffer_ptr.get();
36 std::ostream& get() const
38 return *stream_ptr.get();
46 void swap(std::string& other)
49 std::swap(other, *buffer_ptr.get());
52 void append(std::string const& other)
55 *buffer_ptr.get() += other;
60 boost::shared_ptr<std::string> buffer_ptr;
61 boost::shared_ptr<ostream> stream_ptr;
64 struct collector : boost::noncopyable
67 collector(string_stream& out);
73 std::ostream& get() const
75 return top.get().get();
78 std::string const& str() const
80 return top.get().str();
88 void swap(std::string& other)
90 top.get().swap(other);
93 void append(std::string const& other)
95 top.get().append(other);
100 std::stack<string_stream> streams;
101 boost::reference_wrapper<string_stream> main;
102 boost::reference_wrapper<string_stream> top;
103 string_stream default_;
106 template <typename T>
108 operator<<(collector& out, T const& val)
115 operator<<(collector& out, std::string const& val)
122 #endif // BOOST_SPIRIT_QUICKBOOK_COLLECTOR_HPP