PLCnext API Documentation 25.0.2.69
Public Member Functions | Static Public Member Functions | Friends | List of all members
Arp::Base::Rsc::Commons::RscVariant< N > Class Template Reference

Rsc class for variant data types like primitive data type, strings or information about arrays or structs. ArrayInformation and StructInformation are used in combination with RscArrayReader, RscArrayWriter, RscStructReader and RscStructWriter More...

#include <RscVariant.hxx>

Inheritance diagram for Arp::Base::Rsc::Commons::RscVariant< N >:
Inheritance graph

Public Member Functions

 RscVariant (void)
 The default constructor creates an empty instance of RscVariant. More...
 
 RscVariant (RscType type)
 Creates an empty but typed instance of RscVariant. More...
 
 RscVariant (const String &value)
 Creates a new instance of RscVariant with a value of type String. More...
 
 RscVariant (const char *value)
 Creates a new instance of RscVariant with a value of type String. More...
 
 RscVariant (const char8u *value)
 Creates a new instance of RscVariant with a value of type String. More...
 
 RscVariant (const char16 *input, size_t length)
 Creates a new instance of RscVariant with a value of type String. More...
 
template<int M>
 RscVariant (const RscString< M > &value)
 Creates a new instance of RscVariant with a value of type String. More...
 
template<int M>
 RscVariant (const RscSecureString< M > &value)
 Creates a new instance of RscVariant with a value of type String. More...
 
template<int M>
 RscVariant (const char value[M])
 Creates a new instance of RscVariant with a value of type String. More...
 
template<int M>
 RscVariant (char value[M])
 
template<class T >
 RscVariant (const T &value)
 Creates a new instance of RscVariant with an initial value. More...
 
 RscVariant (const RscVariant &arg)
 The copy constructor. More...
 
 RscVariant (RscVariant &&arg) noexcept
 The move constructor. More...
 
 ~RscVariant (void)
 Default destructor.
 
RscVariantoperator= (const RscVariant &arg)
 The assign operator. More...
 
RscVariantoperator= (RscVariant &&arg) noexcept
 The move-assign operator. More...
 
RscVariantoperator= (const String &value)
 Assign operator for type String. More...
 
RscVariantoperator= (const char *value)
 Assign operator for type char*. More...
 
RscVariantoperator= (const char8u *value)
 Assign operator for type char8u*. More...
 
template<class T >
RscVariantoperator= (const T &value)
 
template<int M>
RscVariantoperator= (const RscString< M > &value)
 
template<int M>
RscVariantoperator= (const RscSecureString< M > &value)
 
bool operator== (const RscVariant &arg) const
 Compares this instance to arg on equality More...
 
bool operator!= (const RscVariant &arg) const
 Compares this instance to arg on inequality More...
 
template<class T >
RscVariant< N > & operator= (const T &value)
 Assign operator for values of arbitrary type. More...
 
template<int M>
RscVariant< N > & operator= (const RscString< M > &value)
 Assign operator for values of type RscString. More...
 
template<int M>
RscVariant< N > & operator= (const RscSecureString< M > &value)
 Assign operator for values of type SecureString. More...
 
- Public Member Functions inherited from Arp::Base::Rsc::Commons::RscVariantBase
 RscVariantBase (RscType type=RscType::None)
 The default constructor creates an empty instance of RscVariantBase. More...
 
 RscVariantBase (RscType type, byte *pBuffer)
 Creates a typed instance of RscVariant which refers to an external buffer. More...
 
 RscVariantBase (RscType type, char *pBuffer, size_t bufferSize)
 Creates a typed instance of RscVariant which refers to an external buffer. More...
 
 RscVariantBase (const RscStringBase &data)
 Creates a typed instance of RscVariant which refers to an external buffer. More...
 
 RscVariantBase (const RscArrayInfo &arrayInfo)
 Creates a typed instance of RscVariant which represents an array. More...
 
 RscVariantBase (const RscStructInfo &structInfo)
 Creates a typed instance of RscVariant which represents a struct. More...
 
 RscVariantBase (const RscVariantBase &arg)
 The copy constructor. More...
 
 RscVariantBase (RscVariantBase &&arg) noexcept
 The move constructor. More...
 
RscVariantBaseoperator= (const RscVariantBase &arg)
 The assign operator. More...
 
RscVariantBaseoperator= (RscVariantBase &&arg) noexcept
 The move-assign operator. More...
 
 ~RscVariantBase (void)
 The default destructor.
 
RscVariantBaseoperator= (const String &value)
 Assign operator for type String. More...
 
