8#include "Arp/Base/Rsc/Commons/Rsc.hpp"
9#include "Arp/Base/Rsc/Commons/RscType.hpp"
10#include "Arp/Base/Rsc/Commons/RscTypeInfo.hpp"
11#include "Arp/Base/Rsc/Commons/RscTypeDeduction.hpp"
12#include "Arp/Base/Rsc/Commons/RscArrayInfo.hpp"
13#include "Arp/Base/Rsc/Commons/RscStructInfo.hpp"
14#include "Arp/Base/Commons/Exceptions/InvalidCastException.hpp"
15#include "Arp/Base/Commons/Exceptions/NotSupportedException.hpp"
18namespace Arp::Base::Rsc::Commons::Internal
20class RscVariantAccessor;
23namespace Arp::Base::Rsc::Commons
42 friend class Arp::Base::Rsc::Commons::Internal::RscVariantAccessor;
75 void SetType(RscType value);
76 RscType GetType(
void)
const;
77 RscType GetValueType(
void)
const;
78 bool IsComplexType(
void)
const;
79 bool IsArray(
void)
const;
80 bool IsStruct(
void)
const;
81 bool IsFormattable(
void)
const;
82 size_t GetDataSize(
void)
const;
83 size_t GetMaxStringSize(
void)
const;
84 size_t GetBufferSize(
void)
const;
85 RscType GetArrayElementType(
void)
const;
86 size_t GetArraySize(
void)
const;
87 size_t GetArrayDimensions(
void)
const;
88 size_t GetArrayFieldCount(
void)
const;
89 size_t GetFieldCount(
void)
const;
90 byte* GetDataAddress(
void);
91 const byte* GetDataAddress(
void)
const;
92 const char* GetChars(
void)
const;
95 void Assign(
const char* input, RscType rscType = RscType::String);
96 void Assign(
const char* input,
size_t length, RscType rscType = RscType::String);
97 void Assign(
const char16* input,
size_t length);
98 void Assign(
const String& value);
99 void CopyTo(
String& value)
const;
100 String ToString(
void)
const;
101 void Clear(
bool clearBuffer =
false);
109 bool HasArrayInfo(
void)
const;
111 void SetArrayInfo(
size_t size, RscType elementType = RscType::None,
size_t dimensions = 1,
size_t fieldCount = 0);
114 bool HasStructInfo(
void)
const;
115 void SetStructInfo(
size_t fieldCount);
118 bool HasReadElementFunction(
void)
const;
121 bool HasWriteElementFunction(
void)
const;
124 void ResetComplexTypeInfo(
void);
127 template<
int N>
void Assign(
char value[N]);
128 template<
int N>
void Assign(
const char value[N]);
131 template<
class T>
void Assign(
const T& value);
132 template<
class T>
void CopyTo(T& value)
const;
135 template<
class T> T GetValue(
void)
const;
136 template<
class T> T* GetValueAddress(
void);
137 template<
class T>
const T* GetValueAddress(
void)
const;
140 void SetBufferInfo(
byte* pDataBuffer,
size_t dataBufferSize,
bool isDynamicString);
141 bool HasReader(
void)
const;
142 bool HasWriter(
void)
const;
149 bool ProvidesDynamicString(
void)
const;
150 String& GetDynamicString(
void);
151 const String& GetDynamicString(
void)
const;
154 static size_t DetermineBufferSize(RscType type);
157 struct ComplexTypeInfo
162 struct ComplexVariantInfo
167 ComplexVariantInfo complexVariantInfo{};
170 ReadElementFunction* pReadElementFunction =
nullptr;
171 mutable WriteElementFunction* pWriteElementFunction =
nullptr;
175 RscType type = RscType::None;
176 byte* pBuffer =
nullptr;
177 size_t bufferSize = 0;
178 bool providesDynamicString =
false;
225 if (rscType == RscType::None)
230 if constexpr (std::is_trivially_copy_assignable_v<T>&& (
alignof(T) >
alignof(
RscVariantBase)))
232 std::memcpy(GetValueAddress<T>(), std::addressof(value),
sizeof(T));
236 *this->GetValueAddress<T>() = value;
258 return reinterpret_cast<T*
>(this->
pBuffer);
267 return reinterpret_cast<const T*
>(this->
pBuffer);
279 throw InvalidCastException(
"Cannot copy value to argument: RscVariant contains data type {0} but arg is of type {1}", this->
GetType(), argType);
281 if constexpr (std::is_trivially_copy_assignable_v<T>&& (
alignof(T) >
alignof(
RscVariantBase)))
283 std::memcpy(std::addressof(value), this->GetValueAddress<T>(),
sizeof(T));
287 value = *this->GetValueAddress<T>();
302 if (this->ProvidesDynamicString())
304 value = this->GetDynamicString();
This exception is thrown when an invalid cast occurs.
Definition: InvalidCastException.hpp:17
This exception is thrown when a not supported operation is invoked.
Definition: NotSupportedException.hpp:16
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
This (meta programming) class provides the C++ type-name of the as template argument passed type.
Definition: TypeName.hxx:20
Contains information to marshal dynamic arrays.
Definition: RscArrayInfo.hpp:14
Specialized implementation of RscString for secure context.
Definition: RscSecureString.hxx:16
This class is a base class of template class RscString.
Definition: RscStringBase.hpp:27
size_t GetLength(void) const
Gets the length of this string.
Definition: RscStringBase.cpp:49
const char * CStr(void) const
Returns a const char pointer to the internal string buffer.
Definition: RscStringBase.cpp:63
void Assign(const char *pChars)
Assigns the char buffer to this instance.
Definition: RscStringBase.cpp:127
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
static constexpr RscType GetFrom(const T &)
Gets the RscType of the as argument passed parameter.
Definition: RscTypeDeduction.hpp:77
static bool IsStringType(RscType type)
Determines if the supplied RscType is a string type.
Definition: RscTypeInfo.cpp:182
This class is a base class of template class RscVariant.
Definition: RscVariantBase.hpp:41
void SetType(RscType value)
Forces the internal RscType to be set to another RscType.
Definition: RscVariantBase.cpp:139
RscVariantBase & operator=(RscVariantBase &&arg) noexcept
The move-assign operator.
const char * GetChars(void) const
Gets a readable pointer to internal string buffer.
Definition: RscVariantBase.cpp:392
~RscVariantBase(void)
The default destructor.
RscType GetType(void) const
Gets the RscType of the contained element
Definition: RscVariantBase.cpp:290
std::function< void(RscType fieldType, const RscVariantBase &value)> WriteFieldFunction
The write field delegate type.
Definition: RscVariantBase.hpp:46
RscVariantBase(RscVariantBase &&arg) noexcept
The move constructor.
std::function< void(RscType elementType, const RscVariantBase &value)> WriteElementFunction
The write element delegate type.
Definition: RscVariantBase.hpp:48
ComplexTypeInfo typeInfo
The type info of this variant.
Definition: RscVariantBase.hpp:180
T GetValue(void) const
Converts this value to the given type T .
Definition: RscVariantBase.hpp:245
RscType type
The RSC type of this variant.
Definition: RscVariantBase.hpp:175
RscVariantBase(const RscVariantBase &arg)
The copy constructor.
RscType GetValueType(void) const
Gets the raw value type as RscType of the contained element.
Definition: RscVariantBase.cpp:301
String dynamicString
The dynamic string storage.
Definition: RscVariantBase.hpp:179
std::function< void(RscType elementType, RscVariantBase &value)> ReadElementFunction
The read element delegate type.
Definition: RscVariantBase.hpp:47
byte * pBuffer
The buffer of this variant (usually applied by RscVariant<T>)
Definition: RscVariantBase.hpp:176
RscVariantBase & operator=(const RscVariantBase &arg)
The assign operator.
std::function< void(RscType fieldType, RscVariantBase &value)> ReadFieldFunction
The read field delegate type.
Definition: RscVariantBase.hpp:45
void Assign(const char *input, RscType rscType=RscType::String)
Assigns an UTF8 string to this instance.
Definition: RscVariantBase.cpp:776
void CopyTo(String &value) const
Copies the content of this variant to a string.
Definition: RscVariantBase.cpp:857
T * GetValueAddress(void)
Gets the address of the contained value as type T *.
Definition: RscVariantBase.hpp:256
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
@ Equals
Start recording if TriggerVariable1 is equal to TriggerVariable2.
@ Write
Specifies write access to the file. Data can be written to the file and the file pointer can be moved...
@ Read
Specifies read access to the file. Data can be read from the file and the file pointer can be moved....