Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Definition of the preprocessor context Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED) Chris@16: #define CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED Chris@16: Chris@16: #include Chris@16: #include Chris@16: #if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: // #include // make_multi_pass Chris@16: Chris@16: // this must occur after all of the includes and before any code appears Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { Chris@16: namespace wave { Chris@16: namespace iteration_context_policies { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // The iteration_context_policies templates are policies for the Chris@16: // boost::wave::iteration_context which allows to control, how a given Chris@16: // input file is to be represented by a pair of iterators pointing to the Chris@16: // begin and the end of the resulting input sequence. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // load_file_to_string Chris@16: // Chris@16: // Loads a file into a string and returns the iterators pointing to Chris@16: // the beginning and the end of the loaded string. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: struct load_file_to_string Chris@16: { Chris@16: template Chris@16: class inner Chris@16: { Chris@16: public: Chris@16: template Chris@16: static void init_iterators(IterContextT &iter_ctx, Chris@16: PositionT const &act_pos, language_support language) Chris@16: { Chris@16: typedef typename IterContextT::iterator_type iterator_type; Chris@16: Chris@16: // read in the file Chris@16: std::ifstream instream(iter_ctx.filename.c_str()); Chris@16: if (!instream.is_open()) { Chris@16: BOOST_WAVE_THROW_CTX(iter_ctx.ctx, preprocess_exception, Chris@16: bad_include_file, iter_ctx.filename.c_str(), act_pos); Chris@16: return; Chris@16: } Chris@16: instream.unsetf(std::ios::skipws); Chris@16: Chris@16: iter_ctx.instring.assign( Chris@16: std::istreambuf_iterator(instream.rdbuf()), Chris@16: std::istreambuf_iterator()); Chris@16: Chris@16: iter_ctx.first = iterator_type( Chris@16: iter_ctx.instring.begin(), iter_ctx.instring.end(), Chris@16: PositionT(iter_ctx.filename), language); Chris@16: iter_ctx.last = iterator_type(); Chris@16: } Chris@16: Chris@16: private: Chris@16: std::string instring; Chris@16: }; Chris@16: }; Chris@16: Chris@16: } // namespace iteration_context_policies Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Base class for iteration contexts Chris@16: template Chris@16: struct base_iteration_context Chris@16: { Chris@16: enum file_type Chris@16: { Chris@16: // this iteration context handles ... Chris@16: main_file, // ... the main preprocessed file Chris@16: system_header, // ... a header file included used #include <> Chris@16: user_header // ... a header file included using #include "" Chris@16: }; Chris@16: Chris@16: base_iteration_context(ContextT& ctx_, Chris@16: BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0) Chris@16: : real_filename(fname), real_relative_filename(fname), filename(fname), Chris@16: line(1), emitted_lines(0), if_block_depth(if_block_depth), ctx(ctx_), Chris@16: type(main_file) Chris@16: {} Chris@16: base_iteration_context(ContextT& ctx_, Chris@16: IteratorT const &first_, IteratorT const &last_, Chris@16: BOOST_WAVE_STRINGTYPE const &fname, std::size_t if_block_depth = 0, Chris@16: file_type type_ = main_file) Chris@16: : first(first_), last(last_), real_filename(fname), Chris@16: real_relative_filename(fname), filename(fname), Chris@16: line(1), emitted_lines(0), if_block_depth(if_block_depth), ctx(ctx_), Chris@16: type(type_) Chris@16: {} Chris@16: Chris@16: // the actual input stream Chris@16: IteratorT first; // actual input stream position Chris@16: IteratorT last; // end of input stream Chris@16: BOOST_WAVE_STRINGTYPE real_filename; // real name of the current file Chris@16: BOOST_WAVE_STRINGTYPE real_relative_filename; // real relative name of the current file Chris@16: BOOST_WAVE_STRINGTYPE filename; // actual processed file Chris@16: std::size_t line; // line counter of underlying stream Chris@16: std::size_t emitted_lines; // count of emitted newlines Chris@16: std::size_t if_block_depth; // depth of #if block recursion Chris@16: ContextT& ctx; // corresponding context<> object Chris@16: file_type type; // the type of the handled file Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: template < Chris@16: typename ContextT, typename IteratorT, Chris@16: typename InputPolicyT = typename ContextT::input_policy_type Chris@16: > Chris@16: struct iteration_context Chris@16: : public base_iteration_context, Chris@16: public InputPolicyT::template Chris@16: inner > Chris@16: { Chris@16: typedef IteratorT iterator_type; Chris@16: typedef typename IteratorT::token_type::position_type position_type; Chris@16: Chris@16: typedef base_iteration_context base_type; Chris@16: typedef iteration_context self_type; Chris@16: Chris@16: iteration_context(ContextT& ctx, BOOST_WAVE_STRINGTYPE const &fname, Chris@16: position_type const &act_pos, Chris@16: boost::wave::language_support language_, Chris@16: typename base_type::file_type type = base_type::main_file) Chris@16: : base_iteration_context(ctx, fname, type) Chris@16: { Chris@16: InputPolicyT::template inner::init_iterators( Chris@16: *this, act_pos, language_); Chris@16: } Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: } // namespace wave Chris@16: } // namespace boost Chris@16: Chris@16: // the suffix header occurs after all of the code Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // !defined(CPP_ITERATION_CONTEXT_HPP_00312288_9DDB_4668_AFE5_25D3994FD095_INCLUDED)