Chris@16: #ifndef BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP Chris@16: #define BOOST_ARCHIVE_ITERATORS_ISTREAM_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: // istream_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 istream_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 // NULL 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 istream_iterator : Chris@16: public boost::iterator_facade< Chris@16: istream_iterator, Chris@16: Elem, Chris@16: std::input_iterator_tag, Chris@16: Elem Chris@16: > Chris@16: { Chris@16: friend class boost::iterator_core_access; Chris@16: typedef istream_iterator this_t ; Chris@101: typedef typename boost::iterator_facade< Chris@16: istream_iterator, Chris@16: Elem, Chris@16: std::input_iterator_tag, Chris@16: Elem Chris@16: > super_t; Chris@101: typedef typename std::basic_istream istream_type; Chris@16: Chris@16: bool equal(const this_t & rhs) const { Chris@16: // note: only works for comparison against end of stream Chris@16: return m_istream == rhs.m_istream; Chris@16: } Chris@16: Chris@16: /* Chris@16: //Access the value referred to Chris@16: Elem dereference() const { Chris@16: return m_current_value; Chris@16: } Chris@16: Chris@16: void increment(){ Chris@16: if(NULL != m_istream){ Chris@16: m_current_value = static_cast(m_istream->get()); Chris@16: if(! m_istream->good()){ Chris@16: const_cast(this)->m_istream = NULL; Chris@16: } Chris@16: } Chris@16: } Chris@16: */ Chris@16: //Access the value referred to Chris@16: Elem dereference() const { Chris@16: return m_istream->peek(); Chris@16: } Chris@16: Chris@16: void increment(){ Chris@16: if(NULL != m_istream){ Chris@16: m_istream->ignore(1); Chris@16: } Chris@16: } Chris@16: Chris@16: istream_type *m_istream; Chris@16: Elem m_current_value; Chris@16: public: Chris@16: istream_iterator(istream_type & is) : Chris@16: m_istream(& is) Chris@16: { Chris@16: //increment(); Chris@16: } Chris@16: Chris@16: istream_iterator() : Chris@16: m_istream(NULL) Chris@16: {} Chris@16: Chris@16: istream_iterator(const istream_iterator & rhs) : Chris@16: m_istream(rhs.m_istream), Chris@16: m_current_value(rhs.m_current_value) Chris@16: {} 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_ISTREAM_ITERATOR_HPP