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#include <shared_mutex>
9
10namespace BPMNOS {
11
12 /**
13 * @brief Utility class for representing strings by numeric values.
14 *
15 * The StringRegistry class provides efficient access to the string by index
16 * and retrieval of the index by string.
17 */
19 /// Constructor adds "false" and "true" at indices 0 and 1.
21
22 /// Operator providing access to a registered string by index.
23 std::string operator[](size_t i) const;
24 /// Operator to register a string and return its index.
25 size_t operator()(const std::string& string);
26 size_t size() const;
27 void clear();
28 private:
29 std::vector<std::string> registeredStrings;
30 std::unordered_map<std::string, size_t> index;
31 mutable std::shared_mutex registryMutex;
32 public:
33 // Prevent use of copy constructor and assignment operator as mutex is not copyable
34 StringRegistry(const StringRegistry &) = delete;
36 };
37
38
39} // namespace BPMNOS
40
41#endif // BPMNOS_Model_StringRegistry_H
42
43// `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