PLCnext API Documentation  21.0.0.35466
EnumStrings.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include <map>
9 
10 namespace Arp
11 {
12 
13 // forwards
14 template<class T>
15 class Enum;
16 
21 template<class T>
22 ARP_CXX_SYMBOL_EXPORT const char* GetEnumString(T key);
23 
29 template<class T>
30 ARP_CXX_SYMBOL_EXPORT bool TryGetEnumValue(const char* name, T& value);
31 
38 template<class T>
40 {
41 private: // typedefs, friends
42  friend const char* GetEnumString<>(T key);
43  friend bool TryGetEnumValue<>(const char* name, T& value);
44  friend class Enum<T>;
45  typedef std::map<T, const char*> Dictionary;
46 
47 public:
51  static const char* GetEntry(T key);
52 
57  static bool TryGetEntryValue(const char* name, T& value);
58 
59 private:
60  static const Dictionary Values;
61 
62 private:
63  EnumStrings(void) = delete;
64 };
65 
67 // inline methods of class EnumString<T>
68 
69 template<class T>
70 inline const char* EnumStrings<T>::GetEntry(T key)
71 {
72  return GetEnumString<T>(key);
73 }
74 
75 template<class T>
76 inline bool EnumStrings<T>::TryGetEntryValue(const char* name, T& value)
77 {
78  return TryGetEnumValue<T>(name, value);
79 }
80 
81 } // end of namespace Arp
82 
static bool TryGetEntryValue(const char *name, T &value)
Tries to return the enum entry of the specified string.
Definition: EnumStrings.hxx:76
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:23
ARP_CXX_SYMBOL_EXPORT bool TryGetEnumValue(const char *name, T &value)
This helper function tries to return the enum entry of the specified string.
ARP_CXX_SYMBOL_EXPORT const char * GetEnumString(T key)
This helper function returns the string of the specified enum entry.
static const char * GetEntry(T key)
Returns the string of the specified enum entry.
Definition: EnumStrings.hxx:70
The class implements an adapter for enums to define the string literals of the enum entries...
Definition: EnumStrings.hxx:39
Root namespace for the PLCnext API