Loading...
Searching...
No Matches
ml::EnumKey Struct Reference

Utility for generating unique, stable string keys from enum values. More...

#include <EnumKey.h>

Static Public Member Functions

template<typename EnumType>
static std::string get (EnumType value)
 Generate a unique string key for an enum value.
template<typename EnumType>
static std::string typeKey ()
 Generate a unique string key for an enum type alone.

Detailed Description

Utility for generating unique, stable string keys from enum values.

EnumKey converts any scoped or unscoped enum value into a std::string key by combining the enum type's mangled name with the enum's integer value. The resulting key is:

  • Guaranteed unique — different enum types produce different typeid().name() strings; different values produce different integers. No collision is possible.
  • General purpose — works for any enum, not just event enums.
  • Human-readable — keys like "N2ml5EventE::0" are debuggable.

Performance note

Keys are std::string — map lookups are slightly slower than size_t but collision-free and correct at any scale. If Malena grows to a scale where string lookup cost matters, switch to a hash-combine approach (e.g. boost::hash_combine) and benchmark.

Usage

std::string key = ml::EnumKey::get(MyManifest::Event::SCORE_CHANGED);
@ CLICK
Mouse button released over component.
Definition Event.h:36
static std::string get(EnumType value)
Generate a unique string key for an enum value.
Definition EnumKey.h:63
Note
Keys are stable within a single program run but are NOT guaranteed stable across runs, platforms, or compiler versions because typeid().name() is implementation-defined. Do not persist or serialize EnumKey values.
See also
EventsManager, Fireable, Unsubscribable

Definition at line 49 of file EnumKey.h.

Member Function Documentation

◆ get()

template<typename EnumType>
std::string ml::EnumKey::get ( EnumType value)
inlinestatic

Generate a unique string key for an enum value.

Combines typeid(EnumType).name() with the integer value of value via "::". Guaranteed unique per (type, value) pair.

Template Parameters
EnumTypeAny enum type (scoped or unscoped). Enforced at compile time via std::is_enum_v.
Parameters
valueThe enum value to convert to a key.
Returns
A unique std::string key for this (type, value) pair.

Definition at line 63 of file EnumKey.h.

◆ typeKey()

template<typename EnumType>
std::string ml::EnumKey::typeKey ( )
inlinestatic

Generate a unique string key for an enum type alone.

Returns a key representing the enum type without a specific value. Useful when grouping all events of a given enum type.

Template Parameters
EnumTypeAny enum type.
Returns
The typeid name for EnumType.

Definition at line 83 of file EnumKey.h.


The documentation for this struct was generated from the following file: