Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:23

0001 /*=============================================================================
0002     Boost.Wave: A Standard compliant C++ preprocessor library
0003     Definition of the preprocessor context
0004 
0005     http://www.boost.org/
0006 
0007     Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
0008     Software License, Version 1.0. (See accompanying file
0009     LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 =============================================================================*/
0011 
0012 #if !defined(BOOST_CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED)
0013 #define BOOST_CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED
0014 
0015 #include <iterator>
0016 #include <boost/filesystem/fstream.hpp>
0017 #if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
0018 #include <sstream>
0019 #endif
0020 
0021 #include <boost/wave/wave_config.hpp>
0022 #include <boost/wave/cpp_exceptions.hpp>
0023 #include <boost/wave/language_support.hpp>
0024 #include <boost/wave/util/file_position.hpp>
0025 // #include <boost/spirit/include/iterator/classic_multi_pass.hpp> // make_multi_pass
0026 
0027 // this must occur after all of the includes and before any code appears
0028 #ifdef BOOST_HAS_ABI_HEADERS
0029 #include BOOST_ABI_PREFIX
0030 #endif
0031 
0032 ///////////////////////////////////////////////////////////////////////////////
0033 namespace boost {
0034 namespace wave {
0035 namespace iteration_context_policies {
0036 
0037 ///////////////////////////////////////////////////////////////////////////////
0038 //
0039 //      The iteration_context_policies templates are policies for the
0040 //      boost::wave::iteration_context which allows to control, how a given
0041 //      input file is to be represented by a pair of iterators pointing to the
0042 //      begin and the end of the resulting input sequence.
0043 //
0044 ///////////////////////////////////////////////////////////////////////////////
0045 
0046     ///////////////////////////////////////////////////////////////////////////
0047     //
0048     //  load_file_to_string
0049     //
0050     //      Loads a file into a string and returns the iterators pointing to
0051     //      the beginning and the end of the loaded string.
0052     //
0053     ///////////////////////////////////////////////////////////////////////////
0054     struct load_file_to_string
0055     {
0056         template <typename IterContextT>
0057         class inner
0058         {
0059         public:
0060             template <typename PositionT>
0061             static void init_iterators(IterContextT &iter_ctx,
0062                 PositionT const &act_pos, language_support language)
0063             {
0064                 typedef typename IterContextT::iterator_type iterator_type;
0065 
0066                 // read in the file
0067                 boost::filesystem::ifstream instream(iter_ctx.filename.c_str());
0068                 if (!instream.is_open()) {
0069                     BOOST_WAVE_THROW_CTX(iter_ctx.ctx, preprocess_exception,
0070                         bad_include_file, iter_ctx.filename.c_str(), act_pos);
0071                     return;
0072                 }
0073                 instream.unsetf(std::ios::skipws);
0074 
0075                 iter_ctx.instring.assign(
0076                     std::istreambuf_iterator<char>(instream.rdbuf()),
0077                     std::istreambuf_iterator<char>());
0078 
0079                 iter_ctx.first = iterator_type(
0080                     iter_ctx.instring.begin(), iter_ctx.instring.end(),
0081                     PositionT(iter_ctx.filename), language);
0082                 iter_ctx.last = iterator_type();
0083             }
0084 
0085         private:
0086             std::string instring;
0087         };
0088     };
0089 
0090 }   // namespace iteration_context_policies
0091 
0092 ///////////////////////////////////////////////////////////////////////////////
0093 //  Base class for iteration contexts
0094 template <typename ContextT, typename IteratorT>
0095 struct base_iteration_context
0096 {
0097     enum file_type
0098     {
0099         // this iteration context handles ...
0100         main_file,      // ... the main preprocessed file
0101         system_header,  // ... a header file included used #include  <>
0102         user_header     // ... a header file included using #include ""
0103     };
0104 
0105     base_iteration_context(ContextT& ctx_,
0106             BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0)
0107     :   real_filename(fname), real_relative_filename(fname), filename(fname),
0108         line(1), emitted_lines(0), if_block_depth(if_block_depth), ctx(ctx_),
0109         type(main_file)
0110     {}
0111     base_iteration_context(ContextT& ctx_,
0112             IteratorT const &first_, IteratorT const &last_,
0113             BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0,
0114             file_type type_ = main_file)
0115     :   first(first_), last(last_), real_filename(fname),
0116         real_relative_filename(fname), filename(fname),
0117         line(1), emitted_lines(0), if_block_depth(if_block_depth), ctx(ctx_),
0118         type(type_)
0119     {}
0120 
0121     // the actual input stream
0122     IteratorT first;            // actual input stream position
0123     IteratorT last;             // end of input stream
0124     BOOST_WAVE_STRINGTYPE real_filename;  // real name of the current file
0125     BOOST_WAVE_STRINGTYPE real_relative_filename;  // real relative name of the current file
0126     BOOST_WAVE_STRINGTYPE filename;       // actual processed file
0127     std::size_t line;                     // line counter of underlying stream
0128     std::size_t emitted_lines;            // count of emitted newlines
0129     std::size_t if_block_depth; // depth of #if block recursion
0130     ContextT& ctx;              // corresponding context<> object
0131     file_type type;             // the type of the handled file
0132 };
0133 
0134 ///////////////////////////////////////////////////////////////////////////////
0135 //
0136 template <
0137     typename ContextT, typename IteratorT,
0138     typename InputPolicyT = typename ContextT::input_policy_type
0139 >
0140 struct iteration_context
0141 :   public base_iteration_context<ContextT, IteratorT>,
0142     public InputPolicyT::template
0143         inner<iteration_context<ContextT, IteratorT, InputPolicyT> >
0144 {
0145     typedef IteratorT iterator_type;
0146     typedef typename IteratorT::token_type::position_type position_type;
0147 
0148     typedef base_iteration_context<ContextT, IteratorT> base_type;
0149     typedef iteration_context<ContextT, IteratorT, InputPolicyT> self_type;
0150 
0151     iteration_context(ContextT& ctx, BOOST_WAVE_STRINGTYPE const &fname,
0152             position_type const &act_pos,
0153             boost::wave::language_support language_,
0154             typename base_type::file_type type = base_type::main_file)
0155     :   base_iteration_context<ContextT, IteratorT>(ctx, fname, type)
0156     {
0157         InputPolicyT::template inner<self_type>::init_iterators(
0158             *this, act_pos, language_);
0159     }
0160 };
0161 
0162 ///////////////////////////////////////////////////////////////////////////////
0163 }   // namespace wave
0164 }   // namespace boost
0165 
0166 // the suffix header occurs after all of the code
0167 #ifdef BOOST_HAS_ABI_HEADERS
0168 #include BOOST_ABI_SUFFIX
0169 #endif
0170 
0171 #endif // !defined(BOOST_CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED)