Loading...
Searching...
No Matches
EnumKey.h
Go to the documentation of this file.
1//
2// EnumKey.h
3//
4
5#ifndef ENUMKEY_H
6#define ENUMKEY_H
7
8#pragma once
9
10#include <string>
11#include <typeinfo>
12#include <type_traits>
13
14namespace ml
15{
49 struct EnumKey
50 {
62 template<typename EnumType>
63 static std::string get(EnumType value)
64 {
65 static_assert(std::is_enum_v<EnumType>,
66 "[Malena] EnumKey::get — template parameter must be an enum type.");
67
68 return std::string(typeid(EnumType).name())
69 + "::"
70 + std::to_string(static_cast<int>(value));
71 }
72
82 template<typename EnumType>
83 static std::string typeKey()
84 {
85 static_assert(std::is_enum_v<EnumType>,
86 "[Malena] EnumKey::typeKey — template parameter must be an enum type.");
87
88 return std::string(typeid(EnumType).name());
89 }
90 };
91
92} // namespace ml
93
94#endif // ENUMKEY_H
Definition Component.h:18
Utility for generating unique, stable string keys from enum values.
Definition EnumKey.h:50
static std::string typeKey()
Generate a unique string key for an enum type alone.
Definition EnumKey.h:83
static std::string get(EnumType value)
Generate a unique string key for an enum value.
Definition EnumKey.h:63