BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
StringRegistry.cpp
Go to the documentation of this file.
1#include "StringRegistry.h"
2#include "Keywords.h"
3#include <cassert>
4
5using namespace BPMNOS;
6
8 // register false with index 0 and true with index 1
9 (*this)(Keyword::False);
10 (*this)(Keyword::True);
11}
12
13std::string StringRegistry::operator[](size_t i) const {
14 assert( i < registeredStrings.size() );
15 return registeredStrings[i];
16}
17
18size_t StringRegistry::operator()(const std::string& string) {
19 std::lock_guard<std::mutex> lock(registryMutex);
20
21 auto it = index.find(string);
22 if ( it == index.end() ) {
23 registeredStrings.push_back(string);
24 index[string] = index.size();
25 return registeredStrings.size()-1;
26 }
27 return it->second;
28}
29
31 registeredStrings.clear();
32 index.clear();
33 (*this)(Keyword::False);
34 (*this)(Keyword::True);
35}
36
37// Create global registry
StringRegistry stringRegistry
const std::string False
Definition Keywords.h:8
const std::string True
Definition Keywords.h:9
Utility class for representing strings by numeric values.
StringRegistry()
Constructor adds "false" and "true" at indices 0 and 1.
size_t operator()(const std::string &string)
Operator to register a string and return its index.
std::string operator[](size_t i) const
Operator providing access to a registered string by index.