RscVariantBaseoperator= (const char *value)
 Assign operator for type char*. More...
 
RscVariantBaseoperator= (const char8u *value)
 Assign operator for type char8u*. More...
 
template<class T >
RscVariantBaseoperator= (const T &value)
 Assign operator for values of arbitrary type. More...
 
template<int N>
RscVariantBaseoperator= (const RscString< N > &value)
 Assign operator for values of type RscString. More...
 
template<int N>
RscVariantBaseoperator= (const RscSecureString< N > &value)
 Assign operator for values of type SecureString. More...
 
void SetType (RscType value)
 Forces the internal RscType to be set to another RscType. More...
 
RscType GetType (void) const
 Gets the RscType of the contained element More...
 
RscType GetValueType (void) const
 Gets the raw value type as RscType of the contained element. More...
 
bool IsComplexType (void) const
 Determines if this instance represents a complex type, i.e. an array or a struct. More...
 
bool IsArray (void) const
 Determines if this instance represents an array. More...
 
bool IsStruct (void) const
 Determines if this instance represents a struct. More...
 
bool IsFormattable (void) const
 Determines if this instance is convertible to String using the ToString() operation. More...
 
size_t GetDataSize (void) const
 Gets the data size of the contained element. More...
 
size_t GetMaxStringSize (void) const
 Gets the maximal length of strings which are provided by this instance. More...
 
size_t GetBufferSize (void) const
 Gets the buffer size of this instance. More...
 
RscType GetArrayElementType (void) const
 Gets the RscType of the array elements, if this instance represents an array. More...
 
size_t GetArraySize (void) const
 Gets the array size, if this instance represents an array. More...
 
size_t GetArrayDimensions (void) const
 Gets the count of array dimensions (1 for simple array, 2 for array of array etc.), if this instance represents an array. More...
 
size_t GetArrayFieldCount (void) const
 Gets the field count of the struct elements, if this instance represents an array of structs. More...
 
size_t GetFieldCount (void) const
 Gets the field count, if this instance represents a struct. More...
 
byte * GetDataAddress (void)
 Gets a writable raw pointer to the internal data buffer. More...
 
const byte * GetDataAddress (void) const
 
const char * GetChars (void) const
 Gets a readable pointer to internal string buffer. More...
 
void Assign (const char *input, RscType rscType=RscType::String)
 Assigns an UTF8 string to this instance. More...
 
void Assign (const char *input, size_t length, RscType rscType=RscType::String)
 Assigns an UTF8 string to this instance. More...
 
void Assign (const char16 *input, size_t length)
 Assigns an UTF16 string to this instance. More...
 
void Assign (const String &value)
 Assigns the given value of type String. More...
 
void CopyTo (String &value) const
 Copies the content of this variant to a string. More...
 
String ToString (void) const
 Converts this instance to String if the variant type has a reasonable string representation. More...
 
void Clear (bool clearBuffer=false)
 Clears the type and all other infos of this instance. More...
 
bool Equals (const RscVariantBase &arg) const
 Checks if this instance is equal to arg . More...
 
void Read (RscReader &reader, bool omitTag)
 Reads this instance from RSC. More...
 
void Write (RscWriter &writer, bool omitTag) const
 Writes this instance to RSC. More...
 
bool HasArrayInfo (void) const
 Determines if the array info of this instance was set yet. More...
 
void SetArrayInfo (const RscArrayInfo &arrayInfo)
 Set the array info of this instance. More...
 
void SetArrayInfo (size_t size, RscType elementType=RscType::None, size_t dimensions=1, size_t fieldCount=0)
 Sets the array info of this instance. More...
 
RscArrayInfoGetArrayInfo (void)
 Gets the array info of this instance. More...
 
const RscArrayInfoGetArrayInfo (void) const
 
bool HasStructInfo (void) const
 Determines if the struct info of this instance was set yet. More...
 
void SetStructInfo (size_t fieldCount)
 Sets the struct info of this instance. More...
 
RscStructInfoGetStructInfo (void)
 Gets the struct info of this instance. More...
 
const RscStructInfoGetStructInfo (void) const
 
bool HasReadElementFunction (void) const
 Determines if this instance provides an element read function. More...
 
ReadElementFunction GetReadElementFunction (void) const
 Gets the element read function if available. More...
 
void SetReadElementFunction (ReadElementFunction &function)
 Sets the element read function. More...
 
bool HasWriteElementFunction (void) const
 Determines if this instance provides an element write function. More...
 
