Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Boost.Wave: A Standard compliant C++ preprocessor library
|
Chris@16
|
3
|
Chris@16
|
4 http://www.boost.org/
|
Chris@16
|
5
|
Chris@16
|
6 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost
|
Chris@16
|
7 Software License, Version 1.0. (See accompanying file
|
Chris@16
|
8 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 =============================================================================*/
|
Chris@16
|
10
|
Chris@16
|
11 #if !defined(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED)
|
Chris@16
|
12 #define TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED
|
Chris@16
|
13
|
Chris@16
|
14 #include <vector>
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/wave/wave_config.hpp>
|
Chris@16
|
17 #include <boost/wave/token_ids.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 // this must occur after all of the includes and before any code appears
|
Chris@16
|
20 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
21 #include BOOST_ABI_PREFIX
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
25 namespace boost {
|
Chris@16
|
26 namespace wave {
|
Chris@16
|
27 namespace cpplexer {
|
Chris@16
|
28
|
Chris@16
|
29 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
30 //
|
Chris@16
|
31 // The token_cache template is used to cache the tokens corresponding to the
|
Chris@16
|
32 // keywords, operators and other constant language elements.
|
Chris@16
|
33 //
|
Chris@16
|
34 // This avoids repeated construction of these tokens, which is especially
|
Chris@16
|
35 // effective when used in conjunction with a copy on write string
|
Chris@16
|
36 // implementation (COW string).
|
Chris@16
|
37 //
|
Chris@16
|
38 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
39 template <typename StringT>
|
Chris@16
|
40 class token_cache
|
Chris@16
|
41 {
|
Chris@16
|
42 public:
|
Chris@16
|
43 token_cache()
|
Chris@16
|
44 : cache(T_LAST_TOKEN - T_FIRST_TOKEN)
|
Chris@16
|
45 {
|
Chris@16
|
46 typename std::vector<StringT>::iterator it = cache.begin();
|
Chris@16
|
47 for (unsigned int i = T_FIRST_TOKEN; i < T_LAST_TOKEN; ++i, ++it)
|
Chris@16
|
48 {
|
Chris@16
|
49 *it = StringT(boost::wave::get_token_value(token_id(i)));
|
Chris@16
|
50 }
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 StringT const &get_token_value(token_id id) const
|
Chris@16
|
54 {
|
Chris@16
|
55 return cache[BASEID_FROM_TOKEN(id) - T_FIRST_TOKEN];
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 private:
|
Chris@16
|
59 std::vector<StringT> cache;
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
63 } // namespace cpplexer
|
Chris@16
|
64 } // namespace wave
|
Chris@16
|
65 } // namespace boost
|
Chris@16
|
66
|
Chris@16
|
67 // the suffix header occurs after all of the code
|
Chris@16
|
68 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
69 #include BOOST_ABI_SUFFIX
|
Chris@16
|
70 #endif
|
Chris@16
|
71
|
Chris@16
|
72 #endif // !defined(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED)
|