Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/wave/util/iteration_context.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.7 KB
Line 
1/*=============================================================================
2    Boost.Wave: A Standard compliant C++ preprocessor library
3
4    http://www.boost.org/
5
6    Copyright (c) 2001-2007 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// this must occur after all of the includes and before any code appears
22#ifdef BOOST_HAS_ABI_HEADERS
23#include BOOST_ABI_PREFIX
24#endif
25
26///////////////////////////////////////////////////////////////////////////////
27namespace boost {
28namespace wave {
29namespace util {
30
31///////////////////////////////////////////////////////////////////////////////
32template <typename IterationContextT>
33class iteration_context_stack 
34{
35    typedef std::stack<IterationContextT> base_type;
36   
37public:
38    typedef typename base_type::size_type size_type;
39   
40    iteration_context_stack()
41    :   max_include_nesting_depth(BOOST_WAVE_MAX_INCLUDE_LEVEL_DEPTH)
42    {}
43   
44    void set_max_include_nesting_depth(size_type new_depth)
45        {  max_include_nesting_depth = new_depth; }
46    size_type get_max_include_nesting_depth() const
47        { return max_include_nesting_depth; }
48
49    typename base_type::size_type size() const { return iter_ctx.size(); }
50    typename base_type::value_type &top() { return iter_ctx.top(); }
51    void pop() { iter_ctx.pop(); }
52   
53    template <typename PositionT>
54    void push(PositionT const &pos, typename base_type::value_type const &val)
55    { 
56        if (iter_ctx.size() == max_include_nesting_depth) {
57        char buffer[22];    // 21 bytes holds all NUL-terminated unsigned 64-bit numbers
58
59            using namespace std;    // for some systems ltoa is in namespace std
60            sprintf(buffer, "%d", (int)max_include_nesting_depth);
61            BOOST_WAVE_THROW(preprocess_exception, include_nesting_too_deep, 
62                buffer, pos);
63        }
64        iter_ctx.push(val); 
65    }
66       
67private:
68    size_type max_include_nesting_depth;
69    base_type iter_ctx;
70};
71
72///////////////////////////////////////////////////////////////////////////////
73}   // namespace util
74}   // namespace wave
75}   // namespace boost
76
77// the suffix header occurs after all of the code
78#ifdef BOOST_HAS_ABI_HEADERS
79#include BOOST_ABI_SUFFIX
80#endif
81
82#endif // !defined(ITERATION_CONTEXT_HPP_9556CD16_F11E_4ADC_AC8B_FB9A174BE664_INCLUDED)
Note: See TracBrowser for help on using the repository browser.