template class EE::UI::CSS::IdNameMap¶
Overview¶
Maps dense process-local IDs to canonical names and back. More…
#include <idnamemap.hpp> template <typename Id, std::size_t MaxIds> class IdNameMap { public: // methods bool addBuiltin(Id id, const std::string& canonicalName); bool addAlias(const std::string& alias, Id target, bool couldBeDuplicate = false); bool finalizeBuiltins(); Id getId(std::string_view name) const; Id getId(const std::string& name) const; Id getId(const char* name) const; const std::string& getName(Id id) const; Id getOrCreateId(const std::string& canonicalName); bool contains(Id id) const; bool contains(std::string_view name) const; bool contains(const std::string& name) const; bool contains(const char* name) const; std::size_t size() const; };
Detailed Documentation¶
Maps dense process-local IDs to canonical names and back.
The map is the full-string reverse lookup for a dense ID space. It owns no definitions: it only tracks which ID belongs to which canonical (or alias) name. Built-in IDs must be registered with addBuiltin() before finalizeBuiltins() seals the built-in range; runtime names then receive IDs via getOrCreateId().
Numeric IDs are unstable internal identifiers. Names are the stable external representation. All names passed into the map are expected to already be lowercase and trimmed; the map performs no hidden normalization and no hash-only equality.
Methods¶
bool addBuiltin(Id id, const std::string& canonicalName)
Registers a built-in ID with its canonical name.
Valid only before custom allocation begins. Rejects Invalid, IDs at or beyond MaxIds, duplicate names, and assigning a different name to an occupied ID.
Returns:
true on success.
bool addAlias(const std::string& alias, Id target, bool couldBeDuplicate = false)
Adds an alias that resolves to an existing ID.
Only the reverse entry is added; no ID is occupied and the canonical name is never replaced.
bool finalizeBuiltins()
Seals the built-in range and enables runtime ID allocation.
Verifies every slot in [1, FirstCustomId) is populated. After this call addBuiltin() is permanently rejected.
Returns:
true when all built-in slots are populated.
Id getId(std::string_view name) const
Returns the ID for a canonical or alias name.
Returns:
Invalid when the name is unknown.
const std::string& getName(Id id) const
Returns the canonical name for an ID.
Returns:
The empty invalid name for invalid, out-of-range, or unassigned IDs.
Id getOrCreateId(const std::string& canonicalName)
Returns the existing ID for a canonical name, or allocates a new custom ID.
Only valid after finalizeBuiltins(). Reaching the capacity returns Invalid and logs a clear error containing the rejected name.