1
2
3
4
5
6 #ifndef CMAJOR_RT_STRING_INCLUDED
7 #define CMAJOR_RT_STRING_INCLUDED
8 #include <soulng/util/Error.hpp>
9 #include <memory>
10 #include <unordered_map>
11 #include <string>
12 #include <stdint.h>
13
14 namespace cmajor { namespace rt {
15
16 class StringTable
17 {
18 public:
19 static void Init();
20 static void Done();
21 static StringTable& Instance() { Assert(instance, "string table not initialized"); return *instance; }
22 int32_t InstallString(const std::string& str);
23 const char* GetString(int32_t stringHandle);
24 void DisposeString(int32_t stringHandle);
25 private:
26 static std::unique_ptr<StringTable> instance;
27 StringTable();
28 int32_t nextStringHandle;
29 std::unordered_map<int32_t, std::string> stringMap;
30 };
31
32 int32_t InstallString(const std::string& str);
33 const char* GetString(int32_t stringHandle);
34 void DisposeString(int32_t stringHandle);
35
36 void InitString();
37 void DoneString();
38
39 } }
40
41 #endif // CMAJOR_RT_STRING_INCLUDED