PLCnext API Documentation 23.3.0.32
CommonTypeName.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Core/TypeName.hxx"
9
10namespace Arp
11{
12
28template<class T = void>
30{
31 friend class CommonTypeName<void>;
32
33public: // 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
49public: // operations
52 String GetNamespace(void)const;
55 String GetClassName(void)const;
56
57public: // fields
60
61public: // operators
63 operator const String& (void)const;
65 operator const char*(void)const;
66
67private: // construction
68 CommonTypeName(const char* typeName);
69};
70
72// inline methods of class CommonTypeName
73template<class T>
75 : Value(TypeName<T>().GetCommonName())
76{
77}
78
79template<class T>
80inline CommonTypeName<T>::CommonTypeName(const char* typeName)
81 : Value(typeName)
82{
83}
84
85template<class T>
87{
88 return this->Value;
89}
90
91template<class T>
92inline CommonTypeName<T>::operator const char*()const
93{
94 return this->Value.CStr();
95}
96
97template<class T>
99{
100 return __Internal::TypeNameHelper::GetNamespace(this->Value, true);
101}
102
103template<class T>
105{
106 return __Internal::TypeNameHelper::GetClassName(this->Value, true);
107}
108
110// implementation of template specialization CommonTypeName<void>
112template<>
113class CommonTypeName<void>
114{
115private: // construction/destruction
116 CommonTypeName(void) = delete;
117 CommonTypeName(const CommonTypeName& arg) = delete;
118 CommonTypeName& operator=(const CommonTypeName& arg) = delete;
119 ~CommonTypeName(void) = delete;
120
121public: // 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 & operator=(const CommonTypeName &arg)=default
The default assignment operator.
~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
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:67
String GetCommonName(void) const
Gets the common name of the as template parameter given type according to the CLS.
Definition: TypeName.hxx:147
Root namespace for the PLCnext API