PLCnext API Documentation  21.9.0.40
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 // forwards
12 namespace Arp { namespace System { namespace Security
13 {
14 class SecurityToken;
15 }}}
16 
17 namespace Arp { namespace System { namespace Rsc { namespace Services
18 {
19 
20 // usings
21 using SecurityToken = Arp::System::Security::SecurityToken;
22 
23 // forwards
24 template<int N>
25 class RscString;
26 template<int N>
28 class IRscSerializable;
29 class RscVersion;
30 class RscGuid;
31 
35 enum class RscType : uint8
36 {
38  None = 0xFF,
40  End = 0,
42  Null = 0,
44  Void = 1,
46  Bool = 2,
48  Char = 3,
50  Int8 = 4,
52  Uint8 = 5,
54  Int16 = 6,
56  Uint16 = 7,
58  Int32 = 8,
60  Uint32 = 9,
62  Int64 = 10,
64  Uint64 = 11,
66  Real32 = 12,
68  Real64 = 13,
70  Struct = 18,
73  String = 19,
75  Utf8String = 19,
77  Array = 20,
79  DateTime = 23,
81  Version = 24,
83  Guid = 25,
85  AnsiString = 26,
87  Object = 28,
89  Utf16String = 30,
91  Stream = 34,
93  Enumerator = 35,
95  SecureString = 36,
97  Enum = 37,
99  Dictionary = 38,
101  SecurityToken = 39,
103  Exception = 40,
105  IecTime = 41,
107  IecTime64 = 42,
110  IecDate = 43,
112  IecDate64 = 44,
115  IecDateTime = 45,
117  IecDateTime64 = 46,
120  IecTimeOfDay = 47,
122  IecTimeOfDay64 = 48,
123 };
124 
129 {
130  RscArrayInformation(void) = default;
131  RscArrayInformation(size_t size, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0)
132  : Size(size)
133  , ElementType(elementType)
134  , Dimensions(dimensions)
135  , FieldCount(fieldCount)
136  {}
137 
141  size_t Size = 0;
142 
146  size_t Dimensions = 1;
147 
151  RscType ElementType = RscType::None;
152 
156  size_t FieldCount = 0;
157 };
158 
163 {
164  RscStructInformation(size_t fieldCount) : FieldCount(fieldCount) {}
165 
169  size_t FieldCount = 0;
170 };
171 
172 // global function GetRscType to determine RscType value by type
174 template<class T, bool isSerializable = std::is_base_of<IRscSerializable, T>::value>
175 struct StructInfo
176 {
177  size_t FieldCount = 0;
178 };
179 
180 template<class T>
181 struct StructInfo<T, true>
182 {
183  size_t FieldCount = T::GetFieldCount();
184 };
185 
186 template<class T>
187 inline constexpr RscType GetRscType(void)
188 {
189  // REMARK: constexpr might only have a single return statement
190  return std::is_enum<T>::value ? GetRscType<typename underlying_enum_type<T>::type>() :
191  (
192  std::is_class<T>::value ? RscType::Struct :
193  (
194  std::is_array<T>::value ? RscType::Array : RscType::None
195  )
196  );
197 }
198 
199 template<>
200 inline constexpr RscType GetRscType<boolean>(void)
201 {
202  return RscType::Bool;
203 }
204 
205 template<>
206 inline constexpr RscType GetRscType<char8>(void)
207 {
208  return RscType::Uint8;
209 }
210 
211 template<>
212 inline constexpr RscType GetRscType<uint8>(void)
213 {
214  return RscType::Uint8;
215 }
216 
217 template<>
218 inline constexpr RscType GetRscType<int8>(void)
219 {
220  return RscType::Int8;
221 }
222 
223 template<>
224 inline constexpr RscType GetRscType<uint16>(void)
225 {
226  return RscType::Uint16;
227 }
228 
229 template<>
230 inline constexpr RscType GetRscType<int16>(void)
231 {
232  return RscType::Int16;
233 }
234 
235 template<>
236 inline constexpr RscType GetRscType<uint32>(void)
237 {
238  return RscType::Uint32;
239 }
240 
241 template<>
242 inline constexpr RscType GetRscType<int32>(void)
243 {
244  return RscType::Int32;
245 }
246 
247 template<>
248 inline constexpr RscType GetRscType<uint64>(void)
249 {
250  return RscType::Uint64;
251 }
252 
253 template<>
254 inline constexpr RscType GetRscType<int64>(void)
255 {
256  return RscType::Int64;
257 }
258 
259 template<>
260 inline constexpr RscType GetRscType<float32>(void)
261 {
262  return RscType::Real32;
263 }
264 
265 template<>
266 inline constexpr RscType GetRscType<float64>(void)
267 {
268  return RscType::Real64;
269 }
270 
271 template<>
272 inline constexpr RscType GetRscType<char*>(void)
273 {
274  return RscType::Utf8String;
275 }
276 
277 //template<>
278 //inline constexpr RscType GetRscType<IecString>(void) { return RscType::Utf8String; }
279 //
280 //template<>
281 //inline RscType GetRscType<StaticString<>>(void) { return RscType::Utf8String; }
282 
283 template<>
284 inline constexpr RscType GetRscType<String>(void)
285 {
286  return RscType::Utf8String;
287 }
288 
289 template<>
290 inline constexpr RscType GetRscType<DateTime>(void)
291 {
292  return RscType::DateTime;
293 }
294 
295 template<>
296 inline constexpr RscType GetRscType<RscVersion>(void)
297 {
298  return RscType::Version;
299 }
300 
301 template<>
302 inline constexpr RscType GetRscType<RscGuid>(void)
303 {
304  return RscType::Guid;
305 }
306 
307 template<>
308 inline constexpr RscType GetRscType<SecurityToken>(void)
309 {
310  return RscType::SecurityToken;
311 }
312 
313 template<class T>
314 inline constexpr RscType GetRscTypeFrom(const T& /*value*/)
315 {
316  return GetRscType<T>();
317 }
318 
319 template<int N>
320 inline constexpr RscType GetRscTypeFrom(const char(&)[N])
321 {
322  return RscType::Utf8String;
323 }
324 
325 template<int N>
326 inline constexpr RscType GetRscTypeFrom(const RscString<N>&)
327 {
328  return RscType::Utf8String;
329 }
330 
331 template<int N>
332 inline constexpr RscType GetRscTypeFrom(const SecureString<N>&)
333 {
334  return RscType::SecureString;
335 }
336 
337 template<>
338 inline constexpr RscType GetRscTypeFrom(const String&)
339 {
340  return RscType::Utf8String;
341 }
342 
343 template<>
344 inline constexpr RscType GetRscTypeFrom(const DateTime&)
345 {
346  return RscType::DateTime;
347 }
348 
349 template<>
350 inline constexpr RscType GetRscTypeFrom(const RscVersion&)
351 {
352  return RscType::Version;
353 }
354 
355 template<>
356 inline constexpr RscType GetRscTypeFrom(const RscGuid&)
357 {
358  return RscType::Guid;
359 }
360 
361 template<>
362 inline constexpr RscType GetRscTypeFrom(const SecurityToken&)
363 {
364  return RscType::SecurityToken;
365 }
366 
367 inline constexpr bool IsPrimitiveRscType(RscType type)
368 {
369  return (type >= RscType::Bool && type <= RscType::Real64) || (type >= RscType::IecTime && type <= RscType::IecTimeOfDay64);
370 }
371 
372 inline std::ostream& operator<<(std::ostream& os, const RscType rhs)
373 {
374  os << Enum<RscType>(rhs);
375  return os;
376 }
377 
378 }}}} // end of namespace Arp::System::Rsc::Services
Definition: RscGuid.hpp:17
Definition: SecurityToken.hpp:11
Utf-16 string, not implemented in Rsc context
std::ostream & operator<<(std::ostream &os, const BasicString< CharType, Alloc > &right)
Streams the right string to the outstream os .
Definition: BasicString.hxx:1559
The class contains date and time informations.
Definition: DateTime.hpp:44
Definition: BasicFormatter.hxx:18
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:35
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:27
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:128
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
Contains information to marshall an struct
Definition: RscType.hpp:162
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