top | up | prev | next

StringTable Class

Definition at line 16 of String.hpp

Constructors

StringTable()

Member Functions

void DisposeString(int32_t stringHandle)
void Done() static
const char* GetString(int32_t stringHandle)
void Init() static
int32_t InstallString(const std::string& str)
StringTable& Instance() static

Member Variables

std::unique_ptr<StringTable> instance static
int32_t nextStringHandle
std::unordered_map<int32_t, std::string> stringMap

Constructor Details

StringTable Constructor

cmajor::rt::StringTable::StringTable()

Definition at line 23 of String.cpp :
23 : nextStringHandle(1)
24 {
25 }


Declaration at line 27 of String.hpp


Member Function Details

DisposeString Member Function

void cmajor::rt::StringTable::DisposeString(int32_t stringHandle)

Definition at line 48 of String.cpp :
49 {
50     std::lock_guard<std::mutex> lock(mtx);
51     stringMap.erase(stringHandle);
52 }


Declaration at line 24 of String.hpp


Done Member Function

void cmajor::rt::StringTable::Done() static

Definition at line 18 of String.cpp :
19 {
20     instance.reset();
21 }


Declaration at line 20 of String.hpp


GetString Member Function

const char * cmajor::rt::StringTable::GetString(int32_t stringHandle)

Definition at line 37 of String.cpp :
38 {
39     std::lock_guard<std::mutex> lock(mtx);
40     auto it = stringMap.find(stringHandle);
41     if (it != stringMap.cend())
42     {
43         return it->second.c_str();
44     }
45     return "";
46 }


Declaration at line 23 of String.hpp


Init Member Function

void cmajor::rt::StringTable::Init() static

Definition at line 13 of String.cpp :
14 {
15     instance.reset(new StringTable());
16 }


Declaration at line 19 of String.hpp


InstallString Member Function

int32_t cmajor::rt::StringTable::InstallString(const std::string& str)

Definition at line 29 of String.cpp :
30 {
31     std::lock_guard<std::mutex> lock(mtx);
32     int32_t stringHandle = nextStringHandle++;
33     stringMap[stringHandle] = str;
34     return stringHandle;
35 }


Declaration at line 22 of String.hpp


Instance Member Function

StringTable & cmajor::rt::StringTable::Instance() static

Definition at line 21 of String.hpp :
21 { Assert(instance"string table not initialized");  return *instance; }


top | up | prev | next