PageRenderTime 53ms CodeModel.GetById 41ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/spirit/home/karma/detail/indirect_iterator.hpp

http://hadesmem.googlecode.com/
C++ Header | 96 lines | 71 code | 16 blank | 9 comment | 1 complexity | c5432bf420c11e17248e3a822fa496e4 MD5 | raw file
 1//  Copyright (c) 2001-2011 Hartmut Kaiser
 2//
 3//  Distributed under the Boost Software License, Version 1.0. (See accompanying
 4//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 5
 6#if !defined(SPIRIT_KARMA_INDIRECT_ITERATOR_JAN_19_2011_0814PM)
 7#define SPIRIT_KARMA_INDIRECT_ITERATOR_JAN_19_2011_0814PM
 8
 9#if defined(_MSC_VER)
10#pragma once
11#endif
12
13#include <boost/spirit/home/support/unused.hpp>
14#include <boost/iterator/iterator_facade.hpp>
15
16///////////////////////////////////////////////////////////////////////////////
17namespace boost { namespace spirit { namespace karma { namespace detail
18{
19    ///////////////////////////////////////////////////////////////////////
20    // This is a wrapper for any iterator allowing to pass a reference of it
21    // to the components of the sequence
22    template <typename Iterator>
23    class indirect_iterator
24      : public boost::iterator_facade<
25            indirect_iterator<Iterator>
26          , typename boost::detail::iterator_traits<Iterator>::value_type
27          , boost::forward_traversal_tag
28          , typename boost::detail::iterator_traits<Iterator>::value_type const&>
29    {
30        typedef typename boost::detail::iterator_traits<Iterator>::value_type
31            base_value_type;
32
33        typedef boost::iterator_facade<
34            indirect_iterator<Iterator>, base_value_type
35          , boost::forward_traversal_tag, base_value_type const&
36        > base_type;
37
38    public:
39        indirect_iterator(Iterator& iter)
40          : iter_(&iter)
41        {}
42        indirect_iterator(indirect_iterator const& iter)
43          : iter_(iter.iter_)
44        {}
45
46    private:
47        friend class boost::iterator_core_access;
48
49        void increment()
50        {
51            ++*iter_;
52        }
53
54        bool equal(indirect_iterator const& other) const
55        {
56            return *iter_ == *other.iter_;
57        }
58
59        typename base_type::reference dereference() const
60        {
61            return **iter_;
62        }
63
64    private:
65        Iterator* iter_;
66    };
67}}}}
68
69///////////////////////////////////////////////////////////////////////////////
70namespace boost { namespace spirit { namespace traits
71{
72    template <typename Iterator>
73    struct make_indirect_iterator
74    {
75        typedef karma::detail::indirect_iterator<Iterator> type;
76    };
77
78    template <typename Iterator>
79    struct make_indirect_iterator<karma::detail::indirect_iterator<Iterator> >
80    {
81        typedef karma::detail::indirect_iterator<Iterator> type;
82    };
83
84    template <>
85    struct make_indirect_iterator<unused_type const*>
86    {
87        typedef unused_type const* type;
88    };
89
90    template <typename Iterator>
91    struct make_indirect_iterator<Iterator const&>
92      : make_indirect_iterator<Iterator const>
93    {};
94}}}
95
96#endif