1 // Copyright (c) 2001-2011 Hartmut Kaiser
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #if !defined(BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM)
7 #define BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace boost { namespace spirit { namespace karma
18 ///////////////////////////////////////////////////////////////////////////
19 // We need our own implementation of an ostream_iterator just to be able
20 // to access the wrapped ostream, which is necessary for the
21 // stream_generator, where we must generate the output using the original
22 // ostream to retain possibly registered facets.
23 ///////////////////////////////////////////////////////////////////////////
25 typename T, typename Elem = char
26 , typename Traits = std::char_traits<Elem> >
27 class ostream_iterator
28 : public std::iterator<std::output_iterator_tag, void, void, void, void>
31 typedef Elem char_type;
32 typedef Traits traits_type;
33 typedef std::basic_ostream<Elem, Traits> ostream_type;
34 typedef ostream_iterator<T, Elem, Traits> self_type;
36 ostream_iterator(ostream_type& os_, Elem const* delim_ = 0)
37 : os(&os_), delim(delim_) {}
39 self_type& operator= (T const& val)
47 self_type& operator*() { return *this; }
48 self_type& operator++() { return *this; }
49 self_type operator++(int) { return *this; }
51 // expose underlying stream
52 ostream_type& get_ostream() { return *os; }
53 ostream_type const& get_ostream() const { return *os; }
55 // expose good bit of underlying stream object
56 bool good() const { return get_ostream().good(); }