118 void setInt3(int32_t val1, int32_t val2, int32_t val3);
130 void setInt4(int32_t val1, int32_t val2, int32_t val3, int32_t val4);
149 void setFloat3(
float val1,
float val2,
float val3);
161 void setFloat4(
float val1,
float val2,
float val3,
float val4);
218 size_t mBufferSize{0};
219 void *mData{
nullptr};
227 assert(
nullptr != pData);
228 std::string str((
char *)pData);
232 ::memcpy(mData, pData, mBufferSize);
239 ::memcpy(mData, &value, mBufferSize);
251 ::memcpy(mData, other.mData, mBufferSize);
274 ::memcpy(mData, &value,
sizeof(
unsigned char));
278 return (*
reinterpret_cast<unsigned char *
>(mData));
284 ::memcpy(mData, &val,
sizeof(int32_t));
288 assert(mType ==
Int);
290 return (*
reinterpret_cast<int *
>(mData));
296 int *ptr =
reinterpret_cast<int *
>(mData);
305 assert(mType ==
Int3);
306 return (
reinterpret_cast<int *
>(mData));
312 int *ptr =
reinterpret_cast<int *
>(mData);
323 assert(mType ==
Int4);
325 return (
reinterpret_cast<int *
>(mData));
331 ::memcpy(mData, &val,
sizeof(
float));
335 assert(mType ==
Float);
336 return (*
reinterpret_cast<float *
>(mData));
342 float *ptr =
reinterpret_cast<float *
>(mData);
352 return (
reinterpret_cast<float *
>(mData));
358 float *ptr =
reinterpret_cast<float *
>(mData);
370 return (
reinterpret_cast<float *
>(mData));
376 ::memcpy(mData, pData,
sizeof(
float) * 16);
381 return (
reinterpret_cast<float *
>(mData));
391 mBufferSize =
sizeof(char) * (value.size() + 1);
392 mData = (
char*) ::malloc(mBufferSize);
393 if (mData ==
nullptr) {
398 ::memcpy(mData, value.c_str(),
sizeof(
char) * value.size());
399 char *ptr = (
char *) mData;
400 ptr[value.size()] =
'\0';
406 return static_cast<char *
>(mData);
412 ::memcpy(mData, &value,
sizeof(
bool));
418 return (*
reinterpret_cast<bool *
>(mData));
439 if (rOther.mType != mType) {
443 if (rOther.mBufferSize != mBufferSize) {
447 if (0 != ::memcmp(rOther.mData, mData, mBufferSize)) {
455 if (!(rOther == *
this)) {
456 mType = rOther.mType;
458 ::memcpy(mData, rOther.mData, mBufferSize);
470 }
else if (type ==
Int || type ==
Float) {
482 }
else if (type ==
String) {
496 size =
sizeof(int) * 3;
497 }
else if (type ==
Float3) {
498 size =
sizeof(float) * 3;
499 }
else if (type ==
Int4) {
500 size =
sizeof(int) * 4;
501 }
else if (type ==
Float4) {
502 size =
sizeof(float) * 4;
504 size =
sizeof(float) * 4 * 4;
505 }
else if (type ==
Byte) {
506 size =
sizeof(
unsigned char);
507 }
else if (type ==
Int) {
509 }
else if (type ==
Float) {
510 size =
sizeof(float);
517 mData = ::malloc(size);
Type
This enum describes the variable type of the variant instance.
@ Float4x4
Float matrix, 4 x 4 components.
@ Int3
Integer vector, 3 components.
@ Invalid
Initialization value.
@ Int4
Integer vector, 4 components.
@ Float4
Float vector, 4 components.
@ Float3
Float vector, 3 components.
Type getType() const
Returns the type of the instance.
bool operator==(const Variant &rOther) const
Operator implementations.
Variant()=default
The class default constructor.
void clear()
Clears the variant data, type will set back to None.
void setInt3(int32_t val1, int32_t val2, int32_t val3)
Set a new integer vector, the old data will be released and destroyed.
static Variant * createFromString(const std::string &value)
Static helper method to generate a new variant storing a std::string.
size_t getSize() const
Will return the size in bytes of the stored type.
float * getFloat4x4() const
Returns the pointer to the float 4x4 value.
~Variant()
The class destructor.
uint8_t getByte() const
Will return the current payload as a byte value.
float * getFloat3() const
Returns a pointer to the first element of the float vector.
void * getPtr() const
Will return a raw pointer showing to the data.
const char * getString() const
Returns a constant reference to the string value.
Variant & operator=(const Variant &rOther)
float getFloat() const
Returns the float value of the instance.
bool isValid(Type type, size_t numItems) const
Performs a validation.
void setFloat4x4(float *pData)
Assigns a new float 4x4 item.
void setFloat(float val)
Returns the float value of the instance.
void setByte(uint8_t value)
Will set the payload to the given value.
float * getFloat4() const
Returns a pointer to the first element of the float vector.
void reserve(Type type, size_t size)
Will reserve a buffer for the requested types.
int32_t * getInt3() const
Returns a pointer to the first element of the integer vector.
int32_t getInt() const
Returns the integer value of the instance.
void setFloat3(float val1, float val2, float val3)
Set a new float vector, the old data will be released and destroyed.
void setStdString(const std::string &value)
Sets a string value.
void setInt4(int32_t val1, int32_t val2, int32_t val3, int32_t val4)
Set a new integer vector, the old data will be released and destroyed.
void setFloat4(float val1, float val2, float val3, float val4)
Set a new float vector, the old data will be released and destroyed.
int32_t * getInt4() const
Returns a pointer to the first element of the integer vector.
void setBool(bool value)
Will set a new bool value.
void setInt(int32_t val)
Sets a new integer value, old values will be released and destroyed.
bool getBool() const
Will return the bool value.