PLCnext API Documentation 23.6.0.37
RscVariant.hxx
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Exceptions/Exceptions.h"
9#include "Arp/System/Commons/Encoding/Utf16.hpp"
10#include "Arp/System/Rsc/Services/Rsc.h"
11#include "Arp/System/Rsc/Services/RscGuid.hpp"
12#include "Arp/System/Rsc/Services/RscVersion.hpp"
13#include "Arp/System/Rsc/Services/RscString.hxx"
14#include "Arp/System/Rsc/Services/SecureString.hxx"
15#include <cstring>
16#include <cstddef>
17#include <sstream>
18#include <iomanip>
19
20namespace Arp { namespace System { namespace Rsc { namespace Services
21{
22
23// forwards
24class RscArrayReader;
25class RscArrayWriter;
26class RemotingReader;
27class RemotingWriter;
28template<int N> class RscStructReader;
29template<int N> class RscStructWriter;
30template<class T, bool IsClass, bool IsSerializable> class RscValueAdapter;
31
67template<int MaxStringSize = 0>
69{
70public: // typedefs/friends
71 friend class RscArrayReader;
72 friend class RscArrayWriter;
73 template<int N> friend class RscStructReader;
74 template<int N> friend class RscStructWriter;
75 template<class T, bool IsClass, bool IsSerializable> friend class RscValueAdapter;
76 template<int N> friend class SecureString;
77
78 using ReadElementFunction = std::function<RscType(RscType expectedType, byte* pValue)>;
79 using WriteElementFunction = std::function<void(RscType valueType, const byte* pValue)>;
81
82public: // construction/destruction
88
92 template <class T>
93 RscVariant(const T& value);
94
99 RscVariant(const String& value);
100
105 RscVariant(const char* value);
106
112 RscVariant(const char16* input, size_t length, RscType type = RscType::Utf8String);
113
118 template<int N>
120
125 template<int N>
127
136 RscVariant(size_t arraySize, RscType arrayElementType, size_t dimensions = 1, size_t fieldCount = 0);
137
147 RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction* pFunction, size_t dimensions = 1, size_t fieldCount = 0);
148
158 RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction* pFunction, size_t dimensions = 1, size_t fieldCount = 0);
159
163 RscVariant(size_t fieldCount, ReadElementFunction* pFunction);
164
169
173 RscVariant(RscVariant&&)noexcept = default;
174
175public: // Static factory operations
181 static RscVariant<MaxStringSize> CreateStructVariant(size_t fieldCount);
182
191 static RscVariant<MaxStringSize> CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0);
192
193private: // static factory operations
194 static RscVariant<MaxStringSize> CreateStructVariant(size_t fieldCount, RemotingWriter& writer);
195 static RscVariant<MaxStringSize> CreateArrayVariant(size_t arraySize, RscType elementType, RemotingWriter& writer, size_t dimensions = 1, size_t fieldCount = 0);
196
197public: // operators
198 template <class T>
199 RscVariant& operator=(const T& value);
200 RscVariant& operator=(const String& value);
201 RscVariant& operator=(const char* value);
202 template<int N>
203 RscVariant& operator=(const RscString<N>& value);
204 template<int N>
205 RscVariant& operator=(const SecureString<N>& value);
206 RscVariant& operator=(const RscVariant& value) = default;
207 RscVariant& operator=(RscVariant&&)noexcept = default;
208 bool operator==(const RscVariant& value)const;
209 bool operator!=(const RscVariant& value)const;
210
211public: // getter/setter
216 RscType GetType(void)const;
217
223
230
236 size_t GetArrayDimensions(void)const;
237
243 size_t GetFieldCount(void) const;
244
249 const char* GetChars(void)const;
250
256 void SetWriteElementFunction(WriteElementFunction* pFunction) const;
257
262 const byte* GetDataAddress(void)const;
263
268 byte* GetDataAddress(void);
269
274 void SetType(RscType rscType);
275
276public: // operations
281 template<class T>
282 T GetValue(void)const;
283
288 template<class T>
289 void CopyTo(T& value)const;
290
295 String ToString(void)const;
296
302 void Assign(const char16 * input, size_t length, RscType rscType = RscType::Utf8String);
303
304private: // Setter/Getter for internal use and friend classes
305 RscArrayInformation& GetArrayInformation(void);
306 const RscArrayInformation& GetArrayInformation(void) const;
307 RscStructInformation& GetStructInformation(void);
308 const RscStructInformation& GetStructInformation(void) const;
309
310private: // methods
311 void Assign(const char* input, size_t length, RscType rscType = RscType::Utf8String);
312 void InitComplexTypeInfo(void);
313 bool ContainsTypeInformation(void) const;
314 size_t GetSize(void)const;
315
316private: // nested types
317 struct ComplexTypeInfo
318 {
319 union
320 {
321 RscArrayInformation arrayInformation;
322 RscStructInformation structInformation;
323 };
324 RemotingReader* pReader = nullptr;
325 mutable RemotingWriter* pWriter = nullptr;
326 ReadElementFunction* pReadElementFunction = nullptr;
327 mutable WriteElementFunction* pWriteElementFunction = nullptr;
328 };
329
330private: // static fields
331 static const size_t maxPrimitiveSize = 8;
332#ifdef ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
333 static const size_t minBufferSize = std::max(maxPrimitiveSize, std::max(sizeof(RscGuid), sizeof(RscVersion)));
334#else
335 static const size_t minBufferSize = maxPrimitiveSize;
336#endif // ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
337
338 static const size_t bufferSize = minBufferSize < (size_t)MaxStringSize ? (size_t)MaxStringSize : minBufferSize;
339
340private: // fields
341 union
342 {
343 ComplexTypeInfo typeInfo;
344 byte buffer[bufferSize];
345 };
346 RscType type = RscType::None;
347};
348
349
351// inline methods of RscType helper
352template<int N>
353inline constexpr RscType GetRscTypeFrom(const RscVariant<N>& /*value*/)
354{
355 return RscType::Object;
356}
357
359// inline methods of class RscVariant
360
361template<int MaxStringSize>
363 : type(typeArg)
364{
365}
366
367template<int MaxStringSize>
368template<class T>
370{
371 this->operator=(value);
372}
373
374template<int MaxStringSize>
376 : type(RscType::Utf8String)
377{
378 this->operator=(value);
379}
380
381template<int MaxStringSize>
383{
384 this->operator=(value);
385}
386
387template<int MaxStringSize>
388inline RscVariant<MaxStringSize>::RscVariant(const char16* input, size_t length, RscType type)
389{
390 this->Assign(input, length, type);
391}
392
393template<int MaxStringSize>
394template<int N>
396{
397 this->operator=(value);
398}
399
400template<int MaxStringSize>
401template<int N>
403{
404 this->operator=(value);
405}
406
407template<int MaxStringSize>
408inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, 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 = nullptr;
420}
421
422template<int MaxStringSize>
423inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction* pFunction, size_t dimensions, size_t fieldCount)
424 : type(RscType::Array)
425{
426 if(arrayElementType == RscType::Struct && fieldCount == 0)
427 {
428 throw ArgumentException::Create("fieldCount", fieldCount, "fieldCount has to be set for struct element types");
429 }
430 this->GetArrayInformation() = RscArrayInformation(arraySize, arrayElementType, dimensions, fieldCount);
431 this->typeInfo.pReader = nullptr;
432 this->typeInfo.pWriter = nullptr;
433 this->typeInfo.pReadElementFunction = pFunction;
434 this->typeInfo.pWriteElementFunction = nullptr;
435}
436
437template<int MaxStringSize>
438inline RscVariant<MaxStringSize>::RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction* pFunction, size_t dimensions, size_t fieldCount)
439 : type(RscType::Array)
440{
441 if(arrayElementType == RscType::Struct && fieldCount == 0)
442 {
443 throw ArgumentException::Create("fieldCount", fieldCount, "fieldCount has to be set for struct element types");
444 }
445 this->GetArrayInformation() = RscArrayInformation(arraySize, arrayElementType, dimensions, fieldCount);
446 this->typeInfo.pReader = nullptr;
447 this->typeInfo.pWriter = nullptr;
448 this->typeInfo.pReadElementFunction = nullptr;
449 this->typeInfo.pWriteElementFunction = pFunction;
450}
451
452template<int MaxStringSize>
453inline RscVariant<MaxStringSize>::RscVariant(size_t fieldCount, ReadElementFunction* pFunction)
454 : type(RscType::Struct)
455{
456 this->InitComplexTypeInfo();
457 this->GetStructInformation() = RscStructInformation(fieldCount);
458 this->typeInfo.pReadElementFunction = pFunction;
459}
460
461template<int MaxStringSize>
463{
464 return this->type;
465}
466
467template<int MaxStringSize>
469{
470 switch (this->type)
471 {
472 case RscType::IecTime:
473 return RscType::Int32;
477 case RscType::IecTimeOfDay64:
478 return RscType::Int64;
479 default:
480 // no mapping
481 return this->type;
482 }
483}
484
485template<int MaxStringSize>
487{
488 return this->GetArrayInformation().ElementType;
489}
490
491template<int MaxStringSize>
493{
494 if(this->GetType() != RscType::Array)
495 {
496 throw InvalidOperationException("RscVariant doesn't contain array information");
497 }
498 return this->typeInfo.arrayInformation;
499}
500
501template<int MaxStringSize>
502inline RscArrayInformation& RscVariant<MaxStringSize>::GetArrayInformation(void)
503{
504 if(this->GetType() != RscType::Array)
505 {
506 throw InvalidOperationException("RscVariant doesn't contain array information");
507 }
508 return this->typeInfo.arrayInformation;
509}
510
511template<int MaxStringSize>
512inline const RscStructInformation& RscVariant<MaxStringSize>::GetStructInformation(void) const
513{
514 if(this->GetType() != RscType::Struct)
515 {
516 throw InvalidOperationException("RscVariant doesn't contain struct information");
517 }
518 return this->typeInfo.structInformation;
519}
520
521template<int MaxStringSize>
522inline RscStructInformation& RscVariant<MaxStringSize>::GetStructInformation(void)
523{
524 if(this->GetType() != RscType::Struct)
525 {
526 throw InvalidOperationException("RscVariant doesn't contain struct information");
527 }
528 return this->typeInfo.structInformation;
529}
530
531template<int MaxStringSize>
533{
534 return this->GetArrayInformation().Dimensions;
535}
536
537template<int MaxStringSize>
539{
540 return this->GetStructInformation().FieldCount;
541}
542
543template<int MaxStringSize>
545{
546 return this->buffer;
547}
548
549template<int MaxStringSize>
550inline const byte* RscVariant<MaxStringSize>::GetDataAddress()const
551{
552 return this->buffer;
553}
554
555template<int MaxStringSize>
557{
558 this->type = rscType;
559}
560
561template<int MaxStringSize>
563{
564 return (this->type == RscType::Struct || this->type == RscType::Array);
565}
566
567template<int MaxStringSize>
568template<class T>
570{
571 this->type = GetRscType<T>();
572 if(this->type == RscType::None)
573 {
574 throw NotSupportedException("Cannot assign from argument: Type of argument is not supported");
575 }
576#ifndef ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
577 if (this->type == RscType::Version || this->type == RscType::Guid)
578 {
579 throw NotImplementedException("Type RscVersion and RscGuid are currently not supported by RscVariant");
580 }
581#endif // ARP_SYSTEM_RSC_SUPPORT_VERSION_GUID_AS_OBJECT
582 *reinterpret_cast<T*>(this->buffer) = value;
583 return *this;
584}
585
586template<int MaxStringSize>
588{
590 result.InitComplexTypeInfo();
591 result.GetStructInformation().FieldCount = fieldCount;
592 return result;
593}
594
595template<int MaxStringSize>
596inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions, size_t fieldCount)
597{
598 RscVariant<MaxStringSize> result(arraySize, elementType, dimensions, fieldCount);
599 return result;
600}
601
602template<int MaxStringSize>
603inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateStructVariant(size_t fieldCount, RemotingWriter& writer)
604{
606 result.typeInfo.pWriter = &writer;
607 return result;
608}
609
610template<int MaxStringSize>
611inline RscVariant<MaxStringSize> RscVariant<MaxStringSize>::CreateArrayVariant(size_t arraySize, RscType elementType, RemotingWriter& writer, size_t dimensions, size_t fieldCount)
612{
613 RscVariant<MaxStringSize> result(arraySize, elementType, dimensions, fieldCount);
614 result.typeInfo.pWriter = &writer;
615 return result;
616}
617
618template<int MaxStringSize>
619inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const String& value)
620{
621 size_t len = value.Length();
622 this->Assign(value.CStr(), len);
623 return *this;
624}
625
626template<int MaxStringSize>
627inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const char* value)
628{
629 size_t len = std::char_traits<char>::length(value);
630 this->Assign(value, len);
631 return *this;
632}
633
634template<int MaxStringSize>
635template<int N>
636inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const RscString<N>& value)
637{
638 this->Assign(value.CStr(), SecureStrnlen(value.CStr(), N), RscType::Utf8String);
639 return *this;
640}
641
642template<int MaxStringSize>
643template<int N>
644inline RscVariant<MaxStringSize>& RscVariant<MaxStringSize>::operator=(const SecureString<N>& value)
645{
646 this->Assign(value.CStr(), strlen(value.CStr()), RscType::SecureString);
647 return *this;
648}
649
650template<int MaxStringSize>
651inline void RscVariant<MaxStringSize>::Assign(const char* input, size_t length, RscType rscType)
652{
653 if (length >= MaxStringSize)
654 {
655 throw ArgumentException("Cannot copy string: argument string length {} exceeds MaxStringSize {}", length, MaxStringSize);
656 }
657 if (rscType != RscType::Utf8String && rscType != RscType::SecureString)
658 {
659 throw NotSupportedException("RscType '{}' not supported for Strings", rscType);
660 }
661 SecureStrncpy(reinterpret_cast<char*>(this->buffer), MaxStringSize, input, length);
662 this->buffer[length] = static_cast<byte>(0);
663 this->type = rscType;
664}
665
666template<int MaxStringSize>
667inline void RscVariant<MaxStringSize>::Assign(const char16* input, size_t length, RscType rscType)
668{
671
672 if (rscType != RscType::Utf8String)
673 {
674 throw NotSupportedException("RscType '{}' not supported for UTF16 strings", rscType);
675 }
676 this->type = rscType;
677 size_t resultLength = 0;
678 EncodingResult result = Utf16::ConvertToUtf8(input, length, reinterpret_cast<char*>(this->buffer), MaxStringSize - 1, resultLength);
679 if ((result != EncodingResult::Success) && (result != EncodingResult::NoConversion))
680 {
681 throw ArgumentException("Cannot convert UTF16 string, encoding result = {}", result);
682 }
683 this->buffer[resultLength] = 0_b;
684}
685
686template<int MaxStringSize>
687inline bool RscVariant<MaxStringSize>::operator==(const RscVariant& value)const
688{
689 if (this->GetType() != value.GetType())
690 {
691 return false;
692 }
693
694 if (this->GetSize() != value.GetSize())
695 {
696 return false;
697 }
698
699 if (memcmp(this->buffer, value.buffer, this->GetSize()) != 0)
700 {
701 return false;
702 }
703
704 if (this->GetType() == RscType::Utf8String)
705 {
706 if (strcmp((char*)this->buffer, (char*)value.buffer) != 0)
707 {
708 return false;
709 }
710 }
711
712 return true;
713}
714
715template<int MaxStringSize>
716inline bool RscVariant<MaxStringSize>::operator!=(const RscVariant& value)const
717{
718 return !(*this == value);
719}
720
721template<int MaxStringSize>
722inline void RscVariant<MaxStringSize>::InitComplexTypeInfo(void)
723{
724 // needed, because elements of union are not initialized
725 this->typeInfo.pReader = nullptr;
726 this->typeInfo.pWriter = nullptr;
727 this->typeInfo.pReadElementFunction = nullptr;
728 this->typeInfo.pWriteElementFunction = nullptr;
729}
730
731template<int MaxStringSize>
732template<class T>
733inline void RscVariant<MaxStringSize>::CopyTo(T& value) const
734{
735 RscType argType = GetRscType<T>();
736 if(this->GetValueType() != argType)
737 {
738 throw InvalidCastException("Cannot copy value to argument: RscVariant contains data type {0} but arg is of type {1}", this->type, argType);
739 }
740 value = *reinterpret_cast<const T*>(this->buffer);
741}
742
743template<int MaxStringSize>
744inline const char* RscVariant<MaxStringSize>::GetChars() const
745{
746 if (this->type != RscType::Utf8String && this->type != RscType::SecureString && this->type != RscType::AnsiString)
747 {
748 throw InvalidCastException("Cannot convert to string: RscVariant is of type {0}", this->type);
749 }
750 return reinterpret_cast<const char*>(this->buffer);
751}
752
753template<int MaxStringSize>
754inline void RscVariant<MaxStringSize>::SetWriteElementFunction(WriteElementFunction * pFunction) const
755{
756 if(this->type != RscType::Array && this->type != RscType::Struct)
757 {
758 throw InvalidOperationException("Method only allowed for array and struct objects");
759 }
760 this->typeInfo.pWriteElementFunction = pFunction;
761}
762
763template<int MaxStringSize>
764template<class T>
766{
767 T result;
768 this->CopyTo(result);
769 return result;
770}
771
772template<int MaxStringSize>
774{
775 const byte* pValue = this->GetDataAddress();
776
777 switch (this->type)
778 {
782 return reinterpret_cast<const char*>(pValue);
784 return reinterpret_cast<const DateTime*>(pValue)->ToIso8601String();
785 case RscType::Bool:
786 {
787 std::ostringstream oss;
788 oss << std::boolalpha << *reinterpret_cast<const bool*>(pValue);
789 if (oss.fail())
790 {
791 throw InvalidOperationException("Value of RscVariant is not of type bool.");
792 }
793 return oss.str();
794 }
795 case RscType::Char:
796 return std::to_string(*reinterpret_cast<const char16*>(pValue));
797 case RscType::Int16:
798 return std::to_string(*reinterpret_cast<const int16*>(pValue));
799 case RscType::Int32:
800 case RscType::IecTime:
801 return std::to_string(*reinterpret_cast<const int32*>(pValue));
802 case RscType::Int8:
803 return std::to_string(*reinterpret_cast<const int8*>(pValue));
804 case RscType::Int64:
808 case RscType::IecTimeOfDay64:
809 return std::to_string(*reinterpret_cast<const int64*>(pValue));
810 case RscType::None:
811 case RscType::Null:
812 return String::Empty;
813 case RscType::Real32:
814 return std::to_string(*reinterpret_cast<const float*>(pValue));
815 case RscType::Real64:
816 return std::to_string(*reinterpret_cast<const double*>(pValue));
817 case RscType::Uint16:
818 return std::to_string(*reinterpret_cast<const uint16*>(pValue));
819 case RscType::Uint32:
820 return std::to_string(*reinterpret_cast<const uint32*>(pValue));
821 case RscType::Uint64:
822 return std::to_string(*reinterpret_cast<const uint64*>(pValue));
823 case RscType::Uint8:
824 return std::to_string(*reinterpret_cast<const uint8*>(pValue));
825 case RscType::Version:
826 return reinterpret_cast<const RscVersion*>(pValue)->ToString();
827 case RscType::Guid:
828 return reinterpret_cast<const RscGuid*>(pValue)->ToString();
829 case RscType::Void:
830 return String::Empty;
831 default:
832 // case RscType::Array:
833 throw NotSupportedException("RscVariant::ToString() not supported for type '{0}'", type);
834 }
835}
836
837template<int MaxStringSize>
838inline size_t RscVariant<MaxStringSize>::GetSize(void)const
839{
840 switch (this->GetValueType())
841 {
842 case RscType::Void:
843 return 0;
844 break;
845 case RscType::Bool:
846 case RscType::Int8:
847 case RscType::Uint8:
848 return 1;
849 break;
850 case RscType::Char:
851 case RscType::Int16:
852 case RscType::Uint16:
853 return 2;
854 break;
855 case RscType::Int32:
856 case RscType::Uint32:
857 case RscType::Real32:
858 case RscType::IecTime:
859 return 4;
860 break;
861 case RscType::Int64:
862 case RscType::Uint64:
863 case RscType::Real64:
868 case RscType::IecTimeOfDay64:
869 return 8;
870 break;
872 return strlen((char*)this->buffer);
873 break;
874 case RscType::Array:
875 {
876 return sizeof(RscArrayInformation);
877 break;
878 }
879 case RscType::Struct:
880 {
881 return sizeof(RscStructInformation);
882 break;
883 }
885 default:
886 throw NotSupportedException("RscType {0} not supported.", this->GetValueType());
887 }
888}
889
890}}}} // end of namespace Arp::System::Rsc::Services
891
The class contains date and time informations.
Definition: DateTime.hpp:46
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:69
RscVariant(const T &value)
Creates a new instance of RscVariant with value. Gets RscType by type deduction of T.
Definition: RscVariant.hxx:369
void SetType(RscType rscType)
Forces the internal RscType to be set to another RscType. This Method does no conversion or validatio...
Definition: RscVariant.hxx:556
String ToString(void) const
Converts this instance to string if the variant type has a reasonable string representation.
Definition: RscVariant.hxx:773
RscVariant(const RscString< N > &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:395
size_t GetArrayDimensions(void) const
Gets the count of array dimensions (1 for simple array, 2 for array of array etc.)....
Definition: RscVariant.hxx:532
RscVariant(const SecureString< N > &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:402
void Assign(const char16 *input, size_t length, RscType rscType=RscType::Utf8String)
Assigns an UTF16 string to this instance.
Definition: RscVariant.hxx:667
RscVariant(RscType type=RscType::None)
Creates an empty instance of RscVariant
Definition: RscVariant.hxx:362
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:382
T GetValue(void) const
Converts this value to the given type T.
Definition: RscVariant.hxx:765
size_t GetFieldCount(void) const
Returns field count, if RscVariant contains struct information
Definition: RscVariant.hxx:538
RscType GetValueType(void) const
Gets the value type as RscType of the contained element
Definition: RscVariant.hxx:468
const char * GetChars(void) const
Gets pointer to internal string buffer. Operation only valid for Utf8Strings.
Definition: RscVariant.hxx:744
static RscVariant< MaxStringSize > CreateStructVariant(size_t fieldCount)
Creates a new RscVariant initialized with RscStructInformation
Definition: RscVariant.hxx:587
RscVariant(const char16 *input, size_t length, RscType type=RscType::Utf8String)
Assigns an UTF16 string to this instance.
Definition: RscVariant.hxx:388
RscVariant(size_t fieldCount, ReadElementFunction *pFunction)
For internal use only
Definition: RscVariant.hxx:453
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:596
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:754
RscVariant(const String &value)
Creates a new instance of RscVariant with value. RscType is Utf8String.
Definition: RscVariant.hxx:375
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:544
RscType GetType(void) const
Gets the RscType of the contained element
Definition: RscVariant.hxx:462
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:438
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:423
RscType GetArrayElementType(void) const
Gets the RscType of the array elements if RscVariant contains array information.
Definition: RscVariant.hxx:486
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:408
void CopyTo(T &value) const
Copies internal data to memory referenced by value. Only for primtive types. Read Strings with GetCha...
Definition: RscVariant.hxx:733
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
size_type Length() const
Returns the number of char elements in this string.
Definition: BasicString.hxx:1049
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:1935
const CharType * CStr() const
Gets the character data of this string.
Definition: BasicString.hxx:1518
static const SelfType Empty
An emtpy static string instance.
Definition: BasicString.hxx:224
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:1899
std::uint64_t uint64
The Arp unsigned integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:40
char16_t char16
The Arp character type of 2 byte size.
Definition: PrimitiveTypes.hpp:50
std::int64_t int64
The Arp integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:42
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:36
std::int8_t int8
The Arp integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:30
std::uint16_t uint16
The Arp unsigned integer type of 2 byte size.
Definition: PrimitiveTypes.hpp:32
std::uint8_t uint8
The Arp unsigned integer type of 1 byte size.
Definition: PrimitiveTypes.hpp:28
std::int32_t int32
The Arp integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:38
std::int16_t int16
The Arp integer type of 2 byte size.
Definition: PrimitiveTypes.hpp:34
@ 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
Data types supported by RSC.
Definition: RscType.hpp:36
@ Version
Arp::System::Rsc::Services::RscVersion
@ Array
std::vector<T> or RSC enumerators
@ Object
Object type as Arp::System::Rsc::Services::RscVariant
@ Struct
struct derived by IRscSerializable
@ AnsiString
Ansi string, not supported in Rsc context
@ IecTime
summary>IEC type: LTIME [int64]
@ Guid
Universal unique ID Arp::System::Rsc::Services::RscGuid
@ SecureString
String for security context, handled by Rsc with Arp::System::Rsc::Services::SecureString
@ Utf8String
Utf-8 string, Arp::System::Rsc::Services::RscString
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:129
Contains information to marshall an struct
Definition: RscType.hpp:161
size_t FieldCount
Count of struct fields
Definition: RscType.hpp:167