17 #include <initializer_list>
29 template <
class EnumClass,
31 const LookupTableType *
table = NULL;
42 for (i = 0; tab [i].name; i++) ;
46 LookupTable (
const std::initializer_list<LookupTableType> tab) :
48 LookupTableType *iniz =
new LookupTableType [tab.size() + 1];
50 for (
auto item : tab) {
52 iniz [i].name = item.name;
53 iniz [i++].value = item.value;
69 virtual const LookupTableType *
get (
const char *s)
const noexcept {
70 for (
const LookupTableType *l =
table; l->name != NULL; l++) {
83 const LookupTableType *item =
get (s);
94 inline const EnumClass
operator[] (
const std::string &s)
const {
95 return (*
this) [s.c_str()];
103 const LookupTableType *item =
get (s);
104 if (!item)
return false;
105 *
value = item->value;
115 const LookupTableType *
get (
const EnumClass
id)
const {
116 for (
const LookupTableType *l =
table; l->name != NULL; l++) {
117 if (
id == l->value) {
128 const LookupTableType *item =
get (
id);
129 if (!item)
return nullptr;
133 const LookupTableType *
begin ()
const {
137 const LookupTableType *
end ()
const {
Exception for command execution problems.
Definition: fundamentals.h:293
Class to map between enumerations and their text values.
Definition: lookup.h:30
const LookupTableType * table
Definition: lookup.h:31
LookupTable(const LookupTableType *tab)
Initialize the lookup table from an array.
Definition: lookup.h:39
const bool tryGetValue(const char *s, EnumClass *value) const
Retrieve the enumerator corresponding to a text value.
Definition: lookup.h:102
bool release
Definition: lookup.h:33
LookupTable(const LookupTable< EnumClass, LookupTableType > &)=delete
const LookupTableType * end() const
Definition: lookup.h:137
const LookupTableType * get(const EnumClass id) const
Retrieve a table entry by the enumerator of an entry.
Definition: lookup.h:115
const int table_size
Definition: lookup.h:32
~LookupTable()
Definition: lookup.h:59
const EnumClass operator[](const char *s) const
Retrieve the enumerator corresponding to text name.
Definition: lookup.h:82
virtual const LookupTableType * get(const char *s) const noexcept
Retrieve a table entry by the text name of an entry.
Definition: lookup.h:69
LookupTable(const LookupTable< EnumClass, LookupTableType > &&)=delete
const LookupTableType * begin() const
Definition: lookup.h:133
const bool tryGetValue(const std::string &s, EnumClass *value) const
Definition: lookup.h:108
LookupTable(const std::initializer_list< LookupTableType > tab)
Initialize the lookup table from an initializer list.
Definition: lookup.h:46
A standard form of enumeration to text value lookup tables.
Definition: lookup.h:22
const char * name
Definition: lookup.h:24
EnumClass value
Definition: lookup.h:25
Essential data structures and support.
@ E_INVALID
Definition: fundamentals.h:192
uint32_t value
Definition: audiooutput.cpp:68
int strcasecmp(const std::string &a, const char *b)
Definition: utility.h:48