1 // Copyright (c) 2001 Daniel C. Nuffer
2 // Copyright (c) 2001-2010 Hartmut Kaiser
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_ITERATOR_LEX_INPUT_POLICY_MAR_16_2007_1205PM)
8 #define BOOST_SPIRIT_ITERATOR_LEX_INPUT_POLICY_MAR_16_2007_1205PM
10 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
11 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
13 namespace boost { namespace spirit { namespace iterator_policies
15 ///////////////////////////////////////////////////////////////////////////////
17 // Implementation of the InputPolicy used by multi_pass
19 // The lex_input class gets tokens (integers) from yylex()
20 ///////////////////////////////////////////////////////////////////////////
23 typedef int value_type;
25 ///////////////////////////////////////////////////////////////////////
27 class unique : public detail::default_input_policy
30 typedef std::ptrdiff_t difference_type;
31 typedef std::ptrdiff_t distance_type;
33 typedef int& reference;
40 template <typename MultiPass>
41 static typename MultiPass::reference get_input(MultiPass& mp)
43 value_type& curtok = mp.shared()->curtok;
52 template <typename MultiPass>
53 static void advance_input(MultiPass& mp)
56 mp.shared()->curtok = yylex();
59 // test, whether we reached the end of the underlying stream
60 template <typename MultiPass>
61 static bool input_at_eof(MultiPass const& mp)
63 return mp.shared()->curtok == 0;
66 template <typename MultiPass>
67 static bool input_is_valid(MultiPass const&, value_type const& t)
73 ///////////////////////////////////////////////////////////////////////
77 explicit shared(T) : curtok(-1) {}
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