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