1 | // (C) Copyright Gennadiy Rozental 2004-2005.
|
---|
2 | // Distributed under the Boost Software License, Version 1.0.
|
---|
3 | // (See accompanying file LICENSE_1_0.txt or copy at
|
---|
4 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
5 |
|
---|
6 | // See http://www.boost.org/libs/test for the library home page.
|
---|
7 | //
|
---|
8 | // File : $RCSfile: input_iterator_facade.hpp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.5 $
|
---|
11 | //
|
---|
12 | // Description : Input iterator facade
|
---|
13 | // ***************************************************************************
|
---|
14 |
|
---|
15 | #ifndef BOOST_INPUT_ITERATOR_FACADE_HPP_071894GER
|
---|
16 | #define BOOST_INPUT_ITERATOR_FACADE_HPP_071894GER
|
---|
17 |
|
---|
18 | // Boost
|
---|
19 | #include <boost/iterator/iterator_facade.hpp>
|
---|
20 |
|
---|
21 | #include <boost/test/detail/suppress_warnings.hpp>
|
---|
22 |
|
---|
23 | //____________________________________________________________________________//
|
---|
24 |
|
---|
25 | namespace boost {
|
---|
26 |
|
---|
27 | namespace unit_test {
|
---|
28 |
|
---|
29 | // ************************************************************************** //
|
---|
30 | // ************** input_iterator_core_access ************** //
|
---|
31 | // ************************************************************************** //
|
---|
32 |
|
---|
33 | class input_iterator_core_access
|
---|
34 | {
|
---|
35 | #if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
---|
36 | public:
|
---|
37 | #else
|
---|
38 | template <class I, class V, class R, class TC> friend class input_iterator_facade;
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | template <class Facade>
|
---|
42 | static bool get( Facade& f )
|
---|
43 | {
|
---|
44 | return f.get();
|
---|
45 | }
|
---|
46 |
|
---|
47 | private:
|
---|
48 | // objects of this class are useless
|
---|
49 | input_iterator_core_access(); //undefined
|
---|
50 | };
|
---|
51 |
|
---|
52 | // ************************************************************************** //
|
---|
53 | // ************** input_iterator_facade ************** //
|
---|
54 | // ************************************************************************** //
|
---|
55 |
|
---|
56 | template<typename Derived,
|
---|
57 | typename ValueType,
|
---|
58 | typename Reference = ValueType const&,
|
---|
59 | typename Traversal = single_pass_traversal_tag>
|
---|
60 | class input_iterator_facade : public iterator_facade<Derived,ValueType,Traversal,Reference>
|
---|
61 | {
|
---|
62 | public:
|
---|
63 | // Constructor
|
---|
64 | input_iterator_facade() : m_valid( false ), m_value() {}
|
---|
65 |
|
---|
66 | protected: // provide access to the Derived
|
---|
67 | void init()
|
---|
68 | {
|
---|
69 | m_valid = true;
|
---|
70 | increment();
|
---|
71 | }
|
---|
72 |
|
---|
73 | // Data members
|
---|
74 | mutable bool m_valid;
|
---|
75 | ValueType m_value;
|
---|
76 |
|
---|
77 | private:
|
---|
78 | friend class boost::iterator_core_access;
|
---|
79 |
|
---|
80 | // iterator facade interface implementation
|
---|
81 | void increment()
|
---|
82 | {
|
---|
83 | // we make post-end incrementation indefinetly safe
|
---|
84 | if( m_valid )
|
---|
85 | m_valid = input_iterator_core_access::get( *static_cast<Derived*>(this) );
|
---|
86 | }
|
---|
87 | Reference dereference() const
|
---|
88 | {
|
---|
89 | return m_value;
|
---|
90 | }
|
---|
91 |
|
---|
92 | // iterator facade interface implementation
|
---|
93 | bool equal( input_iterator_facade const& rhs ) const
|
---|
94 | {
|
---|
95 | // two invalid iterator equals, inequal otherwise
|
---|
96 | return !m_valid && !rhs.m_valid;
|
---|
97 | }
|
---|
98 | };
|
---|
99 |
|
---|
100 | } // namespace unit_test
|
---|
101 |
|
---|
102 | } // namespace boost
|
---|
103 |
|
---|
104 | //____________________________________________________________________________//
|
---|
105 |
|
---|
106 | #include <boost/test/detail/enable_warnings.hpp>
|
---|
107 |
|
---|
108 | // ***************************************************************************
|
---|
109 | // Revision History :
|
---|
110 | //
|
---|
111 | // $Log: input_iterator_facade.hpp,v $
|
---|
112 | // Revision 1.5 2005/05/08 08:55:09 rogeeff
|
---|
113 | // typos and missing descriptions fixed
|
---|
114 | //
|
---|
115 | // Revision 1.4 2005/04/12 06:47:46 rogeeff
|
---|
116 | // help iterator copying
|
---|
117 | //
|
---|
118 | // Revision 1.3 2005/02/20 08:27:09 rogeeff
|
---|
119 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
|
---|
120 | //
|
---|
121 | // Revision 1.2 2005/02/01 06:40:08 rogeeff
|
---|
122 | // copyright update
|
---|
123 | // old log entries removed
|
---|
124 | // minor stilistic changes
|
---|
125 | // depricated tools removed
|
---|
126 | //
|
---|
127 | // Revision 1.1 2005/01/22 18:21:40 rogeeff
|
---|
128 | // moved sharable staff into utils
|
---|
129 | //
|
---|
130 | // ***************************************************************************
|
---|
131 |
|
---|
132 | #endif // BOOST_INPUT_ITERATOR_FACADE_HPP_071894GER
|
---|
133 |
|
---|