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