PLCnext API Documentation 25.0.2.69
RscTypeDeduction.Impl.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Rsc/Commons/RscType.hpp"
9#include "Arp/Base/Rsc/Commons/RscSerializable.hpp"
10#include <type_traits>
11
12// forwards
13namespace Arp::Base::Commons::Security
14{
15class SecurityToken;
16}
17namespace Arp::Base::Rsc::Commons
18{
19class RscGuid;
20class RscVersion;
21template<int N> class RscString;
22template<int N> class RscSecureString;
23template<int N> class RscVariant;
24}
25
26namespace Arp::Base::Rsc::Commons::Impl
27{
28
29// concept BoundedCharArray
30template<class>
31struct IsBoundedCharArray : std::false_type {};
32
33template<size_t N>
34struct IsBoundedCharArray<char[N]> : std::true_type {};
35
36template<class T>
37concept BoundedCharArray = IsBoundedCharArray<T>::value;
38
39// concept RscArryType
40template <class T>
41concept ArrayType = std::is_array_v<T>&& !IsBoundedCharArray<T>::value;
42
43// GetRscType<T> implementation
44template<class T>
45constexpr RscType GetRscType(void)
46{
47 // REMARK: constexpr might only have a single return statement
48 return std::is_enum<T>::value ? GetRscType<typename underlying_enum_type<T>::type>() :
49 (
50 std::is_base_of<RscSerializable, T>::value ? RscType::Struct :
51 (
52 std::is_array<T>::value ? RscType::Array : RscType::None
53 )
54 );
55}
56
57template<>
58constexpr RscType GetRscType<boolean>()
59{
60 return RscType::Bool;
61}
62
63template<>
64constexpr RscType GetRscType<char8>()
65{
66 return RscType::Uint8;
67}
68
69template<>
70constexpr RscType GetRscType<char16>()
71{
72 return RscType::Char;
73}
74
75template<>
76constexpr RscType GetRscType<uint8>()
77{
78 return RscType::Uint8;
79}
80
81template<>
82constexpr RscType GetRscType<int8>()
83{
84 return RscType::Int8;
85}
86
87template<>
88constexpr RscType GetRscType<uint16>()
89{
90 return RscType::Uint16;
91}
92
93template<>
94constexpr RscType GetRscType<int16>()
95{
96 return RscType::Int16;
97}
98
99template<>
100constexpr RscType GetRscType<uint32>()
101{
102 return RscType::Uint32;
103}
104
105template<>
106constexpr RscType GetRscType<int32>()
107{
108 return RscType::Int32;
109}
110
111template<>
112constexpr RscType GetRscType<uint64>()
113{
114 return RscType::Uint64;
115}
116
117template<>
118constexpr RscType GetRscType<int64>()
119{
120 return RscType::Int64;
121}
122
123template<>
124constexpr RscType GetRscType<float32>()
125{
126 return RscType::Real32;
127}
128
129template<>
130constexpr RscType GetRscType<float64>()
131{
132 return RscType::Real64;
133}
134
135template<>
136constexpr RscType GetRscType<String>()
137{
138 return RscType::String;
139}
140
141template<>
142constexpr RscType GetRscType<char8*>()
143{
144 return RscType::String;
145}
146
147template<>
148constexpr RscType GetRscType<char8[]>()
149{
150 return RscType::String;
151}
152
153template<>
154constexpr RscType GetRscType<const char8*>()
155{
156 return RscType::String;
157}
158
159template<>
160constexpr RscType GetRscType<const char8[]>()
161{
162 return RscType::String;
163}
164
165template<>
166constexpr RscType GetRscType<DateTime>()
167{
168 return RscType::DateTime;
169}
170
171template<>
172constexpr RscType GetRscType<RscVersion>()
173{
174 return RscType::Version;
175}
176
177template<>
178constexpr RscType GetRscType<RscGuid>()
179{
180 return RscType::Guid;
181}
182
183} // end of namespace Arp::Base::Rsc::Commons::Impl
184
Definition: RscTypeDeduction.Impl.hpp:31