]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/include/boost/spirit/home/karma/stream/ostream_iterator.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / karma / stream / ostream_iterator.hpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 //
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)
5
6 #if !defined(BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM)
7 #define BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM
8
9 #if defined(_MSC_VER)
10 #pragma once
11 #endif
12
13 #include <iterator>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace boost { namespace spirit { namespace karma
17 {
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 ///////////////////////////////////////////////////////////////////////////
24 template <
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>
29 {
30 public:
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;
35
36 ostream_iterator(ostream_type& os_, Elem const* delim_ = 0)
37 : os(&os_), delim(delim_) {}
38
39 self_type& operator= (T const& val)
40 {
41 *os << val;
42 if (0 != delim)
43 *os << delim;
44 return *this;
45 }
46
47 self_type& operator*() { return *this; }
48 self_type& operator++() { return *this; }
49 self_type operator++(int) { return *this; }
50
51 // expose underlying stream
52 ostream_type& get_ostream() { return *os; }
53 ostream_type const& get_ostream() const { return *os; }
54
55 // expose good bit of underlying stream object
56 bool good() const { return get_ostream().good(); }
57
58 protected:
59 ostream_type *os;
60 Elem const* delim;
61 };
62
63 }}}
64
65 #endif