nany
stringrefs.hxx
1 #pragma once
2 #include "stringrefs.h"
3 
4 
5 namespace ny {
6 
7 
8 inline bool StringRefs::exists(const AnyString& text) const {
9  return m_index.count(text) != 0;
10 }
11 
12 
13 inline uint32_t StringRefs::ref(const AnyString& text) {
14  auto it = m_index.find(text);
15  return it != m_index.end() ? it->second : keepString(text);
16 }
17 
18 
19 inline AnyString StringRefs::refstr(const AnyString& text) {
20  return (*this)[ref(text)];
21 }
22 
23 
24 inline AnyString StringRefs::operator [] (uint32_t ix) const {
25  assert(ix < m_storage.size());
26  return m_storage[ix];
27 }
28 
29 
30 } // namespace ny
uint32_t ref(const AnyString &text)
Get the unique id of a string.
Definition: stringrefs.hxx:13
Definition: ast.cpp:6
AnyString operator[](uint32_t ix) const
Retrieve a stored string from its index.
Definition: stringrefs.hxx:24
AnyString refstr(const AnyString &text)
Add a new entry within the catalog.
Definition: stringrefs.hxx:19
bool exists(const AnyString &text) const
Get if a given string is already indexed.
Definition: stringrefs.hxx:8