Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:29

0001 #ifndef BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP
0003 
0004 // MS compatible compilers support #pragma once
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008 
0009 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
0010 // ostream_iterator.hpp
0011 
0012 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
0013 // Use, modification and distribution is subject to the Boost Software
0014 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0015 // http://www.boost.org/LICENSE_1_0.txt)
0016 
0017 //  See http://www.boost.org for updates, documentation, and revision history.
0018 
0019 // note: this is a custom version of the standard ostream_iterator.
0020 // This is necessary as the standard version doesn't work as expected
0021 // for wchar_t based streams on systems for which wchar_t not a true
0022 // type but rather a synonym for some integer type.
0023 
0024 #include <ostream>
0025 #include <boost/iterator/iterator_facade.hpp>
0026 
0027 namespace boost {
0028 namespace archive {
0029 namespace iterators {
0030 
0031 // given a type, make an input iterator based on a pointer to that type
0032 template<class Elem>
0033 class ostream_iterator :
0034     public boost::iterator_facade<
0035         ostream_iterator<Elem>,
0036         Elem,
0037         std::output_iterator_tag,
0038         ostream_iterator<Elem> &
0039     >
0040 {
0041     friend class boost::iterator_core_access;
0042     typedef ostream_iterator this_t ;
0043     typedef Elem char_type;
0044     typedef std::basic_ostream<char_type> ostream_type;
0045 
0046     //emulate the behavior of std::ostream
0047     ostream_iterator & dereference() const {
0048         return const_cast<ostream_iterator &>(*this);
0049     }
0050     bool equal(const this_t & rhs) const {
0051         return m_ostream == rhs.m_ostream;
0052     }
0053     void increment(){}
0054 protected:
0055     ostream_type *m_ostream;
0056     void put_val(char_type e){
0057         if(NULL != m_ostream){
0058             m_ostream->put(e);
0059             if(! m_ostream->good())
0060                 m_ostream = NULL;
0061         }
0062     }
0063 public:
0064     this_t & operator=(char_type c){
0065         put_val(c);
0066         return *this;
0067     }
0068     ostream_iterator(ostream_type & os) :
0069         m_ostream (& os)
0070     {}
0071     ostream_iterator() :
0072         m_ostream (NULL)
0073     {}
0074     ostream_iterator(const ostream_iterator & rhs) :
0075         m_ostream (rhs.m_ostream)
0076     {}
0077 };
0078 
0079 } // namespace iterators
0080 } // namespace archive
0081 } // namespace boost
0082 
0083 #endif // BOOST_ARCHIVE_ITERATORS_OSTREAM_ITERATOR_HPP