PLCnext API Documentation 25.0.2.69
Public Member Functions | List of all members
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter > Class Template Reference

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

#include <EnumFlagsDictionary.hxx>

Inheritance diagram for Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >:
Inheritance graph

Public Member Functions

 EnumFlagsDictionary (const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumFlagsDictionary (T flagsMask, const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumFlagsDictionary (T flagsMask, const char *invalidValueString, const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumFlagsDictionary (U flagsMask, const InitializerList &fields)
 Constructor passing the enum fields as initializer list. More...
 
 EnumFlagsDictionary (U flagsMask, 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...
 
String GetEnumString (T value) const
 Returns the string of the specified enum entry. More...
 
bool TryGetEnumString (T value, String &result) const
 Returns the string of the specified enum value or nullptr if the value could not be found. More...
 
GetEnumValue (const String &fieldName) const
 Returns the value of the specified enum string. More...
 
bool TryGetEnumValue (const String &fieldName, T &value) const
 Tries to get the enum value of the specified string. More...
 

Additional Inherited Members

- Protected Types inherited from Arp::Base::Core::EnumDictionaryBase< T >
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 inherited from Arp::Base::Core::EnumDictionaryBase< T >
 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 inherited from Arp::Base::Core::EnumDictionaryBase< T >
Fields fields
 
String invalidValueString
 
- Static Protected Attributes inherited from Arp::Base::Core::EnumDictionaryBase< T >
static const T zeroValue = static_cast<T>(0)
 

Detailed Description

template<class T, char Delimiter = '|'>
class Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >

This class implements an adapter for enums containing flags 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

◆ EnumFlagsDictionary() [1/5]

template<class T , char Delimiter>
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( const InitializerList fields)
inline

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.

◆ EnumFlagsDictionary() [2/5]

template<class T , char Delimiter>
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( flagsMask,
const InitializerList fields 
)
inline

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bit-mask which defines the flags of the enum.

◆ EnumFlagsDictionary() [3/5]

template<class T , char Delimiter>
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( flagsMask,
const char *  invalidValueString,
const InitializerList fields 
)
inline

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bit-mask which defines the flags of the enum.
invalidValueStringA string which is used for formatting an invalid enum value.

◆ EnumFlagsDictionary() [4/5]

template<class T , char Delimiter>
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( U  flagsMask,
const InitializerList fields 
)
inline

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bit-mask which defines the flags of the enum.

◆ EnumFlagsDictionary() [5/5]

template<class T , char Delimiter>
Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( U  flagsMask,
const char *  invalidValueString,
const InitializerList fields 
)
inline

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bit-mask which defines the flags of the enum.
invalidValueStringA string which is used for formatting an invalid enum value.

Member Function Documentation

◆ GetEnumString()

template<class T , char Delimiter>
String Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::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.
Exceptions
ExceptionIf the as argument passed value is not defined in the enum.

◆ GetEnumValue()

template<class T , char Delimiter>
T Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::GetEnumValue ( const String 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.
Exceptions
ExceptionIf the as argument passed field name is not defined in the enum.

◆ ReadEnumValue()

template<class T , char Delimiter>
std::istream & Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::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
true on success, otherwise false.

◆ TryGetEnumString()

template<class T , char Delimiter>
bool Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::TryGetEnumString ( value,
String result 
) 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.
resultThe string of the as argument passed enum value or nullptr if it could not be found.
Returns
true on success, otherwise false.

◆ TryGetEnumValue()

template<class T , char Delimiter>
bool Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::TryGetEnumValue ( const String 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 , char Delimiter>
std::ostream & Arp::Base::Core::EnumFlagsDictionary< T, Delimiter >::WriteEnumString ( std::ostream &  os,
value 
) const
inline

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

Parameters
osThe stream to write the enum string to.
valueThe enum value t overwrite.
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 files: