Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:47:35

0001 //  Copyright (c) 2001-2011 Hartmut Kaiser
0002 //
0003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_SPIRIT_KARMA_DETAIL_INDIRECT_ITERATOR_HPP
0007 #define BOOST_SPIRIT_KARMA_DETAIL_INDIRECT_ITERATOR_HPP
0008 
0009 #if defined(_MSC_VER)
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/spirit/home/support/unused.hpp>
0014 #include <boost/iterator/iterator_facade.hpp>
0015 #include <iterator> // for std::iterator_traits
0016 
0017 ///////////////////////////////////////////////////////////////////////////////
0018 namespace boost { namespace spirit { namespace karma { namespace detail
0019 {
0020     ///////////////////////////////////////////////////////////////////////
0021     // This is a wrapper for any iterator allowing to pass a reference of it
0022     // to the components of the sequence
0023     template <typename Iterator>
0024     class indirect_iterator
0025       : public boost::iterator_facade<
0026             indirect_iterator<Iterator>
0027           , typename std::iterator_traits<Iterator>::value_type
0028           , boost::forward_traversal_tag
0029           , typename std::iterator_traits<Iterator>::reference>
0030     {
0031         typedef typename std::iterator_traits<Iterator>::value_type
0032             base_value_type;
0033         typedef typename std::iterator_traits<Iterator>::reference
0034             base_reference_type;
0035 
0036         typedef boost::iterator_facade<
0037             indirect_iterator<Iterator>, base_value_type
0038           , boost::forward_traversal_tag, base_reference_type
0039         > base_type;
0040 
0041     public:
0042         indirect_iterator(Iterator& iter)
0043           : iter_(&iter)
0044         {}
0045         indirect_iterator(indirect_iterator const& iter)
0046           : iter_(iter.iter_)
0047         {}
0048 
0049     private:
0050         friend class boost::iterator_core_access;
0051 
0052         void increment()
0053         {
0054             ++*iter_;
0055         }
0056 
0057         bool equal(indirect_iterator const& other) const
0058         {
0059             return *iter_ == *other.iter_;
0060         }
0061 
0062         base_reference_type dereference() const
0063         {
0064             return **iter_;
0065         }
0066 
0067     private:
0068         Iterator* iter_;
0069     };
0070 }}}}
0071 
0072 ///////////////////////////////////////////////////////////////////////////////
0073 namespace boost { namespace spirit { namespace traits
0074 {
0075     template <typename Iterator>
0076     struct make_indirect_iterator
0077     {
0078         typedef karma::detail::indirect_iterator<Iterator> type;
0079     };
0080 
0081     template <typename Iterator>
0082     struct make_indirect_iterator<karma::detail::indirect_iterator<Iterator> >
0083     {
0084         typedef karma::detail::indirect_iterator<Iterator> type;
0085     };
0086 
0087     template <>
0088     struct make_indirect_iterator<unused_type const*>
0089     {
0090         typedef unused_type const* type;
0091     };
0092 
0093     template <typename Iterator>
0094     struct make_indirect_iterator<Iterator const&>
0095       : make_indirect_iterator<Iterator const>
0096     {};
0097 }}}
0098 
0099 #endif