PLCnext API Documentation  22.9.0.33
RscType.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/TypeDeduction.hxx"
9 #include "Arp/System/Core/Enum.hxx"
10 #include <type_traits>
11 
12 // forwards
13 namespace Arp { namespace System { namespace Security
14 {
15 class SecurityToken;
16 }}}
17 
18 namespace Arp { namespace System { namespace Rsc { namespace Services
19 {
20 
21 // usings
22 using SecurityToken = Arp::System::Security::SecurityToken;
23 
24 // forwards
25 template<int N>
26 class RscString;
27 template<int N>
28 class SecureString;
29 class IRscSerializable;
30 class RscVersion;
31 class RscGuid;
32 
36 enum class RscType : uint8
37 {
39  None = 0xFF,
41  End = 0,
43  Null = 0,
45  Void = 1,
47  Bool = 2,
49  Char = 3,
51  Int8 = 4,
53  Uint8 = 5,
55  Int16 = 6,
57  Uint16 = 7,
59  Int32 = 8,
61  Uint32 = 9,
63  Int64 = 10,
65  Uint64 = 11,
67  Real32 = 12,
69  Real64 = 13,
71  Struct = 18,
74  String = 19,
76  Utf8String = 19,
78  Array = 20,
80  DateTime = 23,
82  Version = 24,
84  Guid = 25,
86  AnsiString = 26,
88  Object = 28,
90  Utf16String = 30,
92  Stream = 34,
94  Enumerator = 35,
96  SecureString = 36,
98  Enum = 37,
100  Dictionary = 38,
102  SecurityToken = 39,
104  Exception = 40,
106  IecTime = 41,
108  IecTime64 = 42,
111  IecDate = 43,
113  IecDate64 = 44,
116  IecDateTime = 45,
118  IecDateTime64 = 46,
121  IecTimeOfDay = 47,
123  IecTimeOfDay64 = 48,
124 };
125 
130 {
131  RscArrayInformation(void) = default;
132  RscArrayInformation(size_t size, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0)
133  : Size(size)
134  , ElementType(elementType)
135  , Dimensions(dimensions)
136  , FieldCount(fieldCount)
137  {}
138 
142  size_t Size = 0;
143 
147  size_t Dimensions = 1;
148 
153 
157  size_t FieldCount = 0;
158 };
159 
164 {
165  RscStructInformation(size_t fieldCount) : FieldCount(fieldCount) {}
166 
170  size_t FieldCount = 0;
171 };
172 
173 // global function GetRscType to determine RscType value by type
175 template<class T, bool isSerializable = std::is_base_of<IRscSerializable, T>::value>
176 struct StructInfo
177 {
178  size_t FieldCount = 0;
179 };
180 
181 template<class T>
182 struct StructInfo<T, true>
183 {
184  size_t FieldCount = T::GetFieldCount();
185 };
186 
187 template<class T>
188 inline constexpr RscType GetRscType(void)
189 {
190  // REMARK: constexpr might only have a single return statement
191  return std::is_enum<T>::value ? GetRscType<typename underlying_enum_type<T>::type>() :
192  (
193  std::is_class<T>::value ? RscType::Struct :
194  (
195  std::is_array<T>::value ? RscType::Array : RscType::None
196  )
197  );
198 }
199 
200 template<>
201 inline constexpr RscType GetRscType<boolean>(void)
202 {
203  return RscType::Bool;
204 }
205 
206 template<>
207 inline constexpr RscType GetRscType<char8>(void)
208 {
209  return RscType::Uint8;
210 }
211 
212 template<>
213 inline constexpr RscType GetRscType<uint8>(void)
214 {
215  return RscType::Uint8;
216 }
217 
218 template<>
219 inline constexpr RscType GetRscType<int8>(void)
220 {
221  return RscType::Int8;
222 }
223 
224 template<>
225 inline constexpr RscType GetRscType<uint16>(void)
226 {
227  return RscType::Uint16;
228 }
229 
230 template<>
231 inline constexpr RscType GetRscType<int16>(void)
232 {
233  return RscType::Int16;
234 }
235 
236 template<>
237 inline constexpr RscType GetRscType<uint32>(void)
238 {
239  return RscType::Uint32;
240 }
241 
242 template<>
243 inline constexpr RscType GetRscType<int32>(void)
244 {
245  return RscType::Int32;
246 }
247 
248 template<>
249 inline constexpr RscType GetRscType<uint64>(void)
250 {
251  return RscType::Uint64;
252 }
253 
254 template<>
255 inline constexpr RscType GetRscType<int64>(void)
256 {
257  return RscType::Int64;
258 }
259 
260 template<>
261 inline constexpr RscType GetRscType<float32>(void)
262 {
263  return RscType::Real32;
264 }
265 
266 template<>
267 inline constexpr RscType GetRscType<float64>(void)
268 {
269  return RscType::Real64;
270 }
271 
272 template<>
273 inline constexpr RscType GetRscType<char*>(void)
274 {
275  return RscType::Utf8String;
276 }
277 
278 //template<>
279 //inline constexpr RscType GetRscType<IecString>(void) { return RscType::Utf8String; }
280 //
281 //template<>
282 //inline RscType GetRscType<StaticString<>>(void) { return RscType::Utf8String; }
283 
284 template<>
285 inline constexpr RscType GetRscType<String>(void)
286 {
287  return RscType::Utf8String;
288 }
289 
290 template<>
291 inline constexpr RscType GetRscType<DateTime>(void)
292 {
293  return RscType::DateTime;
294 }
295 
296 template<>
297 inline constexpr RscType GetRscType<RscVersion>(void)
298 {
299  return RscType::Version;
300 }
301 
302 template<>
303 inline constexpr RscType GetRscType<RscGuid>(void)
304 {
305  return RscType::Guid;
306 }
307 
308 template<>
309 inline constexpr RscType GetRscType<SecurityToken>(void)
310 {
311  return RscType::SecurityToken;
312 }
313 
314 template<class T>
315 inline constexpr RscType GetRscTypeFrom(const T& /*value*/)
316 {
317  return GetRscType<T>();
318 }
319 
320 template<int N>
321 inline constexpr RscType GetRscTypeFrom(const char(&)[N])
322 {
323  return RscType::Utf8String;
324 }
325 
326 template<int N>
327 inline constexpr RscType GetRscTypeFrom(const RscString<N>&)
328 {
329  return RscType::Utf8String;
330 }
331 
332 template<int N>
333 inline constexpr RscType GetRscTypeFrom(const SecureString<N>&)
334 {
335  return RscType::SecureString;
336 }
337 
338 template<>
339 inline constexpr RscType GetRscTypeFrom(const String&)
340 {
341  return RscType::Utf8String;
342 }
343 
344 template<>
345 inline constexpr RscType GetRscTypeFrom(const DateTime&)
346 {
347  return RscType::DateTime;
348 }
349 
350 template<>
351 inline constexpr RscType GetRscTypeFrom(const RscVersion&)
352 {
353  return RscType::Version;
354 }
355 
356 template<>
357 inline constexpr RscType GetRscTypeFrom(const RscGuid&)
358 {
359  return RscType::Guid;
360 }
361 
362 template<>
363 inline constexpr RscType GetRscTypeFrom(const SecurityToken&)
364 {
365  return RscType::SecurityToken;
366 }
367 
368 inline constexpr bool IsPrimitiveRscType(RscType type)
369 {
370  return (type >= RscType::Bool && type <= RscType::Real64) || (type >= RscType::IecTime && type <= RscType::IecTimeOfDay64);
371 }
372 
374 // global stream operators of enum LogLevel for logging and parsing
375 ARP_CXX_SYMBOL_EXPORT std::ostream& operator<<(std::ostream& os, const RscType value);
376 ARP_CXX_SYMBOL_EXPORT std::istream& operator>>(std::istream& is, RscType& value);
377 
378 }}}} // end of namespace Arp::System::Rsc::Services
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:35
The class contains date and time informations.
Definition: DateTime.hpp:45
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:23
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:22
This is the base class of all Arp exception classes.
Definition: Exception.hpp:16
Specialized version of RscString for security context. Not implemented in this version....
Definition: SecureString.hxx:19
Definition: SecurityToken.hpp:12
std::uint8_t uint8
The Arp unsigned integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:27
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
@ IecTimeOfDay
summary>IEC type: LTIME_OF_DAY, LTOD [int64]
@ Uint32
unsigned 32 bit integer
@ Uint16
unsigned 16 bit integer
@ Real32
32 bit floating point number
@ Int16
signed 16 bit integer
@ Uint8
unsigned 8 bit integer
@ IecDateTime
summary>IEC type: LDATE_AND_TIME, LDT [int64]
@ Object
Object type handled by Rsc as RscVariant
@ SecurityToken
Security token needed for security services, handly by Rsc with SecurityToken
@ Struct
Complex datatype with implements IRscSerializable
@ DateTime
Datetime, handled by Rsc with DateTime
@ Real64
64 bit floating point number
@ AnsiString
Ansi string, not implemented in Rsc context
@ Int32
signed 32 bit integer
@ IecTime
summary>IEC type: LTIME [int64]
@ Guid
Universal unique ID Uuid
@ Uint64
unsigned 64 bit integer
@ IecDate
summary>IEC type: LDATE [int64]
@ Stream
Stream type to marshal large data packets (see <see cref="RscStream")/>
@ SecureString
String for security context, handled by Rsc with SecureString
@ Utf16String
Utf-16 string, not implemented in Rsc context
@ Int64
signed 64 bit integer
Root namespace for the PLCnext API
Contains information to marshall an array
Definition: RscType.hpp:130
size_t Size
Count of array elements
Definition: RscType.hpp:142
size_t FieldCount
Count of Fields of struct element type
Definition: RscType.hpp:157
size_t Dimensions
Array Dimensions
Definition: RscType.hpp:147
RscType ElementType
Array element type
Definition: RscType.hpp:152
Contains information to marshall an struct
Definition: RscType.hpp:164
size_t FieldCount
Count of struct fields
Definition: RscType.hpp:170