Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / iterators / istream_iterator.hpp @ 2486

History | View | Annotate | Download (2.8 kB)

1 2486 sjacqu01
#ifndef BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP
2 2486 sjacqu01
#define BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP
3 2486 sjacqu01
4 2486 sjacqu01
// MS compatible compilers support #pragma once
5 2486 sjacqu01
#if defined(_MSC_VER)
6 2486 sjacqu01
# pragma once
7 2486 sjacqu01
#endif
8 2486 sjacqu01
9 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 2486 sjacqu01
// istream_iterator.hpp
11 2486 sjacqu01
12 2486 sjacqu01
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 2486 sjacqu01
// Use, modification and distribution is subject to the Boost Software
14 2486 sjacqu01
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 2486 sjacqu01
// http://www.boost.org/LICENSE_1_0.txt)
16 2486 sjacqu01
17 2486 sjacqu01
//  See http://www.boost.org for updates, documentation, and revision history.
18 2486 sjacqu01
19 2486 sjacqu01
// note: this is a custom version of the standard istream_iterator.
20 2486 sjacqu01
// This is necessary as the standard version doesn't work as expected
21 2486 sjacqu01
// for wchar_t based streams on systems for which wchar_t not a true
22 2486 sjacqu01
// type but rather a synonym for some integer type.
23 2486 sjacqu01
24 2486 sjacqu01
#include <cstddef> // NULL
25 2486 sjacqu01
#include <istream>
26 2486 sjacqu01
#include <boost/iterator/iterator_facade.hpp>
27 2486 sjacqu01
28 2486 sjacqu01
namespace boost {
29 2486 sjacqu01
namespace archive {
30 2486 sjacqu01
namespace iterators {
31 2486 sjacqu01
32 2486 sjacqu01
// given a type, make an input iterator based on a pointer to that type
33 2486 sjacqu01
template<class Elem = char>
34 2486 sjacqu01
class istream_iterator :
35 2486 sjacqu01
    public boost::iterator_facade<
36 2486 sjacqu01
        istream_iterator<Elem>,
37 2486 sjacqu01
        Elem,
38 2486 sjacqu01
        std::input_iterator_tag,
39 2486 sjacqu01
        Elem
40 2486 sjacqu01
    >
41 2486 sjacqu01
{
42 2486 sjacqu01
    friend class boost::iterator_core_access;
43 2486 sjacqu01
    typedef istream_iterator this_t ;
44 2486 sjacqu01
    typedef typename boost::iterator_facade<
45 2486 sjacqu01
        istream_iterator<Elem>,
46 2486 sjacqu01
        Elem,
47 2486 sjacqu01
        std::input_iterator_tag,
48 2486 sjacqu01
        Elem
49 2486 sjacqu01
    > super_t;
50 2486 sjacqu01
    typedef typename std::basic_istream<Elem> istream_type;
51 2486 sjacqu01
52 2486 sjacqu01
    bool equal(const this_t & rhs) const {
53 2486 sjacqu01
        // note: only  works for comparison against end of stream
54 2486 sjacqu01
        return m_istream == rhs.m_istream;
55 2486 sjacqu01
    }
56 2486 sjacqu01
57 2486 sjacqu01
/*
58 2486 sjacqu01
    //Access the value referred to
59 2486 sjacqu01
    Elem dereference() const {
60 2486 sjacqu01
        return m_current_value;
61 2486 sjacqu01
    }
62 2486 sjacqu01

63 2486 sjacqu01
    void increment(){
64 2486 sjacqu01
        if(NULL != m_istream){
65 2486 sjacqu01
            m_current_value = static_cast<Elem>(m_istream->get());
66 2486 sjacqu01
            if(! m_istream->good()){
67 2486 sjacqu01
                const_cast<this_t *>(this)->m_istream = NULL;
68 2486 sjacqu01
            }
69 2486 sjacqu01
        }
70 2486 sjacqu01
    }
71 2486 sjacqu01
*/
72 2486 sjacqu01
    //Access the value referred to
73 2486 sjacqu01
    Elem dereference() const {
74 2486 sjacqu01
        return m_istream->peek();
75 2486 sjacqu01
    }
76 2486 sjacqu01
77 2486 sjacqu01
    void increment(){
78 2486 sjacqu01
        if(NULL != m_istream){
79 2486 sjacqu01
            m_istream->ignore(1);
80 2486 sjacqu01
        }
81 2486 sjacqu01
    }
82 2486 sjacqu01
83 2486 sjacqu01
    istream_type *m_istream;
84 2486 sjacqu01
    Elem m_current_value;
85 2486 sjacqu01
public:
86 2486 sjacqu01
    istream_iterator(istream_type & is) :
87 2486 sjacqu01
        m_istream(& is)
88 2486 sjacqu01
    {
89 2486 sjacqu01
        //increment();
90 2486 sjacqu01
    }
91 2486 sjacqu01
92 2486 sjacqu01
    istream_iterator() :
93 2486 sjacqu01
        m_istream(NULL)
94 2486 sjacqu01
    {}
95 2486 sjacqu01
96 2486 sjacqu01
    istream_iterator(const istream_iterator<Elem> & rhs) :
97 2486 sjacqu01
        m_istream(rhs.m_istream),
98 2486 sjacqu01
        m_current_value(rhs.m_current_value)
99 2486 sjacqu01
    {}
100 2486 sjacqu01
101 2486 sjacqu01
};
102 2486 sjacqu01
103 2486 sjacqu01
} // namespace iterators
104 2486 sjacqu01
} // namespace archive
105 2486 sjacqu01
} // namespace boost
106 2486 sjacqu01
107 2486 sjacqu01
#endif // BOOST_ARCHIVE_ITERATORS_ISTREAM_ITERATOR_HPP