summaryrefslogtreecommitdiffstats
blob: 088b39ae4239513024d140911e8d4e56097f1a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//  Copyright (c) 2001 Daniel C. Nuffer
//  Copyright (c) 2001-2011 Hartmut Kaiser
// 
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(BOOST_SPIRIT_ITERATOR_MULTI_PASS_MAR_16_2007_1122AM)
#define BOOST_SPIRIT_ITERATOR_MULTI_PASS_MAR_16_2007_1122AM

#include <boost/config.hpp>
#include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
#include <boost/iterator.hpp>
#include <boost/mpl/bool.hpp>
#include <iterator>
#include <algorithm> 

///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace detail
{
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
    ///////////////////////////////////////////////////////////////////////////
    //  Meta-function to generate a std::iterator<> base class for multi_pass. 
    //  This is used mainly to improve conformance of compilers not supporting 
    //  PTS and thus relying on inheritance to recognize an iterator.
    //
    //  We are using boost::iterator<> because it offers an automatic 
    //  workaround for broken std::iterator<> implementations.
    ///////////////////////////////////////////////////////////////////////////
    template <typename T, typename InputPolicy>
    struct iterator_base_creator
    {
        typedef typename InputPolicy::BOOST_NESTED_TEMPLATE unique<T> input_type;

        typedef boost::iterator <
            std::forward_iterator_tag
          , typename input_type::value_type
          , typename input_type::difference_type
          , typename input_type::pointer
          , typename input_type::reference
        > type;
    };
#endif

    ///////////////////////////////////////////////////////////////////////////
    //  Default implementations of the different policies to be used with a 
    //  multi_pass iterator
    ///////////////////////////////////////////////////////////////////////////
    struct default_input_policy
    {
        default_input_policy() {}

        template <typename Functor>
        default_input_policy(Functor const&) {}

        template <typename MultiPass>
        static void destroy(MultiPass&) {}

        void swap(default_input_policy&) {}

        template <typename MultiPass, typename TokenType>
        static void advance_input(MultiPass& mp);

        template <typename MultiPass>
        static typename MultiPass::reference get_input(MultiPass& mp);

        template <typename MultiPass>
        static bool input_at_eof(MultiPass const& mp);

        template <typename MultiPass, typename TokenType>
        static bool input_is_valid(MultiPass& mp, TokenType& curtok);
    };

    struct default_ownership_policy
    {
        template <typename MultiPass>
        static void destroy(MultiPass&) {}

        void swap(default_ownership_policy&) {}

        template <typename MultiPass>
        static void clone(MultiPass&) {}

        template <typename MultiPass>
        static bool release(MultiPass& mp);

        template <typename MultiPass>
        static bool is_unique(MultiPass const& mp);
    };

    struct default_storage_policy
    {
        template <typename MultiPass>
        static void destroy(MultiPass&) {}

        void swap(default_storage_policy&) {}

        template <typename MultiPass>
        static typename MultiPass::reference dereference(MultiPass const& mp);

        template <typename MultiPass>
        static void increment(MultiPass&) {}

        template <typename MultiPass>
        static void clear_queue(MultiPass&) {}

        template <typename MultiPass>
        static bool is_eof(MultiPass const& mp);

        template <typename MultiPass>
        static bool equal_to(MultiPass const& mp, MultiPass const& x);

        template <typename MultiPass>
        static bool less_than(MultiPass const& mp, MultiPass const& x);
    };

    struct default_checking_policy
    {
        template <typename MultiPass>
        static void destroy(MultiPass&) {}

        void swap(default_checking_policy&) {}

        template <typename MultiPass>
        static void docheck(MultiPass const&) {}

        template <typename MultiPass>
        static void clear_queue(MultiPass&) {}
    };

}}}

#endif