1 /*=============================================================================
2 Boost.Wave: A Standard compliant C++ preprocessor library
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
7 Software License, Version 1.0. (See accompanying file
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
11 #if !defined(FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)
12 #define FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED
14 #include <boost/assert.hpp>
15 #include <boost/spirit/include/classic_multi_pass.hpp>
16 #include <boost/wave/wave_config.hpp>
18 // this must occur after all of the includes and before any code appears
19 #ifdef BOOST_HAS_ABI_HEADERS
20 #include BOOST_ABI_PREFIX
23 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
30 // class functor_input
32 // Implementation of the InputPolicy used by multi_pass
33 // functor_input gets tokens from a functor
34 // Note: the functor must have a typedef for result_type
35 // It also must have a static variable of type result_type defined
36 // to represent eof that is called eof.
38 // This functor input policy template is essentially the same as the
39 // predefined multi_pass functor_input policy. The difference is,
40 // that the first token is not read at initialization time, but only
41 // just before returning the first token. Additionally it does not
42 // call operator new() twice but only once.
44 ///////////////////////////////////////////////////////////////////////////////
45 struct functor_input {
47 template <typename FunctorT>
50 typedef typename FunctorT::result_type result_type;
53 typedef result_type value_type;
57 Data(FunctorT const &ftor_)
58 : ftor(ftor_), was_initialized(false)
66 // Needed by compilers not implementing the resolution to DR45. For
68 // http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#45.
73 typedef std::ptrdiff_t difference_type;
74 typedef result_type *pointer;
75 typedef result_type &reference;
82 inner(FunctorT const &x)
96 bool same_input(inner const &x) const
98 return data == x.data;
103 boost::spirit::classic::impl::mp_swap(data, x.data);
106 void ensure_initialized() const
108 if (data && !data->was_initialized) {
109 data->curtok = (data->ftor)(); // get the first token
110 data->was_initialized = true;
115 reference get_input() const
117 ensure_initialized();
123 BOOST_ASSERT(0 != data);
124 data->curtok = (data->ftor)();
125 data->was_initialized = true;
128 bool input_at_eof() const
130 ensure_initialized();
131 return !data || data->curtok == data->ftor.eof;
134 FunctorT& get_functor() const
136 BOOST_ASSERT(0 != data);
145 ///////////////////////////////////////////////////////////////////////////////
150 // the suffix header occurs after all of the code
151 #ifdef BOOST_HAS_ABI_HEADERS
152 #include BOOST_ABI_SUFFIX
155 #endif // !defined(FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)