nany
stringrefs.h
1 #pragma once
2 #include <yuni/yuni.h>
3 #include <yuni/core/dictionary.h>
4 #include <yuni/string.h>
5 #include <deque>
6 
7 
8 namespace ny {
9 
10 
12 struct StringRefs final {
13  StringRefs();
14  StringRefs(StringRefs&&) = default;
15  StringRefs(const StringRefs&);
16 
18  AnyString refstr(const AnyString& text);
19 
21  uint32_t ref(const AnyString& text);
22 
24  bool exists(const AnyString& text) const;
25 
27  void clear();
28 
30  AnyString operator [] (uint32_t ix) const;
31 
32  StringRefs& operator = (const StringRefs&);
33  StringRefs& operator = (StringRefs&&) = default;
34 
35 private:
36  uint32_t keepString(const AnyString& text);
37 
39  std::deque<yuni::String> m_storage;
41  std::unordered_map<AnyString, uint32_t> m_index;
42 
43 }; // struct StringRefs
44 
45 
46 } // namespace ny
47 
48 #include "stringrefs.hxx"
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
void clear()
Clear the container.
Definition: stringrefs.cpp:40
bool exists(const AnyString &text) const
Get if a given string is already indexed.
Definition: stringrefs.hxx:8
Container for minimizing memory use of duplicate strings.
Definition: stringrefs.h:12