FSMgine
High-performance finite state machine library for C++17 with single-threaded and multi-threaded variants
Loading...
Searching...
No Matches
StringInterner.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <string>
8#include <string_view>
9#include <unordered_set>
10
11#ifdef FSMGINE_MULTI_THREADED
12#include <mutex>
13#endif
14
17
18namespace fsmgine {
19
40public:
44
49 std::string_view intern(const std::string& str);
50
55 std::string_view intern(std::string_view sv);
56
62 void clear();
63
64private:
65 StringInterner() = default;
66 ~StringInterner() = default;
67 StringInterner(const StringInterner&) = delete;
68 StringInterner& operator=(const StringInterner&) = delete;
69
70 std::unordered_set<std::string> interned_strings_;
71
72#ifdef FSMGINE_MULTI_THREADED
73 mutable std::mutex mutex_;
74#endif
75};
76
77} // namespace fsmgine
Provides memory-efficient string storage through string interning.
Definition StringInterner.hpp:39
void clear()
Clears all interned strings (TEST ONLY - DO NOT USE IN PRODUCTION)
std::string_view intern(std::string_view sv)
Interns a string_view and returns a persistent string_view.
static StringInterner & instance()
Gets the singleton instance of StringInterner.
std::string_view intern(const std::string &str)
Interns a string and returns a persistent string_view.
Main namespace for the FSMgine library.
Definition FSM.hpp:23