source: NonGTP/Boost/boost/wave/util/iteration_context.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Boost.Wave: A Standard compliant C++ preprocessor library
3
4    http://www.boost.org/
5
6    Copyright (c) 2001-2005 Hartmut Kaiser. Distributed under the Boost
7    Software License, Version 1.0. (See accompanying file
8    LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9=============================================================================*/
10
11#if !defined(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
12#define ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED
13
14#include <cstdlib>
15#include <cstdio>
16#include <stack>
17
18#include <boost/wave/wave_config.hpp>
19#include <boost/wave/cpp_exceptions.hpp>
20
21///////////////////////////////////////////////////////////////////////////////
22namespace boost {
23namespace wave {
24namespace util {
25
26///////////////////////////////////////////////////////////////////////////////
27template <typename IterationContextT>
28class iteration_context_stack
29{
30    typedef std::stack<IterationContextT> base_type;
31   
32public:
33    typedef typename base_type::size_type size_type;
34   
35    iteration_context_stack()
36    :   max_include_nesting_depth(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
37    {}
38   
39    void set_max_include_nesting_depth(size_type new_depth)
40        {  max_include_nesting_depth = new_depth; }
41    size_type get_max_include_nesting_depth() const
42        { return max_include_nesting_depth; }
43
44    typename base_type::size_type size() const { return iter_ctx.size(); }
45    typename base_type::value_type &top() { return iter_ctx.top(); }
46    void pop() { iter_ctx.pop(); }
47   
48    template <typename PositionT>
49    void push(PositionT const &pos, typename base_type::value_type const &val)
50    {
51        if (iter_ctx.size() == max_include_nesting_depth) {
52        char buffer[22];    // 21 bytes holds all NUL-terminated unsigned 64-bit numbers
53
54            using namespace std;    // for some systems ltoa is in namespace std
55            sprintf(buffer, "%d", (int)max_include_nesting_depth);
56            BOOST_WAVE_THROW(preprocess_exception, include_nesting_too_deep,
57                buffer, pos);
58        }
59        iter_ctx.push(val);
60    }
61       
62private:
63    size_type max_include_nesting_depth;
64    base_type iter_ctx;
65};
66
67///////////////////////////////////////////////////////////////////////////////
68}   // namespace util
69}   // namespace wave
70}   // namespace boost
71
72#endif // !defined(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
Note: See TracBrowser for help on using the repository browser.