PLCnext API Documentation  22.9.0.33
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
Arp::System::Rsc::Services::RscVariant< MaxStringSize > Class Template Reference

Rsc container class for 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>

Public Types

using ReadElementFunction = std::function< RscType(RscType expectedType, byte *pValue)>
 
using WriteElementFunction = std::function< void(RscType valueType, const byte *pValue)>
 
using Uuid = Arp::System::Commons::Configuration::Uuid
 

Public Member Functions

 RscVariant (RscType type=RscType::None)
 Creates an empty instance of RscVariant More...
 
template<class T >
 RscVariant (const T &value)
 Creates a new instance of RscVariant with value. Gets RscType by type deduction of T. More...
 
 RscVariant (const String &value)
 Creates a new instance of RscVariant with value. RscType is Utf8String. More...
 
 RscVariant (const char *value)
 Creates a new instance of RscVariant with value. RscType is Utf8String. More...
 
 RscVariant (const char16 *input, size_t length, RscType type=RscType::Utf8String)
 Assigns an UTF16 string to this instance. More...
 
template<int N>
 RscVariant (const RscString< N > &value)
 Creates a new instance of RscVariant with value. RscType is Utf8String. More...
 
template<int N>
 RscVariant (const SecureString< N > &value)
 Creates a new instance of RscVariant with value. RscType is Utf8String. More...
 
 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 arrayElementType. Instances created with this constructor are used to to initialize RscArrayWriter to write an array. More...
 
 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 arrayElementType. Instances created with this constructor are used to to initialize RscArrayReader in service implementations to write array data. More...
 
 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 arrayElementType. Instances created with this constructor are used to to initialize RscArrayWriter in service implementations to read array data. More...
 
 RscVariant (size_t fieldCount, ReadElementFunction *pFunction)
 For internal use only More...
 
 RscVariant (const RscVariant< MaxStringSize > &)=default
 Copy constructor More...
 
 RscVariant (RscVariant &&) noexcept=default
 Move constructor More...
 
template<class T >
RscVariantoperator= (const T &value)
 
RscVariantoperator= (const String &value)
 
RscVariantoperator= (const char *value)
 
template<int N>
RscVariantoperator= (const RscString< N > &value)
 
template<int N>
RscVariantoperator= (const SecureString< N > &value)
 
RscVariantoperator= (const RscVariant &value)=default
 
RscVariantoperator= (RscVariant &&) noexcept=default
 
bool operator== (const RscVariant &value) const
 
bool operator!= (const RscVariant &value) const
 
RscType GetType (void) const
 Gets the RscType of the contained element More...
 
RscType GetValueType (void) const
 Gets the value type as RscType of the contained element More...
 
RscType GetArrayElementType (void) const
 Gets the RscType of the array elements if RscVariant contains array information. More...
 
size_t GetArrayDimensions (void) const
 Gets the count of array dimensions (1 for simple array, 2 for array of array etc.). This method is only valid for RscVariants with array information. More...
 
size_t GetFieldCount (void) const
 Returns field count, if RscVariant contains struct information More...
 
const char * GetChars (void) const
 Gets pointer to internal string buffer. Operation only valid for Utf8Strings. More...
 
void SetWriteElementFunction (WriteElementFunction *pFunction) const
 Sets callback for write function to write a single array element. This could only be used for Variants containing an array info. More...
 
const byteGetDataAddress (void) const
 Gets a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment operators because this method doesn't do any validation checks. More...
 
byteGetDataAddress (void)
 Get a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment operators because this method doesn't do any validation checks. More...
 
void SetType (RscType rscType)
 Forces the internal RscType to be set to another RscType. This Method does no conversion or validation. Prefer using assignment operators, who sets the RscType implicitly. More...
 
template<class T >
GetValue (void) const
 Converts this value to the given type T. More...
 
template<class T >
void CopyTo (T &value) const
 Copies internal data to memory referenced by value. Only for primtive types. Read Strings with GetChars. More...
 
String ToString (void) const
 Converts this instance to string if the variant type has a reasonable string representation. More...
 
void Assign (const char16 *input, size_t length, RscType rscType=RscType::Utf8String)
 Assigns an UTF16 string to this instance. More...
 
template<class T >
RscVariant< MaxStringSize > & operator= (const T &value)
 
template<int N>
RscVariant< MaxStringSize > & operator= (const RscString< N > &value)
 
template<int N>
RscVariant< MaxStringSize > & operator= (const SecureString< N > &value)
 

Static Public Member Functions

static RscVariant< MaxStringSize > CreateStructVariant (size_t fieldCount)
 Creates a new RscVariant initialized with RscStructInformation More...
 
