3#ifndef vtkStringManager_h
4#define vtkStringManager_h
22#include <unordered_map>
23#include <unordered_set>
25VTK_ABI_NAMESPACE_BEGIN
42 using Hash = std::uint32_t;
47 static constexpr Hash Invalid = 0;
95 bool Empty()
const {
return this->Data.empty(); }
124 using LockGuard = std::lock_guard<std::mutex>;
126 std::pair<Hash, bool> ComputeInternal(
const std::string& s,
const LockGuard& proofOfLock)
const;
127 std::pair<Hash, bool> ComputeInternalAndInsert(
128 const std::string& s,
const LockGuard& proofOfLock);
129 std::size_t UnmanageInternal(
Hash hh,
const LockGuard& proofOfLock);
131 std::unordered_map<Hash, std::string> Data;
132 std::unordered_map<Hash, std::unordered_set<Hash>> Sets;
133 mutable std::mutex WriteLock;
a simple class to control print indentation
abstract base class for most VTK objects
Manage string-token mappings.
const std::string & Value(Hash hh) const
Look up a string from its hashed value, hh.
bool Contains(const std::string &ss, Hash hh) const
Return true if the set ss exists and contains hash hh ; and false otherwise.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool Contains(Hash ss, Hash hh) const
bool Empty() const
Return true if the manager is empty (i.e., managing no hashes) and false otherwise.
Visit
An enumerant visitors return to terminate early (or not).
@ Halt
Terminate visitation.
std::size_t Unmanage(Hash hh)
Remove a hash from the manager.
Hash Find(const std::string &s) const
Look up a hash from a string value (without inserting it).
Hash Manage(const std::string &ss)
Insert a string into the manager by computing a unique hash (the returned value).
Hash Compute(const std::string &ss) const
Compute a hash from a string value (without inserting it into the manager).
Hash Insert(const std::string &ss, Hash hh)
Add the hash hh to the set ss.
bool Remove(Hash ss, Hash hh)
static vtkStringManager * New()
bool Contains(Hash hh) const
vtkStringManager()=default
Visit VisitSets(Visitor visitor) const
Visit all set names in the manager.
bool Insert(Hash ss, Hash hh)
Visit VisitMembers(Visitor visitor, Hash set=Invalid) const
Visit all members of the set (or the entire Manager if passed the Invalid hash).
std::uint32_t Hash
The type of integer used to hash strings.
bool Remove(const std::string &ss, Hash hh)
Remove the hash h from the set s.
std::function< Visit(Hash entry)> Visitor
Signature for functions visiting strings in the manager or in a set held by the manager.
void Reset()
Reset the manager to an empty state, clearing both members and sets.