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) 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 27 namespace boost { 28 namespace archive { 29 namespace iterators { 30 31 // given a type, make an input iterator based on a pointer to that type 32 template<class Elem> 33 class 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 dereference() const47 ostream_iterator & dereference() const { 48 return const_cast<ostream_iterator &>(*this); 49 } equal(const this_t & rhs) const50 bool equal(const this_t & rhs) const { 51 return m_ostream == rhs.m_ostream; 52 } increment()53 void increment(){} 54 protected: 55 ostream_type *m_ostream; put_val(char_type e)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 } 63 public: operator =(char_type c)64 this_t & operator=(char_type c){ 65 put_val(c); 66 return *this; 67 } ostream_iterator(ostream_type & os)68 ostream_iterator(ostream_type & os) : 69 m_ostream (& os) 70 {} ostream_iterator()71 ostream_iterator() : 72 m_ostream (NULL) 73 {} ostream_iterator(const ostream_iterator & rhs)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 84