PLCnext API Documentation 23.6.0.37
Public Member Functions | Protected Types | List of all members
Arp::EnumFlagsDictionary< T, Delimiter > Class Template Reference

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

#include <EnumFlagsDictionary.hxx>

Inheritance diagram for Arp::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...
 
- 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, char Delimiter = '|'>
class Arp::EnumFlagsDictionary< T, Delimiter >

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

◆ EnumFlagsDictionary() [1/5]

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

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::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( flagsMask,
const InitializerList &  fields 
)

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bitmask which defines the flags of the enum.

◆ EnumFlagsDictionary() [3/5]

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

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bitmask 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::EnumFlagsDictionary< T, Delimiter >::EnumFlagsDictionary ( flagsMask,
const InitializerList &  fields 
)

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bitmask which defines the flags of the enum.

◆ EnumFlagsDictionary() [5/5]

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

Constructor passing the enum fields as initializer list.

Parameters
fieldsThe enum fields as value string pairs.
flagsMaskA bitmask 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::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.

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

◆ GetEnumValue()

template<class T , char Delimiter>
T Arp::EnumFlagsDictionary< T, Delimiter >::GetEnumValue ( const String fieldName) const

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 , char Delimiter>
std::istream & Arp::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::EnumFlagsDictionary< T, Delimiter >::TryGetEnumString ( value,
String result 
) const

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

◆ TryGetEnumValue()

template<class T , char Delimiter>
bool Arp::EnumFlagsDictionary< T, Delimiter >::TryGetEnumValue ( const String fieldName,
T &  value 
) const

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::EnumFlagsDictionary< T, Delimiter >::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 t owrite.
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: