Chris@16
|
1 #ifndef BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP
|
Chris@16
|
2 #define BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP
|
Chris@16
|
3
|
Chris@16
|
4 // MS compatible compilers support #pragma once
|
Chris@101
|
5 #if defined(_MSC_VER)
|
Chris@16
|
6 # pragma once
|
Chris@16
|
7 #endif
|
Chris@16
|
8
|
Chris@16
|
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
Chris@16
|
10 // istream_iterator.hpp
|
Chris@16
|
11
|
Chris@16
|
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
Chris@16
|
13 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
15 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
16
|
Chris@16
|
17 // See http://www.boost.org for updates, documentation, and revision history.
|
Chris@16
|
18
|
Chris@16
|
19 // note: this is a custom version of the standard istream_iterator.
|
Chris@16
|
20 // This is necessary as the standard version doesn't work as expected
|
Chris@16
|
21 // for wchar_t based streams on systems for which wchar_t not a true
|
Chris@16
|
22 // type but rather a synonym for some integer type.
|
Chris@16
|
23
|
Chris@16
|
24 #include <cstddef> // NULL
|
Chris@16
|
25 #include <istream>
|
Chris@16
|
26 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 namespace boost {
|
Chris@16
|
29 namespace archive {
|
Chris@16
|
30 namespace iterators {
|
Chris@16
|
31
|
Chris@16
|
32 // given a type, make an input iterator based on a pointer to that type
|
Chris@16
|
33 template<class Elem = char>
|
Chris@16
|
34 class istream_iterator :
|
Chris@16
|
35 public boost::iterator_facade<
|
Chris@16
|
36 istream_iterator<Elem>,
|
Chris@16
|
37 Elem,
|
Chris@16
|
38 std::input_iterator_tag,
|
Chris@16
|
39 Elem
|
Chris@16
|
40 >
|
Chris@16
|
41 {
|
Chris@16
|
42 friend class boost::iterator_core_access;
|
Chris@16
|
43 typedef istream_iterator this_t ;
|
Chris@101
|
44 typedef typename boost::iterator_facade<
|
Chris@16
|
45 istream_iterator<Elem>,
|
Chris@16
|
46 Elem,
|
Chris@16
|
47 std::input_iterator_tag,
|
Chris@16
|
48 Elem
|
Chris@16
|
49 > super_t;
|
Chris@101
|
50 typedef typename std::basic_istream<Elem> istream_type;
|
Chris@16
|
51
|
Chris@16
|
52 bool equal(const this_t & rhs) const {
|
Chris@16
|
53 // note: only works for comparison against end of stream
|
Chris@16
|
54 return m_istream == rhs.m_istream;
|
Chris@16
|
55 }
|
Chris@16
|
56
|
Chris@16
|
57 /*
|
Chris@16
|
58 //Access the value referred to
|
Chris@16
|
59 Elem dereference() const {
|
Chris@16
|
60 return m_current_value;
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 void increment(){
|
Chris@16
|
64 if(NULL != m_istream){
|
Chris@16
|
65 m_current_value = static_cast<Elem>(m_istream->get());
|
Chris@16
|
66 if(! m_istream->good()){
|
Chris@16
|
67 const_cast<this_t *>(this)->m_istream = NULL;
|
Chris@16
|
68 }
|
Chris@16
|
69 }
|
Chris@16
|
70 }
|
Chris@16
|
71 */
|
Chris@16
|
72 //Access the value referred to
|
Chris@16
|
73 Elem dereference() const {
|
Chris@16
|
74 return m_istream->peek();
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 void increment(){
|
Chris@16
|
78 if(NULL != m_istream){
|
Chris@16
|
79 m_istream->ignore(1);
|
Chris@16
|
80 }
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83 istream_type *m_istream;
|
Chris@16
|
84 Elem m_current_value;
|
Chris@16
|
85 public:
|
Chris@16
|
86 istream_iterator(istream_type & is) :
|
Chris@16
|
87 m_istream(& is)
|
Chris@16
|
88 {
|
Chris@16
|
89 //increment();
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 istream_iterator() :
|
Chris@16
|
93 m_istream(NULL)
|
Chris@16
|
94 {}
|
Chris@16
|
95
|
Chris@16
|
96 istream_iterator(const istream_iterator<Elem> & rhs) :
|
Chris@16
|
97 m_istream(rhs.m_istream),
|
Chris@16
|
98 m_current_value(rhs.m_current_value)
|
Chris@16
|
99 {}
|
Chris@16
|
100
|
Chris@16
|
101 };
|
Chris@16
|
102
|
Chris@16
|
103 } // namespace iterators
|
Chris@16
|
104 } // namespace archive
|
Chris@16
|
105 } // namespace boost
|
Chris@16
|
106
|
Chris@16
|
107 #endif // BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP
|