PLCnext API Documentation 26.6.0.38
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/assignment
75 RscVariant(const RscVariant& arg);
76 RscVariant(RscVariant&& arg)noexcept;
77 RscVariant& operator=(const RscVariant& arg);
78 RscVariant& operator=(RscVariant&& arg)noexcept;
80
81public: // assign operators
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 elementType, size_t dimensions = 1, size_t fieldCount = 0);
92 RscVariant(size_t arraySize, RscType elementType, RscWriter& writer, size_t dimensions, size_t fieldCount);
93 RscVariant(size_t arraySize, RscType elementType, ReadElementFunction& function, size_t dimensions = 1, size_t fieldCount = 0);
94 RscVariant(size_t arraySize, RscType elementType, WriteElementFunction& function, size_t dimensions = 1, size_t fieldCount = 0);
95 RscVariant(size_t fieldCount, ReadElementFunction& function);
96 RscVariant(size_t fieldCount, WriteElementFunction& function);
97 RscVariant(size_t fieldCount, RscReader& reader);
98 RscVariant(size_t fieldCount, RscWriter& writer);
99 RscVariant(const RscStructInfo& info);
100
101public: // Static factory operations
102 static RscVariant CreateStructVariant(size_t fieldCount);
103 static RscVariant CreateStructVariant(size_t fieldCount, ReadElementFunction& readFunction);
104 static RscVariant CreateStructVariant(size_t fieldCount, WriteElementFunction& writeFunction);
105 static RscVariant CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions = 1, size_t fieldCount = 0);
106 static RscVariant CreateArrayVariant(size_t arraySize, RscType elementType, ReadElementFunction& readFunction, size_t dimensions = 1, size_t fieldCount = 0);
107 static RscVariant CreateArrayVariant(size_t arraySize, RscType elementType, WriteElementFunction& writeFunction, size_t dimensions = 1, size_t fieldCount = 0);
108
109public: // global friend operators (shall be defined implicit inline due to EXPORT on Windows)
110
115 friend std::ostream& operator<<(std::ostream& os, const RscVariant& arg)
116 {
117 os << arg.ToString();
118 return os;
119 }
120
121private: // Static factory operations
122 static RscVariant CreateStructVariant(size_t fieldCount, RscReader& reader);
123 static RscVariant CreateStructVariant(size_t fieldCount, RscWriter& writer);
124 static RscVariant CreateArrayVariant(size_t arraySize, RscType elementType, RscWriter& writer, size_t dimensions = 1, size_t fieldCount = 0);
125
126public: // compare operators
127 bool operator==(const RscVariant& arg)const;
128 bool operator!=(const RscVariant& arg)const;
129
130private: // static/const fields
131 static const size_t maxPrimitiveSize = 8;
132 static const size_t maxStringSize = static_cast<size_t>(N);
133 static const size_t stringBufferSize = static_cast<size_t>(N + 1);
134 static const size_t minBufferSize = std::max(maxPrimitiveSize, std::max(sizeof(String), std::max(sizeof(RscGuid), sizeof(RscVersion))));
135 static const size_t bufferSize = std::max(minBufferSize, stringBufferSize);
136
137private: // fields
138 std::array<byte, bufferSize> buffer{};
139};
140
141} // end of namespace Arp::Base::Rsc::Commons
142
143// include inline code of RscVariant
144#include "Arp/Base/Rsc/Commons/RscVariant.ipp"
145
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:41
String ToString(void) const
Converts this instance to String if the variant type has a reasonable string representation.
Definition: RscVariantBase.cpp:876
std::function< void(RscType elementType, const RscVariantBase &value)> WriteElementFunction
The write element delegate type.
Definition: RscVariantBase.hpp:48
RscType type
The RSC type of this variant.
Definition: RscVariantBase.hpp:175
std::function< void(RscType elementType, RscVariantBase &value)> ReadElementFunction
The read element delegate type.
Definition: RscVariantBase.hpp:47
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.
RscVariant & operator=(const RscVariant &arg)
The assign operator.
Definition: RscVariant.ipp:247
friend std::ostream & operator<<(std::ostream &os, const RscVariant &arg)
The ostream operator is used for logging and string formatting.
Definition: RscVariant.hxx:115
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:449
static RscVariant CreateStructVariant(size_t fieldCount)
Creates a new RscVariant initialized with RscStructInfo
Definition: RscVariant.ipp:280
static RscVariant CreateArrayVariant(size_t arraySize, RscType elementType, size_t dimensions=1, size_t fieldCount=0)
Creates a new RscVariant representing an array.
Definition: RscVariant.ipp:315
bool operator!=(const RscVariant &arg) const
Compares this instance to arg on inequality
Definition: RscVariant.ipp:459
Specifies a complex version with 4 version numbers and is marshalled to .NET type System....
Definition: RscVersion.hpp:23
Reads marshaled data of RSC services.
Definition: RscReader.hpp:34
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