static RscVariant< MaxStringSize > CreateArrayVariant (size_t arraySize, RscType elementType, size_t dimensions=1, size_t fieldCount=0)
 Creates a new RscVariant initialized with RscArrayInformation More...
 

Friends

class RscArrayReader
 
class RscArrayWriter
 
template<int N>
class RscStructReader
 
template<int N>
class RscStructWriter
 
template<class T , bool IsClass, bool IsSerializable>
class RscValueAdapter
 
template<int N>
class SecureString
 

Detailed Description

template<int MaxStringSize = 0>
class Arp::System::Rsc::Services::RscVariant< MaxStringSize >

Rsc container class for 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
MaxStringSizeSets the maximum amount of characters for included strings. A RscVariant with dafault value 0 cannot contain string values.

Constructor & Destructor Documentation

◆ RscVariant() [1/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( RscType  type = RscType::None)
inline

Creates an empty instance of RscVariant

Parameters
typeInitial RscType

◆ RscVariant() [2/13]

template<int MaxStringSize>
template<class T >
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const T &  value)
inline

Creates a new instance of RscVariant with value. Gets RscType by type deduction of T.

◆ RscVariant() [3/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const String value)
inline

Creates a new instance of RscVariant with value. RscType is Utf8String.

Parameters
valueReference to Arp::String value

◆ RscVariant() [4/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const char *  value)
inline

Creates a new instance of RscVariant with value. RscType is Utf8String.

Parameters
valueReference to c-string value

◆ RscVariant() [5/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const char16 input,
size_t  length,
RscType  type = RscType::Utf8String 
)
inline

Assigns an UTF16 string to this instance.

Parameters
inputThe input UTF16 string to assign.
lengthThe string length of the input string (number of char16 characters).
typeThe RscType marshalling type. Actually only RscType::Utf8String is supported.

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

◆ RscVariant() [6/13]

template<int MaxStringSize>
template<int N>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const RscString< N > &  value)
inline

Creates a new instance of RscVariant with value. RscType is Utf8String.

Parameters
valueReference to RscString value

◆ RscVariant() [7/13]

template<int MaxStringSize>
template<int N>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const SecureString< N > &  value)
inline

Creates a new instance of RscVariant with value. RscType is Utf8String.

Parameters
valueReference to SecureString value

◆ RscVariant() [8/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( size_t  arraySize,
RscType  arrayElementType,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inline

Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElementType. Instances created with this constructor are used to to initialize RscArrayWriter to write an array.

Parameters
arraySizeNumber of array elements
arrayElementTypeRscType of array elements
dimsionsCount of array dimensions.
fieldCountCount of fields if struct type is used

◆ RscVariant() [9/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( size_t  arraySize,
RscType  arrayElementType,
ReadElementFunction *  pFunction,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inline

Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElementType. Instances created with this constructor are used to to initialize RscArrayReader in service implementations to write array data.

Parameters
arraySizeNumber of array elements
arrayElementTypeRscType of array elements
pFunctionCallback to write an array elements
dimsionsCount of array dimensions.
fieldCountCount of fields if struct type is used

◆ RscVariant() [10/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( size_t  arraySize,
RscType  arrayElementType,
WriteElementFunction *  pFunction,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inline

Creates a new instance of RscVariant containing an array with arraySize elements of RscType arrayElementType. Instances created with this constructor are used to to initialize RscArrayWriter in service implementations to read array data.

Parameters
arraySizeNumber of array elements
arrayElementTypeRscType of array elements
pFunctionCallback to read an array element
dimsionsCount of array dimensions.
fieldCountCount of fields if struct type is used

◆ RscVariant() [11/13]

template<int MaxStringSize>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( size_t  fieldCount,
ReadElementFunction *  pFunction 
)
inline

For internal use only

◆ RscVariant() [12/13]

template<int MaxStringSize = 0>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( const RscVariant< MaxStringSize > &  )
default

Copy constructor

◆ RscVariant() [13/13]

template<int MaxStringSize = 0>
Arp::System::Rsc::Services::RscVariant< MaxStringSize >::RscVariant ( RscVariant< MaxStringSize > &&  )
defaultnoexcept

Move constructor

Member Function Documentation

◆ Assign()

template<int MaxStringSize>
void Arp::System::Rsc::Services::RscVariant< MaxStringSize >::Assign ( const char16 input,
size_t  length,
RscType  rscType = RscType::Utf8String 
)
inline

Assigns an UTF16 string to this instance.

Parameters
inputThe input UTF16 string to assign.
lengthThe string length of the input string (number of char16 characters).
typeThe RscType marshalling type. Actually only RscType::Utf8String is supported.

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

◆ CopyTo()

template<int MaxStringSize>
template<class T >
void Arp::System::Rsc::Services::RscVariant< MaxStringSize >::CopyTo ( T &  value) const
inline

Copies internal data to memory referenced by value. Only for primtive types. Read Strings with GetChars.

Parameters
valueReference to memory

◆ CreateArrayVariant()

template<int MaxStringSize>
RscVariant< MaxStringSize > Arp::System::Rsc::Services::RscVariant< MaxStringSize >::CreateArrayVariant ( size_t  arraySize,
RscType  elementType,
size_t  dimensions = 1,
size_t  fieldCount = 0 
)
inlinestatic

Creates a new RscVariant initialized with RscArrayInformation

Parameters
arraySizeCount of array elements
elementTypeElement type of array
dimensionsDimensions fo array
fieldCountCount of struct fields for struct element types
Returns
Created RscVariant

◆ CreateStructVariant()

template<int MaxStringSize>
RscVariant< MaxStringSize > Arp::System::Rsc::Services::RscVariant< MaxStringSize >::CreateStructVariant ( size_t  fieldCount)
inlinestatic

Creates a new RscVariant initialized with RscStructInformation

Parameters
fieldCountCount of struct fields
Returns
Created RscVariant

◆ GetArrayDimensions()

template<int MaxStringSize>
size_t Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetArrayDimensions ( void  ) const
inline

Gets the count of array dimensions (1 for simple array, 2 for array of array etc.). This method is only valid for RscVariants with array information.

Exceptions
InvalidOperationExceptionThrows if RscVariant doesn't contain array information
Returns
Count of array dimensions

◆ GetArrayElementType()

template<int MaxStringSize>
RscType Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetArrayElementType ( void  ) const
inline

Gets the RscType of the array elements if RscVariant contains array information.

Exceptions
InvalidOperationExceptionThrows if RscVariant doesn't contain array information
Returns
RscType of array elements

◆ GetChars()

template<int MaxStringSize>
const char * Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetChars ( void  ) const
inline

Gets pointer to internal string buffer. Operation only valid for Utf8Strings.

Returns
Pointer to string buffer

◆ GetDataAddress() [1/2]

template<int MaxStringSize = 0>
byte* Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetDataAddress ( void  )

Get a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment operators because this method doesn't do any validation checks.

Returns
Pointer to internal buffer

◆ GetDataAddress() [2/2]

template<int MaxStringSize>
const byte * Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetDataAddress ( void  ) const
inline

Gets a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment operators because this method doesn't do any validation checks.

Returns
Pointer to internal buffer

◆ GetFieldCount()

template<int MaxStringSize>
size_t Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetFieldCount ( void  ) const
inline

Returns field count, if RscVariant contains struct information

Exceptions
InvalidOperationExceptionThrows if RscVariant doesn't contain struct information
Returns
Field count of struct

◆ GetType()

template<int MaxStringSize>
RscType Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetType ( void  ) const
inline

Gets the RscType of the contained element

Returns
RscType of contained element

◆ GetValue()

template<int MaxStringSize>
template<class T >
T Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetValue ( void  ) const
inline

Converts this value to the given type T.

Template Parameters
TThe type to convert this instance to.

◆ GetValueType()

template<int MaxStringSize>
RscType Arp::System::Rsc::Services::RscVariant< MaxStringSize >::GetValueType ( void  ) const
inline

Gets the value type as RscType of the contained element

Returns
The value type as RscType of the contained element

◆ SetType()

template<int MaxStringSize>
void Arp::System::Rsc::Services::RscVariant< MaxStringSize >::SetType ( RscType  rscType)
inline

Forces the internal RscType to be set to another RscType. This Method does no conversion or validation. Prefer using assignment operators, who sets the RscType implicitly.

Parameters
rscType

◆ SetWriteElementFunction()

template<int MaxStringSize>
void Arp::System::Rsc::Services::RscVariant< MaxStringSize >::SetWriteElementFunction ( WriteElementFunction *  pFunction) const
inline

Sets callback for write function to write a single array element. This could only be used for Variants containing an array info.

Parameters
pFunctionReference to function
Exceptions
InvalidOperationExceptionThrows if RscType is not Array

◆ ToString()

template<int MaxStringSize>
String Arp::System::Rsc::Services::RscVariant< MaxStringSize >::ToString ( void  ) const
inline

Converts this instance to string if the variant type has a reasonable string representation.

Returns
Pointer to string buffer

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