PLCnext API Documentation 25.0.2.69
EnumFlagsDictionary.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>
10namespace Arp { namespace Base { namespace Core
11{
12
16template<class T, char Delimiter = '|'>
18{
19private: // usings
21 using U = typename Base::U;
23
24public: // construction
26 EnumFlagsDictionary(T flagsMask, const InitializerList& fields);
27 EnumFlagsDictionary(T flagsMask, const char* invalidValueString, const InitializerList& fields);
28 EnumFlagsDictionary(U flagsMask, const InitializerList& fields);
29 EnumFlagsDictionary(U flagsMask, const char* invalidValueString, const InitializerList& fields);
30
31public: // overlapping operations from base class EnumDictionary<T> (used by stream operators of enums)
32 std::ostream& WriteEnumString(std::ostream& os, T value)const;
33 std::istream& ReadEnumValue(std::istream& is, T& value)const;
34
35public: // string conversion operation
36 String GetEnumString(T value)const;
37 bool TryGetEnumString(T value, String& result)const;
38 T GetEnumValue(const String& fieldName)const;
39 bool TryGetEnumValue(const String& fieldName, T& value)const;
40
41private: // methods
42 bool IsFlag(T value)const;
43 bool TryGetCombinedEnumString(T value, String& result)const;
44 bool TryParseCombinedEnumValue(const String& input, T& value)const;
45 bool TryFormatFlags(T value, String& result)const;
46
47private: // fields
48 T flagsMask = static_cast<T>(std::numeric_limits<U>::max());
49};
50
51}}} // end of namespace Arp::Base::Core
52
53namespace Arp {
56}
57#include "Arp/Base/Core/Detail/EnumFlagsDictionary.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
This class implements an adapter for enums containing flags to define the string literals of the enum...
Definition: EnumFlagsDictionary.hxx:18
std::ostream & WriteEnumString(std::ostream &os, T value) const
Writes the string of the specified enum value to the given stream.
Definition: EnumFlagsDictionary.ipp:69
T GetEnumValue(const String &fieldName) const
Returns the value of the specified enum string.
Definition: EnumFlagsDictionary.ipp:137
bool TryGetEnumValue(const String &fieldName, T &value) const
Tries to get the enum value of the specified string.
Definition: EnumFlagsDictionary.ipp:152
String GetEnumString(T value) const
Returns the string of the specified enum entry.
Definition: EnumFlagsDictionary.ipp:111
EnumFlagsDictionary(const InitializerList &fields)
Constructor passing the enum fields as initializer list.
Definition: EnumFlagsDictionary.ipp:19
bool TryGetEnumString(T value, String &result) const
Returns the string of the specified enum value or nullptr if the value could not be found.
Definition: EnumFlagsDictionary.ipp:127
std::istream & ReadEnumValue(std::istream &is, T &value) const
Tries to return the enum entry of the specified string.
Definition: EnumFlagsDictionary.ipp:95
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
Root namespace for the PLCnext API