source: NonGTP/Boost/boost/archive/iterators/ostream_iterator.hpp @ 857

Revision 857, 2.4 KB checked in by igarcia, 19 years ago (diff)
Line 
1#ifndef BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
2#define BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
3
4// MS compatible compilers support #pragma once
5#if defined(_MSC_VER) && (_MSC_VER >= 1020)
6# pragma once
7#endif
8
9/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10// ostream_iterator.hpp
11
12// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13// Use, modification and distribution is subject to the Boost Software
14// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15// http://www.boost.org/LICENSE_1_0.txt)
16
17//  See http://www.boost.org for updates, documentation, and revision history.
18
19// note: this is a custom version of the standard ostream_iterator.
20// This is necessary as the standard version doesn't work as expected
21// for wchar_t based streams on systems for which wchar_t not a true
22// type but rather a synonym for some integer type.
23
24#include <ostream>
25#include <boost/iterator/iterator_facade.hpp>
26
27namespace boost {
28namespace archive {
29namespace iterators {
30
31// given a type, make an input iterator based on a pointer to that type
32template<class Elem>
33class ostream_iterator : 
34    public boost::iterator_facade<
35        ostream_iterator<Elem>,
36        Elem,
37        std::output_iterator_tag,
38        ostream_iterator<Elem> &
39    >
40{
41    friend class boost::iterator_core_access;
42    typedef ostream_iterator this_t ;
43    typedef Elem char_type;
44    typedef std::basic_ostream<char_type> ostream_type;
45
46    //emulate the behavior of std::ostream
47    ostream_iterator & dereference() const {
48        return const_cast<ostream_iterator &>(*this);
49    }
50    bool equal(const this_t & rhs) const {
51        return m_ostream == rhs.m_ostream;
52    }
53    void increment(){}
54protected:
55    ostream_type *m_ostream;
56    void put_val(char_type e){
57        if(NULL != m_ostream){
58            m_ostream->put(e);
59            if(! m_ostream->good())
60                m_ostream = NULL;
61        }
62    }
63public:
64    this_t & operator=(char_type c){
65        put_val(c);
66        return *this;
67    }
68    ostream_iterator(ostream_type & os) :
69        m_ostream (& os)
70    {}
71    ostream_iterator() :
72        m_ostream (NULL)
73    {}
74    ostream_iterator(const ostream_iterator & rhs) :
75        m_ostream (rhs.m_ostream)
76    {}
77};
78
79} // namespace iterators
80} // namespace archive
81} // namespace boost
82
83#endif // BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
Note: See TracBrowser for help on using the repository browser.