PLCnext API Documentation  22.9.0.33
CommonTypeName.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/TypeName.hxx"
9 
10 namespace Arp
11 {
12 
28 template<class T = void>
30 {
31  friend class CommonTypeName<void>;
32 
33 public: // construction/destruction
35  CommonTypeName(void);
38  CommonTypeName(const CommonTypeName& arg) = default;
41  CommonTypeName(CommonTypeName&& arg)noexcept = default;
45  CommonTypeName& operator=(const CommonTypeName& arg) = default;
47  ~CommonTypeName(void) = default;
48 
49 public: // operations
52  String GetNamespace(void)const;
55  String GetClassName(void)const;
56 
57 public: // fields
60 
61 public: // operators
63  operator const String& (void)const;
65  operator const char*(void)const;
66 
67 private: // construction
68  CommonTypeName(const char* typeName);
69 };
70 
72 // inline methods of class CommonTypeName
73 template<class T>
75  : Value(TypeName<T>().GetCommonName())
76 {
77 }
78 
79 template<class T>
80 inline CommonTypeName<T>::CommonTypeName(const char* typeName)
81  : Value(typeName)
82 {
83 }
84 
85 template<class T>
86 inline CommonTypeName<T>::operator const String& ()const
87 {
88  return this->Value;
89 }
90 
91 template<class T>
92 inline CommonTypeName<T>::operator const char*()const
93 {
94  return this->Value.CStr();
95 }
96 
97 template<class T>
99 {
100  return __Internal::TypeNameHelper::GetNamespace(this->Value, true);
101 }
102 
103 template<class T>
105 {
106  return __Internal::TypeNameHelper::GetClassName(this->Value, true);
107 }
108 
110 // implementation of template specialization CommonTypeName<void>
112 template<>
113 class CommonTypeName<void>
114 {
115 private: // construction/destruction
116  CommonTypeName(void) = delete;
117  CommonTypeName(const CommonTypeName& arg) = delete;
118  CommonTypeName& operator=(const CommonTypeName& arg) = delete;
119  ~CommonTypeName(void) = delete;
120 
121 public: // static factory operations
126  template <class T2>
127  static CommonTypeName<T2> GetFrom(T2& instance)
128  {
129  return GetFrom(&instance);
130  }
131 
136  template <class T2>
137  static CommonTypeName<T2> GetFrom(T2* pInstance)
138  {
139  CommonTypeName<T2> result;
140  result.Value = TypeName<void>::GetFrom(pInstance).GetCommonName();
141  return result;
142  }
143 };
144 
145 } // end of namespace Arp
static CommonTypeName< T2 > GetFrom(T2 &instance)
Creates the CommonTypeName from the as argument passed variable.
Definition: CommonTypeName.hxx:127
static CommonTypeName< T2 > GetFrom(T2 *pInstance)
Creates the CommonTypeName from the as argument passed variable pointer.
Definition: CommonTypeName.hxx:137
This (meta programming) class provides the typename according the CLS (common language specification)...
Definition: CommonTypeName.hxx:30
CommonTypeName(void)
Constructs a CommonTypeName instance and determines the typename of the of T.
Definition: CommonTypeName.hxx:74
~CommonTypeName(void)=default
The default destructor..
String GetClassName(void) const
Gets the classname of the as template parameter given type.
Definition: CommonTypeName.hxx:104
String Value
The CLS typename of the as template argument passed type.
Definition: CommonTypeName.hxx:59
CommonTypeName & operator=(const CommonTypeName &arg)=default
The default assignment operator.
String GetNamespace(void) const
Gets the namespace of the as template parameter given type.
Definition: CommonTypeName.hxx:98
CommonTypeName(const CommonTypeName &arg)=default
The default copy constructor.
CommonTypeName(CommonTypeName &&arg) noexcept=default
The default move constructor.
This (meta programming) class provides the C++ typename of the as template argument passed type.
Definition: TypeName.hxx:56
String GetCommonName(void) const
Gets the common name of the as template parameter given type according to the CLS.
Definition: TypeName.hxx:136
Root namespace for the PLCnext API