123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #if !defined(BOOST_FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)
- #define BOOST_FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED
- #include <boost/assert.hpp>
- #include <boost/spirit/include/classic_multi_pass.hpp>
- #include <boost/wave/wave_config.hpp>
- #ifdef BOOST_HAS_ABI_HEADERS
- #include BOOST_ABI_PREFIX
- #endif
- namespace boost {
- namespace wave {
- namespace util {
- struct functor_input {
- template <typename FunctorT>
- class inner {
- private:
- typedef typename FunctorT::result_type result_type;
- public:
- typedef result_type value_type;
- private:
- struct Data {
- Data(FunctorT const &ftor_)
- : ftor(ftor_), was_initialized(false)
- {}
- FunctorT ftor;
- value_type curtok;
- bool was_initialized;
- };
-
-
-
- friend struct Data;
- public:
- typedef std::ptrdiff_t difference_type;
- typedef result_type *pointer;
- typedef result_type &reference;
- protected:
- inner()
- : data(0)
- {}
- inner(FunctorT const &x)
- : data(new Data(x))
- {}
- inner(inner const &x)
- : data(x.data)
- {}
- void destroy()
- {
- delete data;
- data = 0;
- }
- bool same_input(inner const &x) const
- {
- return data == x.data;
- }
- void swap(inner &x)
- {
- boost::spirit::classic::impl::mp_swap(data, x.data);
- }
- void ensure_initialized() const
- {
- if (data && !data->was_initialized) {
- data->curtok = (data->ftor)();
- data->was_initialized = true;
- }
- }
- public:
- reference get_input() const
- {
- ensure_initialized();
- return data->curtok;
- }
- void advance_input()
- {
- BOOST_ASSERT(0 != data);
- data->curtok = (data->ftor)();
- data->was_initialized = true;
- }
- bool input_at_eof() const
- {
- ensure_initialized();
- return !data || data->curtok == data->ftor.eof;
- }
- FunctorT& get_functor() const
- {
- BOOST_ASSERT(0 != data);
- return data->ftor;
- }
- private:
- mutable Data *data;
- };
- };
- }
- }
- }
- #ifdef BOOST_HAS_ABI_HEADERS
- #include BOOST_ABI_SUFFIX
- #endif
- #endif
|