Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:42

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003 
0004     http://www.boost.org/
0005 
0006     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0007     Software License, Version 1.0. (See accompanying file
0008     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
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 // this must occur after all of the includes and before any code appears
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 //  class functor_input
0031 //
0032 //      Implementation of the InputPolicy used by multi_pass
0033 //      functor_input gets tokens from a functor
0034 //      Note: the functor must have a typedef for result_type
0035 //            It also must have a static variable of type result_type defined
0036 //            to represent eof that is called eof.
0037 //
0038 //      This functor input policy template is essentially the same as the
0039 //      predefined multi_pass functor_input policy. The difference is,
0040 //      that the first token is not read at initialization time, but only
0041 //      just before returning the first token. Additionally it does not
0042 //      call operator new() twice but only once.
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         // Needed by compilers not implementing the resolution to DR45. For
0067         // reference, see
0068         // http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#45.
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)();    // get the first token
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 }   // namespace util
0147 }   // namespace wave
0148 }   // namespace boost
0149 
0150 // the suffix header occurs after all of the code
0151 #ifdef BOOST_HAS_ABI_HEADERS
0152 #include BOOST_ABI_SUFFIX
0153 #endif
0154 
0155 #endif // !defined(BOOST_FUNCTOR_INPUT_HPP_ED3A4C21_8F8A_453F_B438_08214FAC106A_INCLUDED)