PLCnext API Documentation  22.9.0.33
RscVariant.hxx
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Commons/Exceptions/Exceptions.h"
8 #include "Arp/System/Commons/Encoding/Utf16.hpp"
9 #include "Arp/System/Rsc/Services/Rsc.h"
10 #include "Arp/System/Rsc/Services/RscGuid.hpp"
11 #include "Arp/System/Rsc/Services/RscVersion.hpp"
12 #include "Arp/System/Rsc/Services/RscString.hxx"
13 #include "Arp/System/Rsc/Services/SecureString.hxx"
14 #include <cstring>
15 #include <cstddef>
16 #include <sstream>
17 #include <iomanip>
18 
19 namespace Arp { namespace System { namespace Rsc { namespace Services
20 {
21 
22 // forwards
23 class RscArrayReader;
24 class RscArrayWriter;
25 class RemotingReader;
26 class RemotingWriter;
27 template<int N> class RscStructReader;
28 template<int N> class RscStructWriter;
29 template<class T, bool IsClass, bool IsSerializable> class RscValueAdapter;
30 
37 template<int MaxStringSize = 0>
39 {
40 public: // typedefs/friends
41  friend class RscArrayReader;
42  friend class RscArrayWriter;
43  template<int N> friend class RscStructReader;
44  template<int N> friend class RscStructWriter;
45  template<class T, bool IsClass, bool IsSerializable> friend class RscValueAdapter;
46  template<int N> friend class SecureString;
47 
48  using ReadElementFunction = std::function<RscType(RscType expectedType, byte* pValue)>;
49  using WriteElementFunction = std::function<void(RscType valueType, const byte* pValue)>;
51 
52 public: // construction/destruction
58 
62  template <class T>
63  RscVariant(const T& value);
64 
69  RscVariant(const String& value);
70 
75  RscVariant(const char* value);
76 
82  RscVariant(const char16* input, size_t length, RscType type = RscType::Utf8String);
83 
88  template<int N>
89  RscVariant(const RscString<N>& value);
90 
95  template<int N>
96  RscVariant(const SecureString<N>& value);
97 
106  RscVariant(size_t arraySize, RscType arrayElementType, size_t dimensions = 1, size_t fieldCount = 0);
107 
117  RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction* pFunction, size_t dimensions = 1, size_t fieldCount = 0);
118 
128  RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction* pFunction, size_t dimensions = 1, size_t fieldCount = 0);
129 
133  RscVariant(size_t fieldCount, ReadElementFunction* pFunction);
134 
139 
143  RscVariant(RscVariant&&)noexcept = default;
144 
145 public: // Static factory operations
151  static RscVariant<MaxStringSize> CreateStructVariant(size_t fieldCount);
152 
161  static RscVariant<MaxStringSize> CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0);
162 
163 private: // static factory operations
164  static RscVariant<MaxStringSize> CreateStructVariant(size_t fieldCount, RemotingWriter& writer);
165  static RscVariant<MaxStringSize> CreateArrayVariant(size_t arraySize, RscType elementType, RemotingWriter& writer, size_t dimensions = 1, size_t fieldCount = 0);
166 
167 public: // operators
168  template <class T>
169  RscVariant& operator=(const T& value);
170  RscVariant& operator=(const String& value);
171  RscVariant& operator=(const char* value);
172  template<int N>
173  RscVariant& operator=(const RscString<N>& value);
174  template<int N>
175  RscVariant& operator=(const SecureString<N>& value);
176  RscVariant& operator=(const RscVariant& value) = default;
177  RscVariant& operator=(RscVariant&&)noexcept = default;
178  bool operator==(const RscVariant& value)const;
179  bool operator!=(const RscVariant& value)const;
180 
181 public: // getter/setter
186  RscType GetType(void)const;
187 
192  RscType GetValueType(void)const;
193 
200 
206  size_t GetArrayDimensions(void)const;
207 
213  size_t GetFieldCount(void) const;
214 
219  const char* GetChars(void)const;
220 
226  void SetWriteElementFunction(WriteElementFunction* pFunction) const;
227 
232  const byte* GetDataAddress(void)const;
233 
238  byte* GetDataAddress(void);
239 
244  void SetType(RscType rscType);
245 
246 public: // operations
251  template<class T>
252  T GetValue(void)const;
253 
258  template<class T>
259  void CopyTo(T& value)const;
260 
265  String ToString(void)const;
266 
272  void Assign(const char16 * input, size_t length, RscType rscType = RscType::Utf8String);
273 
274 private: // Setter/Getter for internal use and friend classes
275  RscArrayInformation& GetArrayInformation(void);
276  const RscArrayInformation& GetArrayInformation(void) const;
277  RscStructInformation& GetStructInformation(void);
278  const RscStructInformation& GetStructInformation(void) const;
279 
280 private: // methods
281  void Assign(const char* input, size_t length, RscType rscType = RscType::Utf8String);
282  void InitComplexTypeInfo(void);
283  bool ContainsTypeInformation(void) const;
284  size_t GetSize(void)const;
285 
286 private: // nested types
287  struct ComplexTypeInfo
288  {
289  union
290  {
291  RscArrayInformation arrayInformation;
292  RscStructInformation structInformation;
293  };
294  RemotingReader* pReader = nullptr;
295  mutable RemotingWriter* pWriter = nullptr;
296  ReadElementFunction* pReadElementFunction = nullptr;
297  mutable WriteElementFunction* pWriteElementFunction = nullptr;
298  };
299 
300 private: // static fields
301  static const size_t maxPrimitiveSize = 8;
302 #ifdef ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
303  static const size_t minBufferSize = std::max(maxPrimitiveSize, std::max(sizeof(RscGuid), sizeof(RscVersion)));
304 #else
305  static const size_t minBufferSize = maxPrimitiveSize;
306 #endif // ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
307 
308  static const size_t bufferSize = minBufferSize < (size_t)MaxStringSize ? (size_t)MaxStringSize : minBufferSize;
309 
310 private: // fields
311  union
312  {
313  ComplexTypeInfo typeInfo;
314  byte buffer[bufferSize];
315  };
316  RscType type = RscType::None;
317 };
318 
319 
321 // inline methods of RscType helper
322 template<int N>
323 inline constexpr RscType GetRscTypeFrom(const RscVariant<N>& /*value*/)
324 {
325  return RscType::Object;
326 }
327 
329 // inline methods of class RscVariant
330 
331 template<int MaxStringSize>
333  : type(typeArg)
334 {
335 }
336 
337 template<int MaxStringSize>
338 template<class T>
340 {
341  this->operator=(value);
342 }
343 
344 template<int MaxStringSize>
346  : type(RscType::Utf8String)
347 {
348  this->operator=(value);
349 }
350 
351 template<int MaxStringSize>
352 inline RscVariant<MaxStringSize>::RscVariant(const char* value)
353 {
354  this->operator=(value);
355 }
356 
357 template<int MaxStringSize>
358 inline RscVariant<MaxStringSize>::RscVariant(const char16* input, size_t length, RscType type)
359 {
360  this->Assign(input, length, type);
361 }
362 
363 template<int MaxStringSize>
364 template<int N>
366 {
367  this->operator=(value);
368 }
369 
370 template<int MaxStringSize>
371 template<int N>
373 {
374  this->operator=(value);
375 }
376 
377 template<int MaxStringSize>
378 inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, size_t dimensions, size_t fieldCount)
379  : type(RscType::Array)
380 {
381  if(arrayElementType == RscType::Struct && fieldCount == 0)
382  {
383  throw ArgumentException::Create("fieldCount", fieldCount, "fieldCount has to be set for struct element types");
384  }
385  this->GetArrayInformation() = RscArrayInformation(arraySize, arrayElementType, dimensions, fieldCount);
386  this->typeInfo.pReader = nullptr;
387  this->typeInfo.pWriter = nullptr;
388  this->typeInfo.pReadElementFunction = nullptr;
389  this->typeInfo.pWriteElementFunction = nullptr;
390 }
391 
392 template<int MaxStringSize>
393 inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction* pFunction, size_t dimensions, size_t fieldCount)
394  : type(RscType::Array)
395 {
396  if(arrayElementType == RscType::Struct && fieldCount == 0)
397  {
398  throw ArgumentException::Create("fieldCount", fieldCount, "fieldCount has to be set for struct element types");
399  }
400  this->GetArrayInformation() = RscArrayInformation(arraySize, arrayElementType, dimensions, fieldCount);
401  this->typeInfo.pReader = nullptr;
402  this->typeInfo.pWriter = nullptr;
403  this->typeInfo.pReadElementFunction = pFunction;
404  this->typeInfo.pWriteElementFunction = nullptr;
405 }
406 
407 template<int MaxStringSize>
408 inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction* pFunction, size_t dimensions, size_t fieldCount)
409  : type(RscType::Array)
410 {
411  if(arrayElementType == RscType::Struct && fieldCount == 0)
412  {
413  throw ArgumentException::Create("fieldCount", fieldCount, "fieldCount has to be set for struct element types");
414  }
415  this->GetArrayInformation() = RscArrayInformation(arraySize, arrayElementType, dimensions, fieldCount);
416  this->typeInfo.pReader = nullptr;
417  this->typeInfo.pWriter = nullptr;
418  this->typeInfo.pReadElementFunction = nullptr;
419  this->typeInfo.pWriteElementFunction = pFunction;
420 }
421 
422 template<int MaxStringSize>
423 inline RscVariant<MaxStringSize>::RscVariant(size_t fieldCount, ReadElementFunction* pFunction)
424  : type(RscType::Struct)
425 {
426  this->InitComplexTypeInfo();
427  this->GetStructInformation() = RscStructInformation(fieldCount);
428  this->typeInfo.pReadElementFunction = pFunction;
429 }
430 
431 template<int MaxStringSize>
433 {
434  return this->type;
435 }
436 
437 template<int MaxStringSize>
439 {
440  switch (this->type)
441  {
442  case RscType::IecTime:
443  return RscType::Int32;
444  case RscType::IecTime64:
445  case RscType::IecDate64:
447  case RscType::IecTimeOfDay64:
448  return RscType::Int64;
449  default:
450  // no mapping
451  return this->type;
452  }
453 }
454 
455 template<int MaxStringSize>
457 {
458  return this->GetArrayInformation().ElementType;
459 }
460 
461 template<int MaxStringSize>
463 {
464  if(this->GetType() != RscType::Array)
465  {
466  throw InvalidOperationException("RscVariant doesn't contain array information");
467  }
468  return this->typeInfo.arrayInformation;
469 }
470 
471 template<int MaxStringSize>
473 {
474  if(this->GetType() != RscType::Array)
475  {
476  throw InvalidOperationException("RscVariant doesn't contain array information");
477  }
478  return this->typeInfo.arrayInformation;
479 }
480 
481 template<int MaxStringSize>
482 inline const RscStructInformation& RscVariant<MaxStringSize>::GetStructInformation(void) const
483 {
484  if(this->GetType() != RscType::Struct)
485  {
486  throw InvalidOperationException("RscVariant doesn't contain struct information");
487  }
488  return this->typeInfo.structInformation;
489 }
490 
491 template<int MaxStringSize>
492 inline RscStructInformation& RscVariant<MaxStringSize>::GetStructInformation(void)
493 {
494  if(this->GetType() != RscType::Struct)
495  {
496  throw InvalidOperationException("RscVariant doesn't contain struct information");
497  }
498  return this->typeInfo.structInformation;
499 }
500 
501 template<int MaxStringSize>
503 {
504  return this->GetArrayInformation().Dimensions;
505 }
506 
507 template<int MaxStringSize>
509 {
510  return this->GetStructInformation().FieldCount;
511 }
512 
513 template<int MaxStringSize>
515 {
516  return this->buffer;
517 }
518 
519 template<int MaxStringSize>
520 inline const byte* RscVariant<MaxStringSize>::GetDataAddress()const
521 {
522  return this->buffer;
523 }
524 
525 template<int MaxStringSize>
527 {
528  this->type = rscType;
529 }
530 
531 template<int MaxStringSize>
533 {
534  return (this->type == RscType::Struct || this->type == RscType::Array);
535 }
536 
537 template<int MaxStringSize>
538 template<class T>
540 {
541  this->type = GetRscType<T>();
542  if(this->type == RscType::None)
543  {
544  throw NotSupportedException("Cannot assign from argument: Type of argument is not supported");
545  }
546 #ifndef ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
547  if (this->type == RscType::Version || this->type == RscType::Guid)
548  {
549  throw NotImplementedException("Type RscVersion and RscGuid are currently not supported by RscVariant");
550  }
551 #endif // ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
552  *reinterpret_cast<T*>(this->buffer) = value;
553  return *this;
554 }
555 
556 template<int MaxStringSize>
558 {
560  result.InitComplexTypeInfo();
561  result.GetStructInformation().FieldCount = fieldCount;
562  return result;
563 }
564 
565 template<int MaxStringSize>
566 inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions, size_t fieldCount)
567 {
568  RscVariant<MaxStringSize> result(arraySize, elementType, dimensions, fieldCount);
569  return result;
570 }
571 
572 template<int MaxStringSize>
573 inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateStructVariant(size_t fieldCount, RemotingWriter& writer)
574 {
576  result.typeInfo.pWriter = &writer;
577  return result;
578 }
579 
580 template<int MaxStringSize>
581 inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateArrayVariant(size_t arraySize, RscType elementType, RemotingWriter& writer, size_t dimensions, size_t fieldCount)
582 {
583  RscVariant<MaxStringSize> result(arraySize, elementType, dimensions, fieldCount);
584  result.typeInfo.pWriter = &writer;
585  return result;
586 }
587 
588 template<int MaxStringSize>
590 {
591  size_t len = value.Length();
592  this->Assign(value.CStr(), len);
593  return *this;
594 }
595 
596 template<int MaxStringSize>
598 {
599  size_t len = strlen(value);
600  this->Assign(value, len);
601  return *this;
602 }
603 
604 template<int MaxStringSize>
605 template<int N>
606 inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const RscString<N>& value)
607 {
608  this->Assign(value.CStr(), SecureStrnlen(value.CStr(), N), RscType::Utf8String);
609  return *this;
610 }
611 
612 template<int MaxStringSize>
613 template<int N>
614 inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const SecureString<N>& value)
615 {
616  this->Assign(value.CStr(), strlen(value.CStr()), RscType::SecureString);
617  return *this;
618 }
619 
620 template<int MaxStringSize>
621 inline void RscVariant<MaxStringSize>::Assign(const char* input, size_t length, RscType rscType)
622 {
623  if (length >= MaxStringSize)
624  {
625  throw ArgumentException("Cannot copy string: argument string length {} exceeds MaxStringSize {}", length, MaxStringSize);
626  }
627  if (rscType != RscType::Utf8String && rscType != RscType::SecureString)
628  {
629  throw NotSupportedException("RscType '{}' not supported for Strings", rscType);
630  }
631  SecureStrncpy(reinterpret_cast<char*>(this->buffer), MaxStringSize, input, length);
632  this->buffer[length] = '\0';
633  this->type = rscType;
634 }
635 
636 template<int MaxStringSize>
637 inline void RscVariant<MaxStringSize>::Assign(const char16* input, size_t length, RscType rscType)
638 {
641 
642  if (rscType != RscType::Utf8String)
643  {
644  throw NotSupportedException("RscType '{}' not supported for UTF16 strings", rscType);
645  }
646  this->type = rscType;
647  size_t resultLength = 0;
648  EncodingResult result = Utf16::ConvertToUtf8(input, length, reinterpret_cast<char8*>(this->buffer), MaxStringSize, resultLength);
649  if ((result != EncodingResult::Success) && (result != EncodingResult::NoConversion))
650  {
651  throw ArgumentException("Cannot convert UTF16 string, encoding result = {}", result);
652  }
653  this->buffer[resultLength] = '\0';
654 }
655 
656 template<int MaxStringSize>
657 inline bool RscVariant<MaxStringSize>::operator==(const RscVariant& value)const
658 {
659  if (this->GetType() != value.GetType())
660  {
661  return false;
662  }
663 
664  if (this->GetSize() != value.GetSize())
665  {
666  return false;
667  }
668 
669  if (memcmp(this->buffer, value.buffer, this->GetSize()) != 0)
670  {
671  return false;
672  }
673 
674  if (this->GetType() == RscType::Utf8String)
675  {
676  if (strcmp((char*)this->buffer, (char*)value.buffer) != 0)
677  {
678  return false;
679  }
680  }
681 
682  return true;
683 }
684 
685 template<int MaxStringSize>
686 inline bool RscVariant<MaxStringSize>::operator!=(const RscVariant& value)const
687 {
688  return !(*this == value);
689 }
690 
691 template<int MaxStringSize>
692 inline void RscVariant<MaxStringSize>::InitComplexTypeInfo(void)
693 {
694  // needed, because elements of union are not initialized
695  this->typeInfo.pReader = nullptr;
696  this->typeInfo.pWriter = nullptr;
697  this->typeInfo.pReadElementFunction = nullptr;
698  this->typeInfo.pWriteElementFunction = nullptr;
699 }
700 
701 template<int MaxStringSize>
702 template<class T>
703 inline void RscVariant<MaxStringSize>::CopyTo(T& value) const
704 {
705  RscType argType = GetRscType<T>();
706  if(this->GetValueType() != argType)
707  {
708  throw InvalidCastException("Cannot copy value to argument: RscVariant contains data type {0} but arg is of type {1}", this->type, argType);
709  }
710  value = *reinterpret_cast<const T*>(this->buffer);
711 }
712 
713 template<int MaxStringSize>
714 inline const char* RscVariant<MaxStringSize>::GetChars() const
715 {
716  if (this->type != RscType::Utf8String && this->type != RscType::SecureString && this->type != RscType::AnsiString)
717  {
718  throw InvalidCastException("Cannot convert to string: RscVariant is of type {0}", this->type);
719  }
720  return reinterpret_cast<const char*>(this->buffer);
721 }
722 
723 template<int MaxStringSize>
724 inline void RscVariant<MaxStringSize>::SetWriteElementFunction(WriteElementFunction * pFunction) const
725 {
726  if(this->type != RscType::Array && this->type != RscType::Struct)
727  {
728  throw InvalidOperationException("Method only allowed for array and struct objects");
729  }
730  this->typeInfo.pWriteElementFunction = pFunction;
731 }
732 
733 template<int MaxStringSize>
734 template<class T>
736 {
737  T result;
738  this->CopyTo(result);
739  return result;
740 }
741 
742 template<int MaxStringSize>
744 {
745  const byte* pValue = this->GetDataAddress();
746 
747  switch (this->type)
748  {
750  case RscType::AnsiString:
751  case RscType::Utf8String:
752  return reinterpret_cast<const char*>(pValue);
753  case RscType::DateTime:
754  return reinterpret_cast<const DateTime*>(pValue)->ToIso8601String();
755  case RscType::Bool:
756  {
757  std::ostringstream oss;
758  oss << std::boolalpha << *reinterpret_cast<const bool*>(pValue);
759  if (oss.fail())
760  {
761  throw InvalidOperationException("Value of RscVariant is not of type bool.");
762  }
763  return oss.str();
764  }
765  case RscType::Char:
766  return std::to_string(*reinterpret_cast<const char16*>(pValue));
767  case RscType::Int16:
768  return std::to_string(*reinterpret_cast<const int16*>(pValue));
769  case RscType::Int32:
770  case RscType::IecTime:
771  return std::to_string(*reinterpret_cast<const int32*>(pValue));
772  case RscType::Int8:
773  return std::to_string(*reinterpret_cast<const int8*>(pValue));
774  case RscType::Int64:
775  case RscType::IecTime64:
776  case RscType::IecDate64:
778  case RscType::IecTimeOfDay64:
779  return std::to_string(*reinterpret_cast<const int64*>(pValue));
780  case RscType::None:
781  case RscType::Null:
782  return String::Empty;
783  case RscType::Real32:
784  return std::to_string(*reinterpret_cast<const float*>(pValue));
785  case RscType::Real64:
786  return std::to_string(*reinterpret_cast<const double*>(pValue));
787  case RscType::Uint16:
788  return std::to_string(*reinterpret_cast<const uint16*>(pValue));
789  case RscType::Uint32:
790  return std::to_string(*reinterpret_cast<const uint32*>(pValue));
791  case RscType::Uint64:
792  return std::to_string(*reinterpret_cast<const uint64*>(pValue));
793  case RscType::Uint8:
794  return std::to_string(*reinterpret_cast<const uint8*>(pValue));
795  case RscType::Version:
796  return reinterpret_cast<const RscVersion*>(pValue)->ToString();
797  case RscType::Guid:
798  return reinterpret_cast<const RscGuid*>(pValue)->ToString();
799  case RscType::Void:
800  return String::Empty;
801  default:
802  // case RscType::Array:
803  throw NotSupportedException("RscVariant::ToString() not supported for type '{0}'", type);
804  }
805 }
806 
807 template<int MaxStringSize>
808 inline size_t RscVariant<MaxStringSize>::GetSize(void)const
809 {
810  switch (this->GetValueType())
811  {
812  case RscType::Void:
813  return 0;
814  break;
815  case RscType::Bool:
816  case RscType::Int8:
817  case RscType::Uint8:
818  return 1;
819  break;
820  case RscType::Char:
821  case RscType::Int16:
822  case RscType::Uint16:
823  return 2;
824  break;
825  case RscType::Int32:
826  case RscType::Uint32:
827  case RscType::Real32:
828  case RscType::IecTime:
829  return 4;
830  break;
831  case RscType::Int64:
832  case RscType::Uint64:
833  case RscType::Real64:
834  case RscType::DateTime:
835  case RscType::IecTime64:
836  case RscType::IecDate64:
838  case RscType::IecTimeOfDay64:
839  return 8;
840  break;
841  case RscType::Utf8String:
842  return strlen((char*)this->buffer);
843  break;
844  case RscType::Array:
845  {
846  return sizeof(RscArrayInformation);
847  break;
848  }
849  case RscType::Struct:
850  {
851  return sizeof(RscStructInformation);
852  break;
853  }
855  default:
856  throw NotSupportedException("RscType {0} not supported.", this->GetValueType());
857  }
858 }
859 
860 }}}} // end of namespace Arp::System::Rsc::Services
861 
The class contains date and time informations.
Definition: DateTime.hpp:45
This exception is used when an invalid argument occurs.
Definition: ArgumentException.hpp:15
static ArgumentException Create(const char *paramName, const T &paramValue)
Creates an ArgumentException instance using a default message text.
Definition: ArgumentException.hpp:112
This is a small immutable wrapper around the boost::uuids::uuid class and represents a universal uniq...
Definition: Uuid.hpp:19
This static class provides encoding string operations from UTF8 to UTF16 or vice versa.
Definition: Utf16.hpp:15
This exception is used when an invalid cast occurs.
Definition: InvalidCastException.hpp:15
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
This exception is used when a method is not implemented yet.
Definition: NotImplementedException.hpp:15
This exception is used when a method is not supported.
Definition: NotSupportedException.hpp:15
Helper class to read an array of primtive types from an RscVariant. This class uses the array informa...
Definition: RscArrayReader.hpp:23
Helper class to read an array of primtive types from an RscVariant. This class uses the array informa...
Definition: RscArrayWriter.hpp:22
Definition: RscGuid.hpp:18
Contains a static string with string lentgh up to N characters. The string has to be null terminated.
Definition: RscString.hxx:21
Helper class to read a struct from an RscVariant. This class uses the struct information stored in Rs...
Definition: RscStructReader.hxx:25
Helper class to write a struct from an RscVariant. This class uses the struct information stored in R...
Definition: RscStructWriter.hxx:19
Rsc container class for primitive data type, strings or information about arrays or structs....
Definition: RscVariant.hxx:39
RscVariant(const T &value)
Creates a new instance of RscVariant with value. Gets RscType by type deduction of T.
Definition: RscVariant.hxx:339
void SetType(RscType rscType)
Forces the internal RscType to be set to another RscType. This Method does no conversion or validatio...
Definition: RscVariant.hxx:526
String ToString(void) const
Converts this instance to string if the variant type has a reasonable string representation.
Definition: RscVariant.hxx:743
RscVariant(const RscString< N > &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:365
size_t GetArrayDimensions(void) const
Gets the count of array dimensions (1 for simple array, 2 for array of array etc.)....
Definition: RscVariant.hxx:502
RscVariant(const SecureString< N > &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:372
void Assign(const char16 *input, size_t length, RscType rscType=RscType::Utf8String)
Assigns an UTF16 string to this instance.
Definition: RscVariant.hxx:637
RscVariant(RscType type=RscType::None)
Creates an empty instance of RscVariant
Definition: RscVariant.hxx:332
RscVariant(const RscVariant< MaxStringSize > &)=default
Copy constructor
RscVariant(const char *value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:352
T GetValue(void) const
Converts this value to the given type T.
Definition: RscVariant.hxx:735
size_t GetFieldCount(void) const
Returns field count, if RscVariant contains struct information
Definition: RscVariant.hxx:508
RscType GetValueType(void) const
Gets the value type as RscType of the contained element
Definition: RscVariant.hxx:438
const char * GetChars(void) const
Gets pointer to internal string buffer. Operation only valid for Utf8Strings.
Definition: RscVariant.hxx:714
static RscVariant< MaxStringSize > CreateStructVariant(size_t fieldCount)
Creates a new RscVariant initialized with RscStructInformation
Definition: RscVariant.hxx:557
RscVariant(const char16 *input, size_t length, RscType type=RscType::Utf8String)
Assigns an UTF16 string to this instance.
Definition: RscVariant.hxx:358
RscVariant(size_t fieldCount, ReadElementFunction *pFunction)
For internal use only
Definition: RscVariant.hxx:423
static RscVariant< MaxStringSize > CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions=1, size_t fieldCount=0)
Creates a new RscVariant initialized with RscArrayInformation
Definition: RscVariant.hxx:566
void SetWriteElementFunction(WriteElementFunction *pFunction) const
Sets callback for write function to write a single array element. This could only be used for Variant...
Definition: RscVariant.hxx:724
RscVariant(const String &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:345
const byte * GetDataAddress(void) const
Gets a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment...
Definition: RscVariant.hxx:514
RscType GetType(void) const
Gets the RscType of the contained element
Definition: RscVariant.hxx:432
RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction *pFunction, size_t dimensions=1, size_t fieldCount=0)
Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElem...
Definition: RscVariant.hxx:408
RscVariant(RscVariant &&) noexcept=default
Move constructor
RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction *pFunction, size_t dimensions=1, size_t fieldCount=0)
Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElem...
Definition: RscVariant.hxx:393
RscType GetArrayElementType(void) const
Gets the RscType of the array elements if RscVariant contains array information.
Definition: RscVariant.hxx:456
RscVariant(size_t arraySize, RscType arrayElementType, size_t dimensions=1, size_t fieldCount=0)
Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElem...
Definition: RscVariant.hxx:378
void CopyTo(T &value) const
Copies internal data to memory referenced by value. Only for primtive types. Read Strings with GetCha...
Definition: RscVariant.hxx:703
Specifies a version with 4 version numbers and is marshalled to .NET type System.Version.
Definition: RscVersion.hpp:21
Specialized version of RscString for security context. Not implemented in this version....
Definition: SecureString.hxx:19
const CharType * CStr() const
Gets the character data of this string.
Definition: BasicString.hxx:1508
size_type Length() const
Returns the number of char elements in this string.
Definition: BasicString.hxx:1039
bool operator!=(const BasicString< CharType, Alloc > &left, const BasicString< CharType, Alloc > &right)
Compares the left string to the right string on inequality.
Definition: BasicString.hxx:1912
static const SelfType Empty
An emtpy static string instance.
Definition: BasicString.hxx:214
bool operator==(const BasicString< CharType, Alloc > &left, const BasicString< CharType, Alloc > &right)
Compares the left string to the right string on equality.
Definition: BasicString.hxx:1876
std::uint8_t uint8
The Arp unsigned integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:27
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
std::int8_t int8
The Arp integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:29
char16_t char16
The Arp character type of 2 byte size.
Definition: PrimitiveTypes.hpp:49
std::uint64_t uint64
The Arp unsigned integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:39
char char8
The Arp character type of 1 byte size.
Definition: PrimitiveTypes.hpp:47
std::int64_t int64
The Arp integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:41
std::int16_t int16
The Arp integer type of 2 byte size.
Definition: PrimitiveTypes.hpp:33
std::int32_t int32
The Arp integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:37
std::uint16_t uint16
The Arp unsigned integer type of 2 byte size.
Definition: PrimitiveTypes.hpp:31
@ System
System components used by the System, Device, Plc or Io domains.
EncodingResult
This enum defines encoding results for operations of class Utf16.
Definition: EncodingResult.hpp:16
RscType
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
@ 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
@ Object
Object type handled by Rsc as RscVariant
@ 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
@ SecureString
String for security context, handled by Rsc with SecureString
@ Int64
signed 64 bit integer
Root namespace for the PLCnext API
size_t SecureStrnlen(const char *str, size_t maxSize)
Warpper for strnlen_s
void SecureStrncpy(char *dest, size_t destMaxSize, const char *src, size_t count)
Wrapper for strncpy_s
Contains information to marshall an array
Definition: RscType.hpp:130
Contains information to marshall an struct
Definition: RscType.hpp:164
size_t FieldCount
Count of struct fields
Definition: RscType.hpp:170