Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // (C) Copyright Gennadiy Rozental 2004-2008. |
| 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$ |
| 9 | // |
| 10 | // Version : $Revision: 49312 $ |
| 11 | // |
| 12 | // Description : Input iterator facade |
| 13 | // *************************************************************************** |
| 14 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 15 | #ifndef NDNBOOST_INPUT_ITERATOR_FACADE_HPP_071894GER |
| 16 | #define NDNBOOST_INPUT_ITERATOR_FACADE_HPP_071894GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | // Boost |
| 19 | #include <ndnboost/iterator/iterator_facade.hpp> |
| 20 | |
| 21 | #include <ndnboost/test/detail/suppress_warnings.hpp> |
| 22 | |
| 23 | //____________________________________________________________________________// |
| 24 | |
| 25 | namespace ndnboost { |
| 26 | |
| 27 | namespace unit_test { |
| 28 | |
| 29 | // ************************************************************************** // |
| 30 | // ************** input_iterator_core_access ************** // |
| 31 | // ************************************************************************** // |
| 32 | |
| 33 | class input_iterator_core_access |
| 34 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 35 | #if defined(NDNBOOST_NO_MEMBER_TEMPLATE_FRIENDS) || NDNBOOST_WORKAROUND(__BORLANDC__, NDNBOOST_TESTED_AT(0x551)) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 ndnboost::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 ndnboost |
| 103 | |
| 104 | //____________________________________________________________________________// |
| 105 | |
| 106 | #include <ndnboost/test/detail/enable_warnings.hpp> |
| 107 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 108 | #endif // NDNBOOST_INPUT_ITERATOR_FACADE_HPP_071894GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 109 | |