PLCnext API Documentation 23.3.0.32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Protected Types | List of all members
Arp::EnumDictionary< T > Class Template Reference

The class implements an adapter for enums to define the string literals of the enum entries. More...

#include <EnumDictionary.hxx>

Inheritance diagram for Arp::EnumDictionary< T >:
Inheritance graph

Public Member Functions

 EnumDictionary (const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumDictionary (const char *invalidValueString, const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
std::ostream & WriteEnumString (std::ostream &os, T value) const
 Writes the string of the specified enum value to the given stream. More...
 
std::istream & ReadEnumValue (std::istream &is, T &value) const
 Tries to return the enum entry of the specified string. More...
 
const char * GetEnumString (T value) const
 Returns the string of the specified enum entry. More...
 
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. More...
 
GetEnumValue (const char *fieldName) const
 Returns the value of the specified enum string. More...
 
bool TryGetEnumValue (const char *fieldName, T &value) const
 Tries to get the enum value of the specified string. More...
 
- Public Member Functions inherited from Arp::EnumDictionaryBase< T >
 EnumDictionaryBase (const InitializerList &fields)
 
 EnumDictionaryBase (const char *invalidValueString, const InitializerList &fields)
 

Protected Types

using Base = EnumDictionaryBase< T >
 
using U = typename Base::U
 
using InitializerList = typename Base::InitializerList
 
- Protected Types inherited from Arp::EnumDictionaryBase< T >
using Fields = std::map< T, const char * >
 
using InitializerList = std::initializer_list< typename Fields::value_type >
 
using U = typename std::underlying_type< T >::type
 

Additional Inherited Members

- Protected Member Functions inherited from Arp::EnumDictionaryBase< T >
bool TryGetEnumStringInternal (T value, const char *&pResult) const
 Returns the string of the specified enum value or nullptr if the value could not be found. More...
 
bool TryGetEnumValueInternal (const char *fieldName, T &value) const
 Tries to get the enum value of the specified string. More...
 
- Protected Attributes inherited from Arp::EnumDictionaryBase< T >
Fields fields
 
String invalidValueString
 
- Static Protected Attributes inherited from Arp::EnumDictionaryBase< T >
static const T zeroValue = static_cast<T>(0)
 

Detailed Description

template<class T>
class Arp::EnumDictionary< T >

The class implements an adapter for enums to define the string literals of the enum entries.

Template Parameters
TThe type of the enum.

This is a helper class to make enums parsable and loggable/formattable. This helper class is specialied for any enum T defining its string literals using EnumStrings<Tgt;.

Constructor & Destructor Documentation

◆ EnumDictionary() [1/2]

template<class T >
Arp::EnumDictionary< T >::EnumDictionary ( const InitializerList &  fields)

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.

◆ EnumDictionary() [2/2]

template<class T >
Arp::EnumDictionary< T >::EnumDictionary ( const char *  invalidValueString,
const InitializerList &  fields 
)

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
invalidValueStringA string which is used for formatting an invalid enum value.

Member Function Documentation

◆ GetEnumString()

template<class T >
const char * Arp::EnumDictionary< T >::GetEnumString ( value) const
inline

Returns the string of the specified enum entry.

Parameters
valueThe enum value of enum T to get the associated string from.
Returns
The string literal of the as argument passed enum value.

If the as argument passed value is not defined in the enum.

◆ GetEnumValue()

template<class T >
T Arp::EnumDictionary< T >::GetEnumValue ( const char *  fieldName) const
inline

Returns the value of the specified enum string.

Parameters
fieldNameThe name of the enum field to get the associated string from.
Returns
The value of the as argument passed enum string.

If the as argument passed field name is not defined in the enum.

◆ ReadEnumValue()

template<class T >
std::istream & Arp::EnumDictionary< T >::ReadEnumValue ( std::istream &  is,
T &  value 
) const
inline

Tries to return the enum entry of the specified string.

Parameters
isThe stream to read the fieldName from to get the associated enum value.
valueThe resulting enum value.
Returns
The as argument passed stream reference.

◆ TryGetEnumString()

template<class T >
bool Arp::EnumDictionary< T >::TryGetEnumString ( value,
const char *&  pResult 
) const
inline

Returns the string of the specified enum value or nullptr if the value could not be found.

Parameters
valueThe enum value of enum T to get the associated string from.
pResultThe string of the as argument passed enum value or nullptr if it could not be found.
Parameters
value
Returns
true on success, otherwise false.

◆ TryGetEnumValue()

template<class T >
bool Arp::EnumDictionary< T >::TryGetEnumValue ( const char *  fieldName,
T &  value 
) const
inline

Tries to get the enum value of the specified string.

Parameters
fieldNameThe string to get the associated enum value from.
valueThe resulting enum value.
Returns
true on success, otherwise false.

◆ WriteEnumString()

template<class T >
std::ostream & Arp::EnumDictionary< T >::WriteEnumString ( std::ostream &  os,
value 
) const

Writes the string of the specified enum value to the given stream.

Parameters
osThe stream to write the enum string to.
valueThe enum value to write.
Returns
The as argument passed stream reference.

If the field name of the given enum value could not be found, the enum value is written as hex-string to the stream.


The documentation for this class was generated from the following file: