File indexing completed on 2025-01-30 10:02:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
0026
0027
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
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
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
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 }
0091
0092
0093
0094 template <typename ContextT, typename IteratorT>
0095 struct base_iteration_context
0096 {
0097 enum file_type
0098 {
0099
0100 main_file,
0101 system_header,
0102 user_header
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
0122 IteratorT first;
0123 IteratorT last;
0124 BOOST_WAVE_STRINGTYPE real_filename;
0125 BOOST_WAVE_STRINGTYPE real_relative_filename;
0126 BOOST_WAVE_STRINGTYPE filename;
0127 std::size_t line;
0128 std::size_t emitted_lines;
0129 std::size_t if_block_depth;
0130 ContextT& ctx;
0131 file_type type;
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 }
0164 }
0165
0166
0167 #ifdef BOOST_HAS_ABI_HEADERS
0168 #include BOOST_ABI_SUFFIX
0169 #endif
0170
0171 #endif