WriteElementFunction GetWriteElementFunction (void) const
 Gets the element write function if available. More...
 
void SetWriteElementFunction (WriteElementFunction &function) const
 Sets the element write function. More...
 
void ResetComplexTypeInfo (void)
 Clears reader, writer and read/write element functions.
 
template<int N>
void Assign (char value[N])
 Assigns the given value of type T . More...
 
template<int N>
void Assign (const char value[N])
 
template<int N>
void Assign (const RscString< N > &value)
 Assigns the given value of type RscString. More...
 
template<int N>
void Assign (const RscSecureString< N > &value)
 Assigns the given value of type SecureString. More...
 
template<class T >
void Assign (const T &value)
 Assigns the given value of type T . More...
 
template<class T >
void CopyTo (T &value) const
 Copies the value of this instance to the out parameter value . More...
 
template<class T >
GetValue (void) const
 Converts this value to the given type T . More...
 
template<class T >
T * GetValueAddress (void)
 Gets the address of the contained value as type T *. More...
 
template<class T >
const T * GetValueAddress (void) const
 Gets the address of the contained value as type const T *. More...
 

Static Public Member Functions

static RscVariant CreateStructVariant (size_t fieldCount)
 Creates a new RscVariant initialized with RscStructInfo More...
 
static RscVariant CreateStructVariant (size_t fieldCount, ReadElementFunction &readFunction)
 Creates a new RscVariant initialized with RscStructInfo More...
 
static RscVariant CreateArrayVariant (size_t arraySize, RscType arrayElementType, size_t dimensions=1, size_t fieldCount=0)
 Creates a new RscVariant representing an array. More...
 
static RscVariant CreateArrayVariant (size_t arraySize, RscType arrayElementType, ReadElementFunction &readFunction, size_t dimensions=1, size_t fieldCount=0)
 Creates a new RscVariant representing an array for reading. More...
 
static RscVariant CreateArrayVariant (size_t arraySize, RscType arrayElementType, WriteElementFunction &writeFunction, size_t dimensions=1, size_t fieldCount=0)
 Creates a new RscVariant representing an array for writing. More...
 

Friends

class Arp::Base::Rsc::Commons::Internal::RscVariantAccessor
 

Additional Inherited Members

- Public Types inherited from Arp::Base::Rsc::Commons::RscVariantBase
using ReadFieldFunction = std::function< void(RscType fieldType, RscVariantBase &value)>
 The read field delegate type.
 
using WriteFieldFunction = std::function< void(RscType fieldType, const RscVariantBase &value)>
 The write field delegate type.
 
using ReadElementFunction = std::function< void(RscType elementType, RscVariantBase &value)>
 The read element delegate type.
 
using WriteElementFunction = std::function< void(RscType elementType, const RscVariantBase &value)>
 The write element delegate type.
 
- Protected Member Functions inherited from Arp::Base::Rsc::Commons::RscVariantBase
void SetBufferInfo (byte *pDataBuffer, size_t dataBufferSize, bool isDynamicString)
 Sets the buffer properties which are provided by super class RscVariant. More...
 
bool HasReader (void) const
 Determines if this instance has a reader for deserialization. More...
 
bool HasWriter (void) const
 Determines if this instance has a write for serialization. More...
 
void SetReader (RscReader &reader)
 Sets the RSC reader, if this instance represents a complex type (array or struct). More...
 
void SetWriter (RscWriter &writer) const
 Sets the RSC writer, if this instance represents a complex type (array or struct). More...
 
RscReaderGetReader (void) const
 Gets a reader for deserialization. More...
 
RscWriterGetWriter (void) const
 Gets a writer for serialization. More...
 
- Protected Attributes inherited from Arp::Base::Rsc::Commons::RscVariantBase
RscType type = RscType::None
 The RSC type of this variant.
 
byte * pBuffer = nullptr
 The buffer of this variant (usually applied by RscVariant<T>)
 
size_t bufferSize = 0
 The size of the applied buffer.
 
bool providesDynamicString = false
 Determines if this variant supports dynamic strings (see String)
 
String dynamicString
 The dynamic string storage.
 
ComplexTypeInfo typeInfo
 The type info of this variant.
 

Detailed Description

template<int N = 0>
class Arp::Base::Rsc::Commons::RscVariant< N >

Rsc class for variant data types like primitive data type, strings or information about arrays or structs. ArrayInformation and StructInformation are used in combination with RscArrayReader, RscArrayWriter, RscStructReader and RscStructWriter

Template Parameters
NThe maximum count of characters for strings. If this value is zero, strings are not supported.

