PLCnext API Documentation  21.0.0.35466
RscType.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Enum.hxx"
8 #include "Arp/System/Core/TypeDeduction.hxx"
9 #include <type_traits>
10 
11 namespace Arp { namespace System { namespace Rsc { namespace Services
12 {
13 
14 // forwards
15 template<int N>
16 class RscString;
17 template<int N>
19 class RscSecurityToken;
20 class IRscSerializable;
21 class RscVersion;
22 class RscGuid;
23 
27 enum class RscType : uint8
28 {
30  None = 0xFF,
32  End = 0,
34  Null = 0,
36  Void = 1,
38  Bool = 2,
40  Char = 3,
42  Int8 = 4,
44  Uint8 = 5,
46  Int16 = 6,
48  Uint16 = 7,
50  Int32 = 8,
52  Uint32 = 9,
54  Int64 = 10,
56  Uint64 = 11,
58  Real32 = 12,
60  Real64 = 13,
62  Struct = 18,
65  String = 19,
67  Utf8String = 19,
69  Array = 20,
71  DateTime = 23,
73  Version = 24,
75  Guid = 25,
77  AnsiString = 26,
79  Object = 28,
81  Utf16String = 30,
83  Stream = 34,
85  Enumerator = 35,
87  SecureString = 36,
89  Enum = 37,
91  Dictionary = 38,
93  SecurityToken = 39,
95  Exception = 40,
97  IecTime = 41,
99  IecTime64 = 42,
102  IecDate = 43,
104  IecDate64 = 44,
107  IecDateTime = 45,
109  IecDateTime64 = 46,
112  IecTimeOfDay = 47,
114  IecTimeOfDay64 = 48,
115 };
116 
121 {
122  RscArrayInformation(void) = default;
123  RscArrayInformation(size_t size, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0)
124  : Size(size)
125  , ElementType(elementType)
126  , Dimensions(dimensions)
127  , FieldCount(fieldCount)
128  {}
129 
133  size_t Size = 0;
134 
138  size_t Dimensions = 1;
139 
143  RscType ElementType = RscType::None;
144 
148  size_t FieldCount = 0;
149 };
150 
155 {
156  RscStructInformation(size_t fieldCount) : FieldCount(fieldCount) {}
157 
161  size_t FieldCount = 0;
162 };
163 
164 // global function GetRscType to determine RscType value by type
166 template<class T, bool isSerializable = std::is_base_of<IRscSerializable, T>::value>
167 struct StructInfo
168 {
169  size_t FieldCount = 0;
170 };
171 
172 template<class T>
173 struct StructInfo<T, true>
174 {
175  size_t FieldCount = T::GetFieldCount();
176 };
177 
178 template<class T>
179 inline constexpr RscType GetRscType(void)
180 {
181  // REMARK: constexpr might only have a single return statement
182  return std::is_enum<T>::value ? GetRscType<typename underlying_enum_type<T>::type>() :
183  (
184  std::is_class<T>::value ? RscType::Struct :
185  (
186  std::is_array<T>::value ? RscType::Array : RscType::None
187  )
188  );
189 }
190 
191 template<>
192 inline constexpr RscType GetRscType<boolean>(void)
193 {
194  return RscType::Bool;
195 }
196 
197 template<>
198 inline constexpr RscType GetRscType<char8>(void)
199 {
200  return RscType::Uint8;
201 }
202 
203 template<>
204 inline constexpr RscType GetRscType<uint8>(void)
205 {
206  return RscType::Uint8;
207 }
208 
209 template<>
210 inline constexpr RscType GetRscType<int8>(void)
211 {
212  return RscType::Int8;
213 }
214 
215 template<>
216 inline constexpr RscType GetRscType<uint16>(void)
217 {
218  return RscType::Uint16;
219 }
220 
221 template<>
222 inline constexpr RscType GetRscType<int16>(void)
223 {
224  return RscType::Int16;
225 }
226 
227 template<>
228 inline constexpr RscType GetRscType<uint32>(void)
229 {
230  return RscType::Uint32;
231 }
232 
233 template<>
234 inline constexpr RscType GetRscType<int32>(void)
235 {
236  return RscType::Int32;
237 }
238 
239 template<>
240 inline constexpr RscType GetRscType<uint64>(void)
241 {
242  return RscType::Uint64;
243 }
244 
245 template<>
246 inline constexpr RscType GetRscType<int64>(void)
247 {
248  return RscType::Int64;
249 }
250 
251 template<>
252 inline constexpr RscType GetRscType<float32>(void)
253 {
254  return RscType::Real32;
255 }
256 
257 template<>
258 inline constexpr RscType GetRscType<float64>(void)
259 {
260  return RscType::Real64;
261 }
262 
263 template<>
264 inline constexpr RscType GetRscType<char*>(void)
265 {
266  return RscType::Utf8String;
267 }
268 
269 //template<>
270 //inline constexpr RscType GetRscType<IecString>(void) { return RscType::Utf8String; }
271 //
272 //template<>
273 //inline RscType GetRscType<StaticString<>>(void) { return RscType::Utf8String; }
274 
275 template<>
276 inline constexpr RscType GetRscType<String>(void)
277 {
278  return RscType::Utf8String;
279 }
280 
281 template<>
282 inline constexpr RscType GetRscType<DateTime>(void)
283 {
284  return RscType::DateTime;
285 }
286 
287 template<>
288 inline constexpr RscType GetRscType<RscVersion>(void)
289 {
290  return RscType::Version;
291 }
292 
293 template<>
294 inline constexpr RscType GetRscType<RscGuid>(void)
295 {
296  return RscType::Guid;
297 }
298 
299 template<>
300 inline constexpr RscType GetRscType<RscSecurityToken>(void)
301 {
302  return RscType::SecurityToken;
303 }
304 
305 template<class T>
306 inline constexpr RscType GetRscTypeFrom(const T& /*value*/)
307 {
308  return GetRscType<T>();
309 }
310 
311 template<int N>
312 inline constexpr RscType GetRscTypeFrom(const char(&)[N])
313 {
314  return RscType::Utf8String;
315 }
316 
317 template<int N>
318 inline constexpr RscType GetRscTypeFrom(const RscString<N>&)
319 {
320  return RscType::Utf8String;
321 }
322 
323 template<int N>
324 inline constexpr RscType GetRscTypeFrom(const SecureString<N>&)
325 {
326  return RscType::SecureString;
327 }
328 
329 template<>
330 inline constexpr RscType GetRscTypeFrom(const String&)
331 {
332  return RscType::Utf8String;
333 }
334 
335 template<>
336 inline constexpr RscType GetRscTypeFrom(const DateTime&)
337 {
338  return RscType::DateTime;
339 }
340 
341 template<>
342 inline constexpr RscType GetRscTypeFrom(const RscVersion&)
343 {
344  return RscType::Version;
345 }
346 
347 template<>
348 inline constexpr RscType GetRscTypeFrom(const RscGuid&)
349 {
350  return RscType::Guid;
351 }
352 
353 template<>
354 inline constexpr RscType GetRscTypeFrom(const RscSecurityToken&)
355 {
356  return RscType::SecurityToken;
357 }
358 
359 inline constexpr bool IsPrimitiveRscType(RscType type)
360 {
361  return (type >= RscType::Bool && type <= RscType::Real64) || (type >= RscType::IecTime && type <= RscType::IecTimeOfDay64);
362 }
363 
364 inline std::ostream& operator<<(std::ostream& os, const RscType rhs)
365 {
366  os << Enum<RscType>(rhs);
367  return os;
368 }
369 
370 }}}} // end of namespace Arp::System::Rsc::Services
Definition: RscGuid.hpp:17
summary>IEC type: LDATE_AND_TIME, LDT [int64]
Complex datatype with implements IRscSerializable
summary>IEC type: LDATE [int64]
Definition: SecurityToken.hpp:11
Utf-16 string, not implemented in Rsc context
summary>IEC type: LTIME [int64]
The class contains date and time informations.
Definition: DateTime.hpp:44
String for security context, handled by Rsc with SecureString
Adapter class for enums to make them loggable and parsable from e.g. XML files.
Definition: Enum.hxx:23
RscType
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType. Only supported types of RemotingMarshalType are included.
Definition: RscType.hpp:27
This class represents the version of a special SDK or Arp build.
Definition: BasicVersion.hpp:34
Object type handled by Rsc as RscVariant
Specifies a version with 4 version numbers and is marshalled to .NET type System.Version.
Definition: RscVersion.hpp:20
Security token needed for security services, handly by Rsc with SecurityToken
Marshalls structure or class data types. Serialize and Deserialize have to marshal fields in the same...
Definition: IRscSerializable.hpp:18
Ansi string, not implemented in Rsc context
Specialized version of RscString for security context. Not implemented in this version. Wraps only RscString
Definition: RscType.hpp:18
std::uint8_t uint8
The Arp unsigned integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:27
Root namespace for the PLCnext API
Contains information to marshall an array
Definition: RscType.hpp:120
Datetime, handled by Rsc with DateTime
System components used by the System, Device, Plc or Io domains.
Stream type to marshal large data packets (see <see cref="RscStream")/>
This is the base class of all Arp exception classes.
Definition: Exception.hpp:15
summary>IEC type: LTIME_OF_DAY, LTOD [int64]
Contains information to marshall an struct
Definition: RscType.hpp:154
Contains a static string with string lentgh up to N characters. The string has to be null terminated...
Definition: RscString.hxx:18
This class defines a base class for all enumerator implementations and some predefined enumerators as...
Definition: Enumerator.hxx:21