iteration_context.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*=============================================================================
  2. Boost.Wave: A Standard compliant C++ preprocessor library
  3. http://www.boost.org/
  4. Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
  5. Software License, Version 1.0. (See accompanying file
  6. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
  9. #define BOOST_ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED
  10. #include <cstdlib>
  11. #include <stack>
  12. #include <string>
  13. #include <boost/wave/wave_config.hpp>
  14. #include <boost/wave/cpp_exceptions.hpp>
  15. // this must occur after all of the includes and before any code appears
  16. #ifdef BOOST_HAS_ABI_HEADERS
  17. #include BOOST_ABI_PREFIX
  18. #endif
  19. ///////////////////////////////////////////////////////////////////////////////
  20. namespace boost {
  21. namespace wave {
  22. namespace util {
  23. ///////////////////////////////////////////////////////////////////////////////
  24. template <typename IterationContextT>
  25. class iteration_context_stack
  26. {
  27. typedef std::stack<IterationContextT> base_type;
  28. public:
  29. typedef typename base_type::size_type size_type;
  30. iteration_context_stack()
  31. : max_include_nesting_depth(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
  32. {}
  33. void set_max_include_nesting_depth(size_type new_depth)
  34. { max_include_nesting_depth = new_depth; }
  35. size_type get_max_include_nesting_depth() const
  36. { return max_include_nesting_depth; }
  37. typename base_type::size_type size() const { return iter_ctx.size(); }
  38. typename base_type::value_type &top() { return iter_ctx.top(); }
  39. void pop() { iter_ctx.pop(); }
  40. template <typename Context, typename PositionT>
  41. void push(Context& ctx, PositionT const &pos,
  42. typename base_type::value_type const &val)
  43. {
  44. if (iter_ctx.size() == max_include_nesting_depth) {
  45. std::string buffer = std::to_string(max_include_nesting_depth);
  46. BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
  47. include_nesting_too_deep, buffer.c_str(), pos);
  48. }
  49. iter_ctx.push(val);
  50. }
  51. private:
  52. size_type max_include_nesting_depth;
  53. base_type iter_ctx;
  54. };
  55. ///////////////////////////////////////////////////////////////////////////////
  56. } // namespace util
  57. } // namespace wave
  58. } // namespace boost
  59. // the suffix header occurs after all of the code
  60. #ifdef BOOST_HAS_ABI_HEADERS
  61. #include BOOST_ABI_SUFFIX
  62. #endif
  63. #endif // !defined(BOOST_ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)