1 /*============================================================================= 2 Copyright (c) 2002 2004 2006 Joel de Guzman 3 http://spirit.sourceforge.net/ 4 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 #include "collector.hpp" 10 #include <boost/assert.hpp> 11 12 namespace quickbook 13 { string_stream()14 string_stream::string_stream() 15 : buffer_ptr(new std::string()) 16 , stream_ptr( 17 new ostream(boost::iostreams::back_inserter(*buffer_ptr.get()))) 18 { 19 } 20 string_stream(string_stream const & other)21 string_stream::string_stream(string_stream const& other) 22 : buffer_ptr(other.buffer_ptr), stream_ptr(other.stream_ptr) 23 { 24 } 25 operator =(string_stream const & other)26 string_stream& string_stream::operator=(string_stream const& other) 27 { 28 buffer_ptr = other.buffer_ptr; 29 stream_ptr = other.stream_ptr; 30 return *this; 31 } 32 collector()33 collector::collector() : main(default_), top(default_) {} 34 collector(string_stream & out)35 collector::collector(string_stream& out) : main(out), top(out) {} 36 ~collector()37 collector::~collector() 38 { 39 BOOST_ASSERT( 40 streams.empty()); // assert there are no more pushes than pops!!! 41 } 42 push()43 void collector::push() 44 { 45 streams.push(string_stream()); 46 top = boost::ref(streams.top()); 47 } 48 pop()49 void collector::pop() 50 { 51 BOOST_ASSERT(!streams.empty()); 52 streams.pop(); 53 54 if (streams.empty()) 55 top = boost::ref(main); 56 else 57 top = boost::ref(streams.top()); 58 } 59 } 60