The following types are supported by RscVariant:

RscTypeC++ type
Voidvoid
BoolArp::boolean
Int8Arp::int8
Uint8Arp::uint8
Int16Arp::int16
Uint16Arp::uint16
Int32Arp::int32
Uint32Arp::uint32
Uint32Arp::uint32
Int64Arp::int64
Uint64Arp::uint64
Real32Arp::float32
Real64Arp::float64
StringArp::StringOnly if N is not zero.
Structstruct derived by Arp::Base::Rsc::Commons::RscSerializable
Arraystd::vector<T> or RSC enumerators
DateTimeArp::DateTime
VersionArp::Base::Rsc::Commons::RscVersion
GuidArp::Base::Rsc::Commons::RscGuid
SecureStringArp::Base::Rsc::Commons::RscSecureString
SecurityTokenArp::Base::Commons::Security::SecurityToken

Constructor & Destructor Documentation

◆ RscVariant() [1/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( void  )
inline

The default constructor creates an empty instance of RscVariant.

Template Parameters
NThe maximum size for strings.

◆ RscVariant() [2/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( RscType  type)
inline

Creates an empty but typed instance of RscVariant.

Parameters
typeThe initial Rsc type.
Template Parameters
NThe maximum size for strings.

◆ RscVariant() [3/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const String value)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe String value to copy to this instance.
Template Parameters
NThe maximum size for strings.

◆ RscVariant() [4/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const char *  value)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe String value to copy to this instance.
Template Parameters
NThe maximum size for strings.

◆ RscVariant() [5/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const char8u *  value)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe String value to copy to this instance.
Template Parameters
NThe maximum size for strings.

◆ RscVariant() [6/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const char16 *  input,
size_t  length 
)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
inputThe UTF16 encoded string to copy to this instance.
lengthThe string length of the input string (number of char16 characters).

The input string is converted to an UTF8 string for marshalling.

Template Parameters
NThe maximum size for strings.

◆ RscVariant() [7/12]

template<int N>
template<int M>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const RscString< M > &  value)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe String value to copy to this instance.
Template Parameters
NThe maximum size for strings.
MThe maximum size of the as argument passed string.

◆ RscVariant() [8/12]

template<int N>
template<int M>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const RscSecureString< M > &  value)
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe String value to copy to this instance.
Template Parameters
NThe maximum size for strings.
MThe maximum size of the as argument passed string.

◆ RscVariant() [9/12]

template<int N>
template<int M>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const char  value[M])
inlineexplicit

Creates a new instance of RscVariant with a value of type String.

Parameters
valueThe string to copy to this instance.
Template Parameters
NThe maximum size for strings.
MThe maximum size of the as argument passed string.

◆ RscVariant() [10/12]

template<int N>
template<class T >
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const T &  value)
inlineexplicit

Creates a new instance of RscVariant with an initial value.

Parameters
valueThe initial value to copy to this instance.

The RscType is deduced automatically through type deduction of T.

Template Parameters
NThe maximum size for strings.

