PLCnext API Documentation 23.6.0.37
TypeDeduction.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include <type_traits>
9
10namespace Arp
11{
12
13
16
18// IsInstanceOfType
19
25template<class T, class TInstance>
26inline bool IsInstanceOfType(const TInstance& instance)
27{
28 const TInstance *instancePtr = &instance;
29 return (dynamic_cast<const T*>(instancePtr)) != nullptr;
30}
31
37template<class T, class TInstance>
38inline bool IsInstanceOfType(const TInstance* pInstance)
39{
40 return (pInstance != nullptr) && (dynamic_cast<const T*>(pInstance) != nullptr);
41}
42
48template<class T, class TInstance>
49inline bool IsInstanceOfType(TInstance& instance)
50{
51 return dynamic_cast<T*>(&instance) != nullptr;
52}
53
59template<class T, class TInstance>
60inline 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
70template<class T, bool IsEnum = std::is_enum<T>::value>
71struct underlying_enum_type // primary template, none enum
72{
73 typedef T type;
74};
75
78template<class T>
79struct 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
88template<class T>
90{
91 typedef T type;
92};
93
96
97template<class T>
98struct 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