comparison DEPENDENCIES/generic/include/boost/archive/iterators/istream_iterator.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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) && (_MSC_VER >= 1020)
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 BOOST_DEDUCED_TYPENAME boost::iterator_facade<
45 istream_iterator<Elem>,
46 Elem,
47 std::input_iterator_tag,
48 Elem
49 > super_t;
50 typedef BOOST_DEDUCED_TYPENAME std::basic_istream<Elem> istream_type;
51
52 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 /*
58 //Access the value referred to
59 Elem dereference() const {
60 return m_current_value;
61 }
62
63 void increment(){
64 if(NULL != m_istream){
65 m_current_value = static_cast<Elem>(m_istream->get());
66 if(! m_istream->good()){
67 const_cast<this_t *>(this)->m_istream = NULL;
68 }
69 }
70 }
71 */
72 //Access the value referred to
73 Elem dereference() const {
74 return m_istream->peek();
75 }
76
77 void increment(){
78 if(NULL != m_istream){
79 m_istream->ignore(1);
80 }
81 }
82
83 istream_type *m_istream;
84 Elem m_current_value;
85 public:
86 istream_iterator(istream_type & is) :
87 m_istream(& is)
88 {
89 //increment();
90 }
91
92 istream_iterator() :
93 m_istream(NULL)
94 {}
95
96 istream_iterator(const istream_iterator<Elem> & rhs) :
97 m_istream(rhs.m_istream),
98 m_current_value(rhs.m_current_value)
99 {}
100
101 };
102
103 } // namespace iterators
104 } // namespace archive
105 } // namespace boost
106
107 #endif // BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP