File indexing completed on 2025-01-18 09:53:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #if !defined(BOOST_FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)
0012 #define BOOST_FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED
0013
0014 #include <boost/assert.hpp>
0015 #include <boost/spirit/include/classic_multi_pass.hpp>
0016 #include <boost/wave/wave_config.hpp>
0017
0018
0019 #ifdef BOOST_HAS_ABI_HEADERS
0020 #include BOOST_ABI_PREFIX
0021 #endif
0022
0023
0024 namespace boost {
0025 namespace wave {
0026 namespace util {
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 struct functor_input {
0046
0047 template <typename FunctorT>
0048 class inner {
0049 private:
0050 typedef typename FunctorT::result_type result_type;
0051
0052 public:
0053 typedef result_type value_type;
0054
0055 private:
0056 struct Data {
0057 Data(FunctorT const &ftor_)
0058 : ftor(ftor_), was_initialized(false)
0059 {}
0060
0061 FunctorT ftor;
0062 value_type curtok;
0063 bool was_initialized;
0064 };
0065
0066
0067
0068
0069
0070 friend struct Data;
0071
0072 public:
0073 typedef std::ptrdiff_t difference_type;
0074 typedef result_type *pointer;
0075 typedef result_type &reference;
0076
0077 protected:
0078 inner()
0079 : data(0)
0080 {}
0081
0082 inner(FunctorT const &x)
0083 : data(new Data(x))
0084 {}
0085
0086 inner(inner const &x)
0087 : data(x.data)
0088 {}
0089
0090 void destroy()
0091 {
0092 delete data;
0093 data = 0;
0094 }
0095
0096 bool same_input(inner const &x) const
0097 {
0098 return data == x.data;
0099 }
0100
0101 void swap(inner &x)
0102 {
0103 boost::spirit::classic::impl::mp_swap(data, x.data);
0104 }
0105
0106 void ensure_initialized() const
0107 {
0108 if (data && !data->was_initialized) {
0109 data->curtok = (data->ftor)();
0110 data->was_initialized = true;
0111 }
0112 }
0113
0114 public:
0115 reference get_input() const
0116 {
0117 ensure_initialized();
0118 return data->curtok;
0119 }
0120
0121 void advance_input()
0122 {
0123 BOOST_ASSERT(0 != data);
0124 data->curtok = (data->ftor)();
0125 data->was_initialized = true;
0126 }
0127
0128 bool input_at_eof() const
0129 {
0130 ensure_initialized();
0131 return !data || data->curtok == data->ftor.eof;
0132 }
0133
0134 FunctorT& get_functor() const
0135 {
0136 BOOST_ASSERT(0 != data);
0137 return data->ftor;
0138 }
0139
0140 private:
0141 mutable Data *data;
0142 };
0143 };
0144
0145
0146 }
0147 }
0148 }
0149
0150
0151 #ifdef BOOST_HAS_ABI_HEADERS
0152 #include BOOST_ABI_SUFFIX
0153 #endif
0154
0155 #endif