PLCnext API Documentation 25.0.2.69
RscVariant.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/Base/Rsc/Commons/Rsc.hpp"
9#include "Arp/Base/Rsc/Commons/RscGuid.hpp"
10#include "Arp/Base/Rsc/Commons/RscString.hxx"
11#include "Arp/Base/Rsc/Commons/RscVersion.hpp"
12#include "Arp/Base/Rsc/Commons/RscTypeInfo.hpp"
13#include "Arp/Base/Rsc/Commons/RscSecureString.hxx"
14#include "Arp/Base/Rsc/Commons/RscVariantBase.hpp"
15#include "Arp/Base/Rsc/Commons/RscTypeDeduction.hpp"
16
17namespace Arp::Base::Rsc::Commons
18{
19
55template<int N = 0>
57{
58 friend class Arp::Base::Rsc::Commons::Internal::RscVariantAccessor;
59
60public: // construction
61 RscVariant(void);
62 RscVariant(RscType type); // no explicit here, is used by unit tests heavily
63 explicit RscVariant(const String& value);
64 explicit RscVariant(const char* value);
65 explicit RscVariant(const char8u* value);
66 explicit RscVariant(const char16* input, size_t length);
67
68 template<int M> explicit RscVariant(const RscString<M>& value);
69 template<int M> explicit RscVariant(const RscSecureString<M>& value);
70 template<int M> explicit RscVariant(const char value[M]);
71 template<int M> explicit RscVariant(char value[M]);
72 template<class T> explicit RscVariant(const T& value);
73
74 // canonical construction/destruction
75 RscVariant(const RscVariant& arg);
76 RscVariant(RscVariant&& arg)noexcept;
78
79public: // assign operators
80 RscVariant& operator=(const RscVariant& arg);
81 RscVariant& operator=(RscVariant&& arg)noexcept;
82 RscVariant& operator=(const String& value);
83 RscVariant& operator=(const char* value);
84 RscVariant& operator=(const char8u* value);
85
86 template<class T> RscVariant& operator=(const T& value);
87 template<int M> RscVariant& operator=(const RscString<M>& value);
88 template<int M> RscVariant& operator=(const RscSecureString<M>& value);
89
90private: // construction
91 RscVariant(size_t arraySize, RscType arrayElementType, size_t dimensions = 1, size_t fieldCount = 0);
92 RscVariant(size_t arraySize, RscType arrayElementType, RscWriter& writer, size_t dimensions, size_t fieldCount);
93 RscVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction& function, size_t dimensions = 1, size_t fieldCount = 0);
94 RscVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction& function, size_t dimensions = 1, size_t fieldCount = 0);
95 RscVariant(size_t fieldCount, ReadElementFunction& function);
96 RscVariant(size_t fieldCount, RscWriter& writer);
97 RscVariant(const RscStructInfo& info);
98
99public: // Static factory operations
100 static RscVariant CreateStructVariant(size_t fieldCount);
101 static RscVariant CreateStructVariant(size_t fieldCount, ReadElementFunction& readFunction);
102 static RscVariant CreateArrayVariant(size_t arraySize, RscType arrayElementType, size_t dimensions = 1, size_t fieldCount = 0);
103 static RscVariant CreateArrayVariant(size_t arraySize, RscType arrayElementType, ReadElementFunction& readFunction, size_t dimensions = 1, size_t fieldCount = 0);
104 static RscVariant CreateArrayVariant(size_t arraySize, RscType arrayElementType, WriteElementFunction& writeFunction, size_t dimensions = 1, size_t fieldCount = 0);
105
106private: // Static factory operations
107 static RscVariant CreateStructVariant(size_t fieldCount, RscWriter& writer);
108 static RscVariant CreateArrayVariant(size_t arraySize, RscType arrayElementType, RscWriter& writer, size_t dimensions = 1, size_t fieldCount = 0);
109
110public: // compare operators
111 bool operator==(const RscVariant& arg)const;
112 bool operator!=(const RscVariant& arg)const;
113
114private: // static/const fields
115 static const size_t maxPrimitiveSize = 8;
116 static const size_t maxStringSize = static_cast<size_t>(N);
117 static const size_t stringBufferSize = static_cast<size_t>(N + 1);
118 static const size_t minBufferSize = std::max(maxPrimitiveSize, std::max(sizeof(String), std::max(sizeof(RscGuid), sizeof(RscVersion))));
119 static const size_t bufferSize = std::max(minBufferSize, stringBufferSize);
120
121private: // fields
122 std::array<byte, bufferSize> buffer{};
123};
124
125} // end of namespace Arp::Base::Rsc::Commons
126
127// include inline code of RscVariant
128#include "Arp/Base/Rsc/Commons/RscVariant.ipp"
129
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
A RSC wrapper class to marshal objects of type Uuid.
Definition: RscGuid.hpp:22
Specialized implementation of RscString for secure context.
Definition: RscSecureString.hxx:16
Contains a static string with string lentgh up to N characters. The string shall be null terminated.
Definition: RscString.hxx:24
Contains information to marshal structs.
Definition: RscStructInfo.hpp:17
This class is a base class of template class RscVariant.
Definition: RscVariantBase.hpp:40
std::function< void(RscType elementType, const RscVariantBase &value)> WriteElementFunction
The write element delegate type.
Definition: RscVariantBase.hpp:47
RscType type
The RSC type of this variant.
Definition: RscVariantBase.hpp:169
std::function< void(RscType elementType, RscVariantBase &value)> ReadElementFunction
The read element delegate type.
Definition: RscVariantBase.hpp:46
Rsc class for variant data types like primitive data type, strings or information about arrays or str...
Definition: RscVariant.hxx:57
~RscVariant(void)
Default destructor.
static RscVariant CreateArrayVariant(size_t arraySize, RscType arrayElementType, size_t dimensions=1, size_t fieldCount=0)
Creates a new RscVariant representing an array.
Definition: RscVariant.ipp:286
RscVariant & operator=(const RscVariant &arg)
The assign operator.
Definition: RscVariant.ipp:229
RscVariant(void)
The default constructor creates an empty instance of RscVariant.
Definition: RscVariant.ipp:18
bool operator==(const RscVariant &arg) const
Compares this instance to arg on equality
Definition: RscVariant.ipp:413
static RscVariant CreateStructVariant(size_t fieldCount)
Creates a new RscVariant initialized with RscStructInfo
Definition: RscVariant.ipp:273
bool operator!=(const RscVariant &arg) const
Compares this instance to arg on inequality
Definition: RscVariant.ipp:423
Specifies a complex version with 4 version numbers and is marshalled to .NET type System....
Definition: RscVersion.hpp:23
Writes marshalled data of RSC services.
Definition: RscWriter.hpp:34
char16_t char16
The Arp character type of 2 byte size.
Definition: PrimitiveTypes.hpp:49
char8_t char8u
The Arp UTF8 character type of 1 byte size.
Definition: PrimitiveTypes.hpp:47