Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 Chris@16: // ostream_iterator.hpp Chris@16: Chris@16: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org for updates, documentation, and revision history. Chris@16: Chris@16: // note: this is a custom version of the standard ostream_iterator. Chris@16: // This is necessary as the standard version doesn't work as expected Chris@16: // for wchar_t based streams on systems for which wchar_t not a true Chris@16: // type but rather a synonym for some integer type. Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace archive { Chris@16: namespace iterators { Chris@16: Chris@16: // given a type, make an input iterator based on a pointer to that type Chris@16: template Chris@16: class ostream_iterator : Chris@16: public boost::iterator_facade< Chris@16: ostream_iterator, Chris@16: Elem, Chris@16: std::output_iterator_tag, Chris@16: ostream_iterator & Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: typedef ostream_iterator this_t ; Chris@16: typedef Elem char_type; Chris@16: typedef std::basic_ostream ostream_type; Chris@16: Chris@16: //emulate the behavior of std::ostream Chris@16: ostream_iterator & dereference() const { Chris@16: return const_cast(*this); Chris@16: } Chris@16: bool equal(const this_t & rhs) const { Chris@16: return m_ostream == rhs.m_ostream; Chris@16: } Chris@16: void increment(){} Chris@16: protected: Chris@16: ostream_type *m_ostream; Chris@16: void put_val(char_type e){ Chris@16: if(NULL != m_ostream){ Chris@16: m_ostream->put(e); Chris@16: if(! m_ostream->good()) Chris@16: m_ostream = NULL; Chris@16: } Chris@16: } Chris@16: public: Chris@16: this_t & operator=(char_type c){ Chris@16: put_val(c); Chris@16: return *this; Chris@16: } Chris@16: ostream_iterator(ostream_type & os) : Chris@16: m_ostream (& os) Chris@16: {} Chris@16: ostream_iterator() : Chris@16: m_ostream (NULL) Chris@16: {} Chris@16: ostream_iterator(const ostream_iterator & rhs) : Chris@16: m_ostream (rhs.m_ostream) Chris@16: {} Chris@16: }; Chris@16: Chris@16: } // namespace iterators Chris@16: } // namespace archive Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP