BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
StringRegistry.h
Go to the documentation of this file.
1#ifndef BPMNOS_Model_StringRegistry_H
2#define BPMNOS_Model_StringRegistry_H
3
4#include <string>
5#include <vector>
6#include <unordered_map>
7#include <mutex>
8
9namespace BPMNOS {
10
11 /**
12 * @brief Utility class for representing strings by numeric values.
13 *
14 * The StringRegistry class provides efficient access to the string by index
15 * and retrieval of the index by string.
16 */
18 /// Constructor adds "false" and "true" at indices 0 and 1.
20
21 /// Operator providing access to a registered string by index.
22 std::string operator[](size_t i) const;
23 /// Operator to register a string and return its index.
24 size_t operator()(const std::string& string);
25 void clear();
26 private:
27 std::vector<std::string> registeredStrings;
28 std::unordered_map<std::string, size_t> index;
29 std::mutex registryMutex;
30 public:
31 // Prevent use of copy constructor and assignment operator as mutex is not copyable
32 StringRegistry(const StringRegistry &) = delete;
34 };
35
36
37} // namespace BPMNOS
38
39#endif // BPMNOS_Model_StringRegistry_H
40
41// `stringRegistry` is a global variable
BPMNOS::StringRegistry stringRegistry
Utility class for representing strings by numeric values.
StringRegistry(const StringRegistry &)=delete
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.
StringRegistry & operator=(const StringRegistry &)=delete