SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
10 #ifndef smtk_string_Manager_h
11 #define smtk_string_Manager_h
13 #include "smtk/CoreExports.h"
14 #include "smtk/SystemConfig.h"
15 #include "smtk/common/Observers.h"
18 #include "nlohmann/json.hpp"
24 #include <unordered_map>
25 #include <unordered_set>
40 class SMTKCORE_EXPORT
Manager :
public std::enable_shared_from_this<Manager>
43 static std::shared_ptr<Manager> create();
66 static constexpr
Hash Invalid = 0;
69 Hash manage(
const std::string& s);
71 std::size_t unmanage(
Hash h);
74 const std::string& value(
Hash h)
const;
77 Hash find(
const std::string& s)
const;
85 Hash compute(
const std::string& s)
const;
95 Hash insert(
const std::string& set,
Hash h);
100 bool remove(
const std::string& set,
Hash h);
108 bool contains(
const std::string& set,
Hash h)
const;
109 bool contains(
Hash set,
Hash h)
const;
110 bool contains(
Hash h)
const {
return this->contains(Invalid, h); }
128 bool verify(
Hash& verified,
Hash input)
const;
131 bool empty()
const {
return m_data.empty(); }
147 const std::unordered_map<Hash, std::string>& members,
148 const std::unordered_map<
Hash, std::unordered_set<Hash>>& sets);
155 friend class DeserializationContext;
157 friend void SMTKCORE_EXPORT from_json(
const nlohmann::json&, std::shared_ptr<Manager>&);
160 std::pair<Hash, bool> computeInternal(
const std::string& s)
const;
161 std::pair<Hash, bool> computeInternalAndInsert(
const std::string& s);
164 std::unordered_map<Hash, std::string> m_data;
165 std::unordered_map<Hash, std::unordered_set<Hash>> m_sets;
166 mutable std::mutex m_writeLock;
181 std::atomic<int> m_translationDepth{ 0 };
194 #endif // smtk_string_Manager_h
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
bool empty() const
Return true if the manager is empty (i.e., managing no hashes) and false otherwise.
Definition: Manager.h:131
@ Removed
A string was removed from a set.
Definition: Manager.h:50
std::ostream & operator<<(std::ostream &os, const Manager::Event &e)
Events may be appended to streams.
Definition: Manager.cxx:411
std::unordered_map< Hash, Hash > m_translation
A translation map for deserialization.
Definition: Manager.h:179
std::function< smtk::common::Visit(Hash entry)> Visitor
Signature for functions visiting strings in the manager or in a set held by the manager.
Definition: Manager.h:54
@ Managed
A string was added to the manager.
Definition: Manager.h:48
Event
Events that can occur during the lifecycle of the manager.
Definition: Manager.h:46
@ Inserted
A string was inserted into a set.
Definition: Manager.h:49
std::size_t Hash
A fixed-size integer type used to represent an arbitrary-length string.
Definition: Manager.h:34
Visit
Return values common to most visitor methods.
Definition: Visit.h:23
Observers & observers()
Return the set of string-manager observers (so you can insert/remove an observer).
Definition: Manager.h:143
std::function< void(Event, Hash, const std::string &, Hash)> Observer
The signature used by observers to receive notifications from the string manager.
Definition: Manager.h:62
std::string eventName(const Manager::Event &e)
A type-conversion operation to cast enumerants to strings.
Definition: Manager.cxx:379
The string manager class is a dictionary mapping integers to (constant) string values.
Definition: Manager.h:40
Manager::Event eventEnum(const std::string &e)
A type-conversion operation to cast strings to event types.
Definition: Manager.cxx:385