1 #ifndef BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP 2 #define BOOST_ARCHIVE_ITERATORS_ISTREAM_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 // istream_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 istream_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 <cstddef> // NULL 25 #include <istream> 26 #include <boost/iterator/iterator_facade.hpp> 27 28 namespace boost { 29 namespace archive { 30 namespace iterators { 31 32 // given a type, make an input iterator based on a pointer to that type 33 template<class Elem = char> 34 class istream_iterator : 35 public boost::iterator_facade< 36 istream_iterator<Elem>, 37 Elem, 38 std::input_iterator_tag, 39 Elem 40 > 41 { 42 friend class boost::iterator_core_access; 43 typedef istream_iterator this_t ; 44 typedef typename boost::iterator_facade< 45 istream_iterator<Elem>, 46 Elem, 47 std::input_iterator_tag, 48 Elem 49 > super_t; 50 typedef typename std::basic_istream<Elem> istream_type; 51 equal(const this_t & rhs) const52 bool equal(const this_t & rhs) const { 53 // note: only works for comparison against end of stream 54 return m_istream == rhs.m_istream; 55 } 56 57 //Access the value referred to dereference() const58 Elem dereference() const { 59 return static_cast<Elem>(m_istream->peek()); 60 } 61 increment()62 void increment(){ 63 if(NULL != m_istream){ 64 m_istream->ignore(1); 65 } 66 } 67 68 istream_type *m_istream; 69 Elem m_current_value; 70 public: istream_iterator(istream_type & is)71 istream_iterator(istream_type & is) : 72 m_istream(& is) 73 { 74 //increment(); 75 } 76 istream_iterator()77 istream_iterator() : 78 m_istream(NULL), 79 m_current_value(NULL) 80 {} 81 istream_iterator(const istream_iterator<Elem> & rhs)82 istream_iterator(const istream_iterator<Elem> & rhs) : 83 m_istream(rhs.m_istream), 84 m_current_value(rhs.m_current_value) 85 {} 86 }; 87 88 } // namespace iterators 89 } // namespace archive 90 } // namespace boost 91 92 #endif // BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP 93