8#include <Common/assertion.h>
24template<
typename InEnumType, std::
size_t MAX_ENTRIES = 64>
32 static_assert(std::is_enum_v<EnumType>,
33 "EnumType must be a C++ enum. Currently it is not.");
46 using EntryValueType =
decltype(std::declval<Entry>().value);
49 return {entry.
name,
static_cast<EntryValueType
>(entry.
value)};
54 return m_entries.size();
59 const std::string_view valueName,
62 PH_ASSERT_MSG(!m_entries.isFull(),
63 "No space for more entries; increase MAX_ENTRIES parameter for this enum.");
66 entry.nameIndex = m_nameBuffer.size();
67 entry.nameSize = valueName.size();
68 entry.value = enumValue;
70 m_nameBuffer.append(valueName);
71 PH_ASSERT_EQ(entry.nameIndex + entry.nameSize, m_nameBuffer.size());
73 const std::size_t entryIndex = m_entries.size();
74 m_entries.pushBack(entry);
82 const BasicEnumEntry& basicEntry = m_entries[entryIndex];
84 const std::string_view entryName(
85 m_nameBuffer.data() + basicEntry.nameIndex,
88 return {entryName, basicEntry.value};
99 for(std::size_t entryIdx = 0; entryIdx < m_entries.size(); ++entryIdx)
102 if(entry.
name == entryName)
108 throw SdlLoadError(
"use of invalid enum entry name <" + std::string(entryName) +
">");
119 for(std::size_t entryIdx = 0; entryIdx < m_entries.size(); ++entryIdx)
122 if(entry.
value == enumValue)
138 struct BasicEnumEntry
140 std::size_t nameIndex;
141 std::size_t nameSize;
144 inline BasicEnumEntry() :
145 nameIndex(0), nameSize(0), value(static_cast<
EnumType>(0))
149 std::string m_nameBuffer;
150 TArrayVector<BasicEnumEntry, MAX_ENTRIES> m_entries;
Describes enum in SDL.
Definition SdlEnum.h:22
SdlEnum & setDescription(std::string description)
Definition SdlEnum.h:68
SdlEnum & setEntryDescription(std::size_t entryIndex, std::string description)
Definition SdlEnum.h:75
Error on the SDL input process.
Definition sdl_exceptions.h:22
SDL enum implementation with common features. Enum value and string mapping are done in a brute-force...
Definition TSdlGeneralEnum.h:26
TSdlGeneralEnum & description(std::string descriptionStr)
Definition TSdlGeneralEnum.h:131
TSdlGeneralEnum(std::string name)
Definition TSdlGeneralEnum.h:36
TEntry< EnumType > getTypedEntry(const std::size_t entryIndex) const
Definition TSdlGeneralEnum.h:80
InEnumType EnumType
Definition TSdlGeneralEnum.h:30
TSdlGeneralEnum & addEntry(const EnumType enumValue, const std::string_view valueName, std::string description="")
Definition TSdlGeneralEnum.h:57
Entry getEntry(const std::size_t entryIndex) const override
Definition TSdlGeneralEnum.h:44
std::size_t numEntries() const override
Definition TSdlGeneralEnum.h:52
TEntry< EnumType > getTypedEntry(const EnumType enumValue) const
Get an enum entry via an enum value. Note that the method cannot distinguish between identical enum v...
Definition TSdlGeneralEnum.h:116
TEntry< EnumType > getTypedEntry(const std::string_view entryName) const
Get an enum entry via an enum name. Note that the method cannot distinguish between identical enum na...
Definition TSdlGeneralEnum.h:96
The root for all renderer implementations.
Definition EEngineProject.h:6
std::string enum_to_string(const EnumType enumValue)
Definition utility.h:173
ValueType value
Definition SdlEnum.h:28
std::string_view name
Definition SdlEnum.h:27