1 // Copyright (c) 2001-2011 Hartmut Kaiser
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)
6 #if !defined(BOOST_SPIRIT_ITERATOR_SPLIT_FUNCTOR_INPUT_POLICY_JAN_16_2008_0448M)
7 #define BOOST_SPIRIT_ITERATOR_SPLIT_FUNCTOR_INPUT_POLICY_JAN_16_2008_0448M
9 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
10 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
11 #include <boost/assert.hpp>
13 namespace boost { namespace spirit { namespace iterator_policies
15 namespace is_valid_test_
17 template <typename Token>
18 inline bool token_is_valid(Token const&)
24 ///////////////////////////////////////////////////////////////////////////
25 // class functor_input
26 // Implementation of the InputPolicy used by multi_pass
27 // functor_input gets tokens from a functor
29 // Note: the functor must have a typedef for result_type
30 // It also must have a static variable of type result_type defined
31 // to represent EOF that is called eof.
33 ///////////////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////
37 template <typename Functor>
38 class unique : public detail::default_input_policy
41 typedef typename Functor::result_type result_type;
45 explicit unique(Functor const& x) : ftor(x) {}
49 boost::swap(ftor, x.ftor);
53 typedef result_type value_type;
54 typedef std::ptrdiff_t difference_type;
55 typedef std::ptrdiff_t distance_type;
56 typedef result_type* pointer;
57 typedef result_type& reference;
61 template <typename MultiPass>
62 static typename MultiPass::reference get_input(MultiPass& mp)
64 value_type& curtok = mp.shared()->curtok;
65 if (!input_is_valid(mp, curtok))
70 template <typename MultiPass>
71 static void advance_input(MultiPass& mp)
73 // if mp.shared is NULL then this instance of the multi_pass
74 // represents a end iterator
75 BOOST_ASSERT(0 != mp.shared());
76 mp.shared()->curtok = mp.ftor();
79 // test, whether we reached the end of the underlying stream
80 template <typename MultiPass>
81 static bool input_at_eof(MultiPass const& mp)
83 return mp.shared()->curtok == mp.ftor.eof;
86 template <typename MultiPass>
87 static bool input_is_valid(MultiPass const&, value_type const& t)
89 using namespace is_valid_test_;
90 return token_is_valid(t);
93 Functor& get_functor() const
102 ///////////////////////////////////////////////////////////////////////
103 template <typename Functor>
106 explicit shared(Functor const&) : curtok(0) {}
108 typename Functor::result_type curtok;
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams