1 #ifndef BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
2 #define BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
4 // MS compatible compilers support #pragma once
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // ostream_iterator.hpp
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)
17 // See http://www.boost.org for updates, documentation, and revision history.
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.
25 #include <boost/iterator/iterator_facade.hpp>
31 // given a type, make an input iterator based on a pointer to that type
33 class ostream_iterator :
34 public boost::iterator_facade<
35 ostream_iterator<Elem>,
37 std::output_iterator_tag,
38 ostream_iterator<Elem> &
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;
46 //emulate the behavior of std::ostream
47 ostream_iterator & dereference() const {
48 return const_cast<ostream_iterator &>(*this);
50 bool equal(const this_t & rhs) const {
51 return m_ostream == rhs.m_ostream;
55 ostream_type *m_ostream;
56 void put_val(char_type e){
57 if(NULL != m_ostream){
59 if(! m_ostream->good())
64 this_t & operator=(char_type c){
68 ostream_iterator(ostream_type & os) :
74 ostream_iterator(const ostream_iterator & rhs) :
75 m_ostream (rhs.m_ostream)
79 } // namespace iterators
80 } // namespace archive
83 #endif // BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP