PLCnext API Documentation 25.0.2.69
Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Arp::Base::Core::EnumDictionaryBase< T > Class Template Reference

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

#include <EnumDictionaryBase.hxx>

Inheritance diagram for Arp::Base::Core::EnumDictionaryBase< T >:
Inheritance graph

Protected Types

using Fields = std::map< T, const char * >
 The container type containing the value/name pairs of all enum fields.
 
using InitializerList = std::initializer_list< typename Fields::value_type >
 The initializer list type of the Fields container.
 
using U = typename std::underlying_type< T >::type
 The underlying integral type of the enum.
 

Protected Member Functions

 EnumDictionaryBase (const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumDictionaryBase (const char *invalidValueString, const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumDictionaryBase (const EnumDictionaryBase &arg)
 Copy constructor.
 
 EnumDictionaryBase (EnumDictionaryBase &&arg) noexcept
 Move constructor.
 
EnumDictionaryBaseoperator= (const EnumDictionaryBase &arg)
 Copy-assignment operator.
 
EnumDictionaryBaseoperator= (EnumDictionaryBase &&arg) noexcept
 Move-assignment operator.
 
 ~EnumDictionaryBase (void)
 Destructor.
 
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

Fields fields
 
String invalidValueString
 

Static Protected Attributes

static const T zeroValue = static_cast<T>(0)
 

Detailed Description

template<class T>
class Arp::Base::Core::EnumDictionaryBase< T >

This 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 or formattable, respectively.

Constructor & Destructor Documentation

◆ EnumDictionaryBase() [1/2]

template<class T >
Arp::Base::Core::EnumDictionaryBase< T >::EnumDictionaryBase ( const InitializerList fields)
inlineexplicitprotected

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.

◆ EnumDictionaryBase() [2/2]

template<class T >
Arp::Base::Core::EnumDictionaryBase< T >::EnumDictionaryBase ( const char *  invalidValueString,
const InitializerList fields 
)
inlineprotected

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

◆ TryGetEnumStringInternal()

template<class T >
bool Arp::Base::Core::EnumDictionaryBase< T >::TryGetEnumStringInternal ( value,
const char *&  pResult 
) const
inlineprotected

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.
Returns
true on success, otherwise false.

◆ TryGetEnumValueInternal()

template<class T >
bool Arp::Base::Core::EnumDictionaryBase< T >::TryGetEnumValueInternal ( const char *  fieldName,
T &  value 
) const
inlineprotected

Tries to get the enum value of the specified string.

Parameters
fieldNameThe string to get the associated enum value from.
valueThe resulting enum value or T{} if it could not be found.
Returns
true on success, otherwise false.

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