Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:41

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //!@file
0009 //! Input iterator facade
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_UTILS_INPUT_ITERATOR_FACADE_HPP
0013 #define BOOST_TEST_UTILS_INPUT_ITERATOR_FACADE_HPP
0014 
0015 // Boost
0016 #include <boost/iterator/iterator_facade.hpp>
0017 
0018 #include <boost/test/detail/suppress_warnings.hpp>
0019 
0020 //____________________________________________________________________________//
0021 
0022 namespace boost {
0023 namespace unit_test {
0024 namespace utils {
0025 
0026 // ************************************************************************** //
0027 // **************          input_iterator_core_access          ************** //
0028 // ************************************************************************** //
0029 
0030 class input_iterator_core_access
0031 {
0032 #if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
0033 public:
0034 #else
0035     template <class I, class V, class R, class TC> friend class input_iterator_facade;
0036 #endif
0037 
0038     template <class Facade>
0039     static bool get( Facade& f )
0040     {
0041         return f.get();
0042     }
0043 
0044 private:
0045     // objects of this class are useless
0046     input_iterator_core_access(); //undefined
0047 };
0048 
0049 // ************************************************************************** //
0050 // **************            input_iterator_facade             ************** //
0051 // ************************************************************************** //
0052 
0053 template<typename Derived,
0054          typename ValueType,
0055          typename Reference = ValueType const&,
0056          typename Traversal = single_pass_traversal_tag>
0057 class input_iterator_facade : public iterator_facade<Derived,ValueType,Traversal,Reference>
0058 {
0059 public:
0060     // Constructor
0061     input_iterator_facade() : m_valid( false ), m_value() {}
0062 
0063 protected: // provide access to the Derived
0064     void                init()
0065     {
0066         m_valid = true;
0067         increment();
0068     }
0069 
0070     // Data members
0071     mutable bool        m_valid;
0072     ValueType           m_value;
0073 
0074 private:
0075     friend class boost::iterator_core_access;
0076 
0077     // iterator facade interface implementation
0078     void                increment()
0079     {
0080         // we make post-end incrementation indefinetly safe
0081         if( m_valid )
0082             m_valid = input_iterator_core_access::get( *static_cast<Derived*>(this) );
0083     }
0084     Reference           dereference() const
0085     {
0086         return m_value;
0087     }
0088 
0089     // iterator facade interface implementation
0090     bool                equal( input_iterator_facade const& rhs ) const
0091     {
0092         // two invalid iterator equals, inequal otherwise
0093         return !m_valid && !rhs.m_valid;
0094     }
0095 };
0096 
0097 } // namespace utils
0098 } // namespace unit_test
0099 } // namespace boost
0100 
0101 //____________________________________________________________________________//
0102 
0103 #include <boost/test/detail/enable_warnings.hpp>
0104 
0105 #endif // BOOST_TEST_UTILS_INPUT_ITERATOR_FACADE_HPP