iteration_context.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
  9. #define ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED
  10. #include <cstdlib>
  11. #include <cstdio>
  12. #include <stack>
  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. char buffer[22]; // 21 bytes holds all NUL-terminated unsigned 64-bit numbers
  46. using namespace std; // for some systems sprintf is in namespace std
  47. sprintf(buffer, "%d", (int)max_include_nesting_depth);
  48. BOOST_WAVE_THROW_CTX(ctx, preprocess_exception,
  49. include_nesting_too_deep, buffer, pos);
  50. }
  51. iter_ctx.push(val);
  52. }
  53. private:
  54. size_type max_include_nesting_depth;
  55. base_type iter_ctx;
  56. };
  57. ///////////////////////////////////////////////////////////////////////////////
  58. } // namespace util
  59. } // namespace wave
  60. } // namespace boost
  61. // the suffix header occurs after all of the code
  62. #ifdef BOOST_HAS_ABI_HEADERS
  63. #include BOOST_ABI_SUFFIX
  64. #endif
  65. #endif // !defined(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)