Chris@16: /*============================================================================= Chris@16: Boost.Wave: A Standard compliant C++ preprocessor library Chris@16: Chris@16: http://www.boost.org/ Chris@16: Chris@16: Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost Chris@16: Software License, Version 1.0. (See accompanying file Chris@16: LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: =============================================================================*/ Chris@16: Chris@16: #if !defined(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED) Chris@16: #define TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: // this must occur after all of the includes and before any code appears Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: namespace boost { Chris@16: namespace wave { Chris@16: namespace cpplexer { Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // The token_cache template is used to cache the tokens corresponding to the Chris@16: // keywords, operators and other constant language elements. Chris@16: // Chris@16: // This avoids repeated construction of these tokens, which is especially Chris@16: // effective when used in conjunction with a copy on write string Chris@16: // implementation (COW string). Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: class token_cache Chris@16: { Chris@16: public: Chris@16: token_cache() Chris@16: : cache(T_LAST_TOKEN - T_FIRST_TOKEN) Chris@16: { Chris@16: typename std::vector::iterator it = cache.begin(); Chris@16: for (unsigned int i = T_FIRST_TOKEN; i < T_LAST_TOKEN; ++i, ++it) Chris@16: { Chris@16: *it = StringT(boost::wave::get_token_value(token_id(i))); Chris@16: } Chris@16: } Chris@16: Chris@16: StringT const &get_token_value(token_id id) const Chris@16: { Chris@16: return cache[BASEID_FROM_TOKEN(id) - T_FIRST_TOKEN]; Chris@16: } Chris@16: Chris@16: private: Chris@16: std::vector cache; Chris@16: }; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: } // namespace cpplexer Chris@16: } // namespace wave Chris@16: } // namespace boost Chris@16: Chris@16: // the suffix header occurs after all of the code Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: #include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // !defined(TOKEN_CACHE_HPP_4D2320B7_1D56_4113_A114_397E70FA438C_INCLUDED)