123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // this must occur after all of the includes and before any code appears
- ///////////////////////////////////////////////////////////////////////////////
- namespace boost {
- namespace wave {
- namespace cpplexer {
- ///////////////////////////////////////////////////////////////////////////////
- //
- // The token_cache template is used to cache the tokens corresponding to the
- // keywords, operators and other constant language elements.
- //
- // This avoids repeated construction of these tokens, which is especially
- // effective when used in conjunction with a copy on write string
- // implementation (COW string).
- //
- ///////////////////////////////////////////////////////////////////////////////
- template <typename StringT>
- class token_cache
- {
- public:
- token_cache()
- : cache(T_LAST_TOKEN - T_FIRST_TOKEN)
- {
- typename std::vector<StringT>::iterator it = cache.begin();
- for (unsigned int i = T_FIRST_TOKEN; i < T_LAST_TOKEN; ++i, ++it)
- {
- *it = StringT(boost::wave::get_token_value(token_id(i)));
- }
- }
- StringT const &get_token_value(token_id id) const
- {
- return cache[BASEID_FROM_TOKEN(id) - T_FIRST_TOKEN];
- }
- private:
- std::vector<StringT> cache;
- };
- ///////////////////////////////////////////////////////////////////////////////
- } // namespace cpplexer
- } // namespace wave
- } // namespace boost
- // the suffix header occurs after all of the code
|