8#include "Arp/System/Core/EnumDictionaryBase.hxx"
9#include "Arp/System/Core/TypeName.hxx"
25 using U =
typename Base::U;
26 using InitializerList =
typename Base::InitializerList;
35 EnumDictionary(
const char* invalidValueString,
const InitializerList& fields);
87 :
Base(invalidValueString, fields)
94 const char* pString =
nullptr;
95 if (this->TryGetEnumString(value, pString))
101 if (this->invalidValueString.IsEmpty())
103 os << static_cast<U>(value);
107 os << this->invalidValueString;
109 os.setstate(std::ios::failbit);
121 is.setstate(std::ios::failbit);
129 const char* pResult =
nullptr;
130 if(!this->TryGetEnumString(value, pResult))
132 throw Exception(
"Could not find enum string of enum '{}' for value '{}'.",
TypeName<T>().Value,
static_cast<U
>(value));
140 return this->TryGetEnumStringInternal(value, pResult);
149 throw Exception(
"Could not find enum value of enum '{}' for string '{}'.",
TypeName<T>().Value, fieldName);
157 return this->TryGetEnumValueInternal(fieldName, value);
The class implements an adapter for enums to define the string literals of the enum entries.
Definition: EnumDictionaryBase.hxx:21
The class implements an adapter for enums to define the string literals of the enum entries.
Definition: EnumDictionary.hxx:22
std::ostream & WriteEnumString(std::ostream &os, T value) const
Writes the string of the specified enum value to the given stream.
Definition: EnumDictionary.hxx:92
bool TryGetEnumString(T value, const char *&pResult) const
Returns the string of the specified enum value or nullptr if the value could not be found.
Definition: EnumDictionary.hxx:138
T GetEnumValue(const char *fieldName) const
Returns the value of the specified enum string.
Definition: EnumDictionary.hxx:144
std::istream & ReadEnumValue(std::istream &is, T &value) const
Tries to return the enum entry of the specified string.
Definition: EnumDictionary.hxx:115
bool TryGetEnumValue(const char *fieldName, T &value) const
Tries to get the enum value of the specified string.
Definition: EnumDictionary.hxx:155
EnumDictionary(const InitializerList &fields)
Constructor passing the enum fields as initializer list.
Definition: EnumDictionary.hxx:80
const char * GetEnumString(T value) const
Returns the string of the specified enum entry.
Definition: EnumDictionary.hxx:127
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
This (meta programming) class provides the C++ typename of the as template argument passed type.
Definition: TypeName.hxx:67
Root namespace for the PLCnext API
ARP_CXX_SYMBOL_EXPORT bool TryGetEnumValue(const char *name, T &value)
This helper function tries to return the enum entry of the specified string.