PLCnext API Documentation 25.0.2.69
EnumDictionary.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Core/Detail/EnumDictionaryBase.hxx"
9#include <iosfwd>
10
11namespace Arp { namespace Base { namespace Core
12{
13
17template<class T>
19{
20private: // usings
22 using U = typename Base::U;
24
25public: // construction/destruction
26 EnumDictionary(const InitializerList& fields);
27 EnumDictionary(const char* invalidValueString, const InitializerList& fields);
28
29public: // operations used by stream operators of enums
30 std::ostream& WriteEnumString(std::ostream& os, T value)const;
31 std::istream& ReadEnumValue(std::istream& is, T& value)const;
32
33public: // string conversion operations
34 const char* GetEnumString(T value)const;
35 bool TryGetEnumString(T value, const char*& pResult)const;
36 T GetEnumValue(const char* fieldName)const;
37 bool TryGetEnumValue(const char* fieldName, T& value)const;
38};
39
40}}} // end of namespace Arp::Base::Core
41
42namespace Arp {
45}
46#include "Arp/Base/Core/Detail/EnumDictionary.ipp"
This class implements an adapter for enums to define the string literals of the enum entries.
Definition: EnumDictionaryBase.hxx:18
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
The class implements an adapter for enums to define the string literals of the enum entries.
Definition: EnumDictionary.hxx:19
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