8#ifndef ARP_USE_ARP_SYSTEM_CORE
10#include "Arp/Base/Core/EnumDictionary.hxx"
15#include "Arp/System/Core/EnumDictionaryBase.hxx"
16#include "Arp/System/Core/TypeName.hxx"
28class EnumDictionary :
public EnumDictionaryBase<T>
31 using Base = EnumDictionaryBase<T>;
42 EnumDictionary(
const char* invalidValueString,
const InitializerList& fields);
93EnumDictionary<T>::EnumDictionary(
const char* invalidValueString,
const InitializerList& fields)
94 : Base(invalidValueString, fields)
99std::ostream& EnumDictionary<T>::WriteEnumString(std::ostream& os, T value)
const
101 const char* pString =
nullptr;
102 if (this->TryGetEnumString(value, pString))
108 if (this->invalidValueString.IsEmpty())
110 os << String::Format(
"{:d}",
static_cast<U
>(value));
114 os << this->invalidValueString;
116 os.setstate(std::ios::failbit);
122inline std::istream& EnumDictionary<T>::ReadEnumValue(std::istream& is, T& value)
const
126 if (!TryGetEnumValue(token, value))
128 is.setstate(std::ios::failbit);
134inline const char* EnumDictionary<T>::GetEnumString(T value)
const
136 const char* pResult =
nullptr;
137 if(!this->TryGetEnumString(value, pResult))
139 throw Exception(
"Could not find enum string of enum '{}' for value '{}'.", TypeName<T>(),
static_cast<U
>(value));
145inline bool EnumDictionary<T>::TryGetEnumString(T value,
const char*& pResult)
const
147 return this->TryGetEnumStringInternal(value, pResult);
151inline T EnumDictionary<T>::GetEnumValue(
const char* fieldName)
const
154 if (!this->TryGetEnumValue(fieldName, result))
156 throw Exception(
"Could not find enum value of enum '{}' for string '{}'.", TypeName<T>(), fieldName);
162inline bool EnumDictionary<T>::TryGetEnumValue(
const char* fieldName, T& value)
const
164 return this->TryGetEnumValueInternal(fieldName, value);
std::initializer_list< typename Fields::value_type > InitializerList
The initializer list type of the Fields container.
Definition: EnumDictionaryBase.hxx:24
typename std::underlying_type< T >::type U
The underlying integral type of the enum.
Definition: EnumDictionaryBase.hxx:25
const char * GetEnumString(T value) const
Returns the string of the specified enum entry.
Definition: EnumDictionary.ipp:82
bool TryGetEnumValue(const char *fieldName, T &value) const
Tries to get the enum value of the specified string.
Definition: EnumDictionary.ipp:122
std::istream & ReadEnumValue(std::istream &is, T &value) const
Tries to return the enum entry of the specified string.
Definition: EnumDictionary.ipp:66
T GetEnumValue(const char *fieldName) const
Returns the value of the specified enum string.
Definition: EnumDictionary.ipp:107
EnumDictionary(const InitializerList &fields)
Constructor passing the enum fields as initializer list.
Definition: EnumDictionary.ipp:20
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.ipp:97
std::ostream & WriteEnumString(std::ostream &os, T value) const
Writes the string of the specified enum value to the given stream.
Definition: EnumDictionary.ipp:40
Root namespace for the PLCnext API