PLCnext API Documentation  22.9.0.33
TypeDeduction.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include <type_traits>
9 
10 namespace Arp
11 {
12 
13 
16 
18 // IsInstanceOfType
19 
25 template<class T, class TInstance>
26 inline bool IsInstanceOfType(const TInstance& instance)
27 {
28  const TInstance *instancePtr = &instance;
29  return (dynamic_cast<const T*>(instancePtr)) != nullptr;
30 }
31 
37 template<class T, class TInstance>
38 inline bool IsInstanceOfType(const TInstance* pInstance)
39 {
40  return (pInstance != nullptr) && (dynamic_cast<const T*>(pInstance) != nullptr);
41 }
42 
48 template<class T, class TInstance>
49 inline bool IsInstanceOfType(TInstance& instance)
50 {
51  return dynamic_cast<T*>(&instance) != nullptr;
52 }
53 
59 template<class T, class TInstance>
60 inline bool IsInstanceOfType(TInstance* pInstance)
61 {
62  return (pInstance != nullptr) && (dynamic_cast<T*>(pInstance) != nullptr);
63 }
64 
66 // underlying_enum_type: meta function to determine underlying type of enums
70 template<class T, bool IsEnum = std::is_enum<T>::value>
71 struct underlying_enum_type // primary template, none enum
72 {
73  typedef T type;
74 };
75 
78 template<class T>
79 struct underlying_enum_type<T, true> // specialized template for enums, use underlying type
80 {
81  typedef typename std::underlying_type<T>::type type;
82 };
83 
85 // remove_shared_ptr
88 template<class T>
90 {
91  typedef T type;
92 };
93 
96 
97 template<class T>
98 struct remove_shared_ptr<std::shared_ptr<T>>
99 {
100  typedef T type;
101 };
102 
104 
105 } // end of namespace Arp::System::Core
106 
bool IsInstanceOfType(const TInstance &instance)
Tests if the type of the as argument passed instance is T or derived by T .
Definition: TypeDeduction.hxx:26
Root namespace for the PLCnext API
Namespace of the C++ standard library
T type
The resulting type.
Definition: TypeDeduction.hxx:100
Gets the value type of a shared_ptr.
Definition: TypeDeduction.hxx:90
T type
The resulting type.
Definition: TypeDeduction.hxx:91
std::underlying_type< T >::type type
The resulting type.
Definition: TypeDeduction.hxx:81
Determines the underlying type of an enum class.
Definition: TypeDeduction.hxx:72
T type
The resulting type.
Definition: TypeDeduction.hxx:73