[857] | 1 | #ifndef BOOST_ARCHIVE_ITERATORS_HEAD_ITERATOR_HPP
|
---|
| 2 | #define BOOST_ARCHIVE_ITERATORS_HEAD_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 | // head_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 | #include <boost/type_traits/is_same.hpp>
|
---|
| 20 | #include <boost/iterator/iterator_adaptor.hpp>
|
---|
| 21 | #include <boost/iterator/iterator_traits.hpp>
|
---|
| 22 |
|
---|
| 23 | namespace boost {
|
---|
| 24 | namespace archive {
|
---|
| 25 | namespace iterators {
|
---|
| 26 |
|
---|
| 27 | template<class Predicate, class Base>
|
---|
| 28 | class head_iterator
|
---|
| 29 | : public boost::iterator_adaptor<
|
---|
| 30 | head_iterator<Predicate, Base>,
|
---|
| 31 | Base,
|
---|
| 32 | use_default,
|
---|
| 33 | single_pass_traversal_tag
|
---|
| 34 | >
|
---|
| 35 | {
|
---|
| 36 | private:
|
---|
| 37 | friend class iterator_core_access;
|
---|
| 38 | typedef boost::iterator_adaptor<
|
---|
| 39 | head_iterator<Predicate, Base>,
|
---|
| 40 | Base,
|
---|
| 41 | use_default,
|
---|
| 42 | single_pass_traversal_tag
|
---|
| 43 | > super_t;
|
---|
| 44 |
|
---|
| 45 | typedef head_iterator<Predicate, Base> this_t;
|
---|
| 46 | typedef BOOST_DEDUCED_TYPENAME super_t::value_type value_type;
|
---|
| 47 | typedef BOOST_DEDUCED_TYPENAME super_t::reference reference_type;
|
---|
| 48 |
|
---|
| 49 | reference_type dereference_impl(){
|
---|
| 50 | if(! m_end){
|
---|
| 51 | while(! m_predicate(* base_reference()))
|
---|
| 52 | ++ base_reference();
|
---|
| 53 | m_end = true;
|
---|
| 54 | }
|
---|
| 55 | return * base_reference();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | reference_type dereference() const {
|
---|
| 59 | return const_cast<this_t *>(this)->dereference_impl();
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void increment(){
|
---|
| 63 | ++base_reference();
|
---|
| 64 | }
|
---|
| 65 | Predicate m_predicate;
|
---|
| 66 | bool m_end;
|
---|
| 67 | public:
|
---|
| 68 | template<class T>
|
---|
| 69 | head_iterator(Predicate f, T start) :
|
---|
| 70 | super_t(Base(start)),
|
---|
| 71 | m_predicate(f),
|
---|
| 72 | m_end(false)
|
---|
| 73 | {}
|
---|
| 74 |
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | } // namespace iterators
|
---|
| 78 | } // namespace archive
|
---|
| 79 | } // namespace boost
|
---|
| 80 |
|
---|
| 81 | #endif // BOOST_ARCHIVE_ITERATORS_HEAD_ITERATOR_HPP
|
---|