◆ RscVariant() [11/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( const RscVariant< N > &  arg)
inline

The copy constructor.

Parameters
argThe argument to copy.
Template Parameters
NThe maximum size for strings.

◆ RscVariant() [12/12]

template<int N>
Arp::Base::Rsc::Commons::RscVariant< N >::RscVariant ( RscVariant< N > &&  arg)
inlinenoexcept

The move constructor.

Parameters
argThe argument to move.
Template Parameters
NThe maximum size for strings.

Member Function Documentation

◆ CreateArrayVariant() [1/3]

template<int N>
RscVariant< N > Arp::Base::Rsc::Commons::RscVariant< N >::CreateArrayVariant ( size_t  arraySize,
RscType  arrayElementType,
ReadElementFunction readFunction,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inlinestatic

Creates a new RscVariant representing an array for reading.

Parameters
arraySizeSize of array.
arrayElementTypeThe element type as RscType.
readFunctionThe function to read elements.
dimensionsNumber of array dimensions.
fieldCountNumber of fields if the element type is a struct type.
Returns
The new RscVariant object initialized to represent an array.
Template Parameters
NThe maximum size for strings.

◆ CreateArrayVariant() [2/3]

template<int N>
RscVariant< N > Arp::Base::Rsc::Commons::RscVariant< N >::CreateArrayVariant ( size_t  arraySize,
RscType  arrayElementType,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inlinestatic

Creates a new RscVariant representing an array.

Parameters
arraySizeSize of array.
arrayElementTypeThe element type as RscType.
dimensionsNumber of array dimensions.
fieldCountNumber of fields if the element type is a struct type.
Returns
The new RscVariant object initialized to represent an array.
Template Parameters
NThe maximum size for strings.

◆ CreateArrayVariant() [3/3]

template<int N>
RscVariant< N > Arp::Base::Rsc::Commons::RscVariant< N >::CreateArrayVariant ( size_t  arraySize,
RscType  arrayElementType,
WriteElementFunction writeFunction,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inlinestatic

Creates a new RscVariant representing an array for writing.

Parameters
arraySizeSize of array.
arrayElementTypeThe element type as RscType.
writeFunctionThe function to write elements.
dimensionsNumber of array dimensions.
fieldCountNumber of fields if the element type is a struct type.
Returns
The new RscVariant object initialized to represent an array.
Template Parameters
NThe maximum size for strings.

◆ CreateStructVariant() [1/2]

template<int N>
RscVariant< N > Arp::Base::Rsc::Commons::RscVariant< N >::CreateStructVariant ( size_t  fieldCount)
inlinestatic

Creates a new RscVariant initialized with RscStructInfo

Parameters
fieldCountCount of struct fields
Returns
Created RscVariant
Template Parameters
NThe maximum size for strings.

◆ CreateStructVariant() [2/2]

template<int N>
RscVariant< N > Arp::Base::Rsc::Commons::RscVariant< N >::CreateStructVariant ( size_t  fieldCount,
ReadElementFunction readFunction 
)
inlinestatic

Creates a new RscVariant initialized with RscStructInfo

Parameters
fieldCountCount of struct fields
readFunctionThe function to read a single element.
Returns
Created RscVariant
Template Parameters
NThe maximum size for strings.

◆ operator!=()

template<int N>
bool Arp::Base::Rsc::Commons::RscVariant< N >::operator!= ( const RscVariant< N > &  arg) const
inline

Compares this instance to arg on inequality

Parameters
argThe argument to compare this instance to.
Returns
true if arg is not equal to this instance, otherwise false.
Template Parameters
NThe maximum size for strings.

◆ operator=() [1/8]

template<int N>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const char *  value)
inline

Assign operator for type char*.

Parameters
valueThe string to assign.
Returns
A reference to this instance.
Template Parameters
NThe maximum size for strings.

◆ operator=() [2/8]

template<int N>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const char8u *  value)
inline

Assign operator for type char8u*.

Parameters
valueThe string to assign.
Returns
A reference to this instance.
Template Parameters
NThe maximum size for strings.

◆ operator=() [3/8]

template<int N = 0>
template<int M>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const RscSecureString< M > &  value)
inline

Assign operator for values of type SecureString.

Parameters
valueThe string to assign.
Template Parameters
MThe maximal string length.
NThe maximum size for strings.
Returns
This instance as reference.

◆ operator=() [4/8]

template<int N = 0>
template<int M>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const RscString< M > &  value)
inline

Assign operator for values of type RscString.

Parameters
valueThe string to assign.
Template Parameters
MThe maximal string length.
NThe maximum size for strings.
Returns
This instance as reference.

◆ operator=() [5/8]

template<int N>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const RscVariant< N > &  arg)
inline

The assign operator.

Parameters
argThe argument to assign.
Template Parameters
NThe maximum size for strings.
Returns
This instance.

◆ operator=() [6/8]

template<int N>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const String value)
inline

Assign operator for type String.

Parameters
valueThe string to assign.
Returns
A reference to this instance.
Template Parameters
NThe maximum size for strings.

◆ operator=() [7/8]

template<int N = 0>
template<class T >
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( const T &  value)
inline

Assign operator for values of arbitrary type.

Parameters
valueThe value to assign.
Template Parameters
TThe type of the value.
NThe maximum size for strings.
Returns
This instance as reference.

◆ operator=() [8/8]

template<int N>
RscVariant< N > & Arp::Base::Rsc::Commons::RscVariant< N >::operator= ( RscVariant< N > &&  arg)
inlinenoexcept

The move-assign operator.

Parameters
argThe argument to move.
Template Parameters
NThe maximum size for strings.
Returns
This instance.

◆ operator==()

template<int N>
bool Arp::Base::Rsc::Commons::RscVariant< N >::operator== ( const RscVariant< N > &  arg) const
inline

Compares this instance to arg on equality

Parameters
argThe argument to compare this instance to.
Returns
true if arg is equal to this instance, otherwise false.
Template Parameters
NThe maximum size for strings.

The documentation for this class was generated from the following files: