ADTF  3.18.2
builds/digitalwerk/solutions/adtf_content/adtf_base/adtf_core/src/libraries/a_utils/include/a_utils/core/variant.h
Go to the documentation of this file.
1 
7 #ifndef _VARIANT_CLASS_HEADER_
8 #define _VARIANT_CLASS_HEADER_
9 
10 namespace A_UTILS_NS
11 {
12 
14 typedef enum : tUInt8
15 {
16  VT_Empty = 0,
17  VT_Null = 1,
18  VT_Bool = 2,
19  VT_Int8 = 3,
20  VT_UInt8 = 4,
21  VT_Int16 = 5,
22  VT_UInt16 = 6,
23  VT_Int32 = 7,
24  VT_UInt32 = 8,
25  VT_Float32 = 9,
26  VT_Float64 = 10,
27  VT_String = 11,
28  VT_Int64 = 12,
29  VT_UInt64 = 13,
30 
31  VT_Array = 0x80
32 } tVariantType;
33 
34 
35 
43 class DOEXPORT cVariant
44 {
45  public:
46  static const cVariant vEmpty;
47 
48  protected:
49  static const tUInt8 m_ui8Version;
51 
53  union
54  {
66 
78  } m_Data;
79 
82 
83  public:
90 
98  cVariant(const cVariant& oVariant);
99 
107  cVariant(tBool Value);
109  cVariant(tInt8 Value);
111  cVariant(tUInt8 Value);
113  cVariant(tInt16 Value);
117  cVariant(tInt32 Value);
121  cVariant(tInt64 Value);
129  cVariant(const cString& Value);
131  cVariant(const tChar* Value);
132 
138  virtual ~cVariant();
139 
147 
157 
167 
176  tVoid Set(const cVariant& oVariant);
177 
186  tVoid Set(tBool Value);
188  tVoid Set(tInt8 Value);
190  tVoid Set(tUInt8 Value);
192  tVoid Set(tInt16 Value);
194  tVoid Set(tUInt16 Value);
196  tVoid Set(tInt32 Value);
198  tVoid Set(tUInt32 Value);
200  tVoid Set(tInt64 Value);
202  tVoid Set(tUInt64 Value);
208  tVoid Set(const cString& Value);
210  tVoid Set(const tChar* Value);
211 
221  tVoid Set(tInt8* pArray, tSize nSize);
223  tVoid Set(tUInt8* pArray, tSize nSize);
225  tVoid Set(tInt16* pArray, tSize nSize);
227  tVoid Set(tUInt16* pArray, tSize nSize);
229  tVoid Set(tInt32* pArray, tSize nSize);
231  tVoid Set(tUInt32* pArray, tSize nSize);
233  tVoid Set(tInt64* pArray, tSize nSize);
235  tVoid Set(tUInt64* pArray, tSize nSize);
237  tVoid Set(tFloat32* pArray, tSize nSize);
239  tVoid Set(tFloat64* pArray, tSize nSize);
240 
249  tBool GetBool(tBool* pIsOk=nullptr) const;
251  tInt8 GetInt8(tBool* pIsOk=nullptr) const;
253  tUInt8 GetUInt8(tBool* pIsOk=nullptr) const;
255  tInt16 GetInt16(tBool* pIsOk=nullptr) const;
257  tUInt16 GetUInt16(tBool* pIsOk=nullptr) const;
259  tInt32 GetInt32(tBool* pIsOk=nullptr) const;
261  tUInt32 GetUInt32(tBool* pIsOk=nullptr) const;
263  tInt64 GetInt64(tBool* pIsOk=nullptr) const;
265  tUInt64 GetUInt64(tBool* pIsOk=nullptr) const;
267  tInt GetInt(tBool* pIsOk=nullptr) const;
269  tUInt GetUInt(tBool* pIsOk=nullptr) const;
271  tFloat32 GetFloat32(tBool* pIsOk=nullptr) const;
273  tFloat64 GetFloat64(tBool* pIsOk=nullptr) const;
275  tFloat64 GetFloat(tBool* pIsOk=nullptr) const;
277  const tChar* GetStringPtr(tBool* pIsOk=nullptr) const;
279  cString GetString(tBool* pIsOk=nullptr) const;
280 
289  tInt32 AsInt(tBool* pIsOk=nullptr) const;
290 
299  tFloat64 AsFloat(tBool* pIsOk=nullptr) const;
300 
309  cString AsString(tBool* pIsOk=nullptr) const;
310 
319  const tBool* GetBoolArray() const;
321  const tInt8* GetInt8Array() const;
323  const tUInt8* GetUInt8Array() const;
325  const tInt16* GetInt16Array() const;
327  const tUInt16* GetUInt16Array() const;
329  const tInt32* GetInt32Array() const;
331  const tUInt32* GetUInt32Array() const;
333  const tInt64* GetInt64Array() const;
335  const tUInt64* GetUInt64Array() const;
337  const tInt* GetIntArray() const;
339  const tUInt* GetUIntArray() const;
341  const tFloat32* GetFloat32Array() const;
343  const tFloat64* GetFloat64Array() const;
345  tVoid* GetArray() const;
346 
355  tBool IsArray() const;
356 
365  tBool IsInt() const;
366 
367 
376  tBool IsFloat() const;
377 
386  tBool IsBool() const;
387 
396  tBool IsString() const;
397 
406  tBool IsIntArray() const;
407 
417 
427 
436  tBool IsEmpty() const;
437 
445  operator tBool() const;
447  operator tInt8() const;
449  operator tUInt8() const;
451  operator tInt16() const;
453  operator tUInt16() const;
455  operator tInt32() const;
457  operator tUInt32() const;
459  operator tInt64() const;
461  operator tUInt64() const;
463  operator tFloat32() const;
465  operator tFloat64() const;
467  operator const cString() const;
469  operator const tChar*() const;
470 
479  cVariant& operator=(const cVariant& Value);
481  cVariant& operator=(const tBool Value);
483  cVariant& operator=(const tInt8 Value);
485  cVariant& operator=(const tUInt8 Value);
487  cVariant& operator=(const tInt16 Value);
489  cVariant& operator=(const tUInt16 Value);
491  cVariant& operator=(const tInt32 Value);
493  cVariant& operator=(const tUInt32 Value);
495  cVariant& operator=(const tInt64 Value);
497  cVariant& operator=(const tUInt64 Value);
499  cVariant& operator=(const tFloat32 Value);
501  cVariant& operator=(const tFloat64 Value);
503  cVariant& operator=(const cString& Value);
505  cVariant& operator=(const tChar* Value);
506 
517  static tResult Serialize(cVariant& oVariant, tVoid* pWriteBuffer, tSize szSize, tSize* pszWriteSize=nullptr);
528  static tResult Deserialize(cVariant& oVariant, tVoid* pReadBuffer, tSize szSize, tSize* pszReadSize=nullptr);
529 
530  protected:
538 
546 };
547 
548 bool operator==(const cVariant& a, const cVariant& b);
549 bool operator!=(const cVariant& a, const cVariant& b);
550 
551 } // namespace A_UTILS_NS
552 
553 #endif // _VARIANT_CLASS_HEADER_
uint8_t tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
int64_t tInt64
type definition for signed integer values (64bit) (platform and compiler independent type).
int16_t tInt16
type definition for signed integer values (16bit) (platform and compiler independent type).
int32_t tInt32
type definition for signed integer values (32bit) (platform and compiler independent type).
unsigned int tUInt
type definition for unsigned integer value (platform and compiler dependent type).
float tFloat32
type definition for Float32 (32bit float values) (platform and compiler independent type).
void tVoid
The tVoid is always the definition for the void (non-type).
uint16_t tUInt16
type definition for unsigned integer values (16bit) (platform and compiler independent type).
int tInt
type definition for signed integer value (platform and compiler dependent type).
double tFloat64
type definition for Float64 (64bit double values) (platform and compiler independent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
uint32_t tUInt32
type definition for unsigned integer values (32bit) (platform and compiler independent type).
size_t tSize
type definition for a array size values, map size values etc.
int8_t tInt8
type definition for signed integer values (8bit) (platform and compiler independent type).
uint64_t tUInt64
type definition for unsigned integer values (64bit) (platform and compiler independent type).
cVariant & operator=(const tBool Value)
Sets the variant value and the type.
static tResult Deserialize(cVariant &oVariant, tVoid *pReadBuffer, tSize szSize, tSize *pszReadSize=nullptr)
Deserialization method.
const tUInt64 * GetUInt64Array() const
Get pointer to the array buffer.
tVoid Set(tUInt64 Value)
Sets the variant value and the type.
tVoid Set(tInt8 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
cVariant & operator=(const tInt64 Value)
Sets the variant value and the type.
tUInt64 GetUInt64(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
const tFloat64 * GetFloat64Array() const
Get pointer to the array buffer.
tVoid Set(const tChar *Value)
Sets the variant value and the type.
virtual ~cVariant()
Destructor.
tVoid Set(tUInt16 Value)
Sets the variant value and the type.
tVoid Set(tInt8 Value)
Sets the variant value and the type.
tVoid Set(const cString &Value)
Sets the variant value and the type.
cVariant(tFloat64 Value)
Constructor that initializes the variant with a certain type and value.
const tUInt16 * GetUInt16Array() const
Get pointer to the array buffer.
tVoid Set(tFloat32 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
cVariant & operator=(const tUInt32 Value)
Sets the variant value and the type.
tVoid Set(tBool Value)
Sets the variant value and the type.
cVariant & operator=(const tFloat64 Value)
Sets the variant value and the type.
cVariant(tUInt8 Value)
Constructor that initializes the variant with a certain type and value.
cVariant(tInt8 Value)
Constructor that initializes the variant with a certain type and value.
const tInt8 * GetInt8Array() const
Get pointer to the array buffer.
const tInt16 * GetInt16Array() const
Get pointer to the array buffer.
tInt64 GetInt64(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tFloat64 GetFloat(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
const tInt * GetIntArray() const
Get pointer to the array buffer.
tVoid Set(tInt64 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
tBool GetBool(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tBool IsString() const
This function checks, if the variant is a string.
cVariant()
Constructor that initializes an empty cVariant object.
cVariant & operator=(const tInt16 Value)
Sets the variant value and the type.
tFloat64 GetFloat64(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tBool IsFloatArray() const
This function checks, if the variant is a float [ tFloat(32/36) ] array.
tBool IsIntArray() const
This function checks, if the variant is an integer [ (U)Int(8/16/32/64) ] array.
tVoid Set(tInt16 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
tVoid Set(tUInt32 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
const tUInt * GetUIntArray() const
Get pointer to the array buffer.
tUInt GetUInt(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tVoid Initialize()
Initializes the object.
tVoid Set(tUInt32 Value)
Sets the variant value and the type.
tVoid Set(tInt32 Value)
Sets the variant value and the type.
tInt8 GetInt8(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
const tInt32 * GetInt32Array() const
Get pointer to the array buffer.
cVariant & operator=(const tUInt64 Value)
Sets the variant value and the type.
tInt GetInt(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
const tBool * GetBoolArray() const
Get pointer to the array buffer.
cVariant(tUInt32 Value)
Constructor that initializes the variant with a certain type and value.
tVoid * GetArray() const
Get pointer to the array buffer.
const tUInt8 * GetUInt8Array() const
Get pointer to the array buffer.
cVariant(const tChar *Value)
Constructor that initializes the variant with a certain type and value.
tVoid Set(tUInt8 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
tInt16 GetInt16(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tBool IsInt() const
This function checks, if the variant is an integer, that is (U)Int(8/16/32/64)
tBool IsStringArray() const
This function checks, if the variant is a string array.
tVoid Set(tInt16 Value)
Sets the variant value and the type.
tSize GetArraySize() const
This function returns the size of an array type variant.
tFloat32 GetFloat32(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
cVariant(tUInt16 Value)
Constructor that initializes the variant with a certain type and value.
cString GetString(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
cVariant & operator=(const cString &Value)
Sets the variant value and the type.
tUInt16 GetUInt16(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
cString AsString(tBool *pIsOk=nullptr) const
Converts the variant value to cString if neccessary.
static tResult Serialize(cVariant &oVariant, tVoid *pWriteBuffer, tSize szSize, tSize *pszWriteSize=nullptr)
Serialization method.
tBool IsArray() const
This function checks, if the variant is an array.
tInt32 AsInt(tBool *pIsOk=nullptr) const
Converts the variant value to tInt if neccessary.
cVariant(tInt32 Value)
Constructor that initializes the variant with a certain type and value.
tVoid Free()
Frees internally used memory structures.
tVoid Clear()
Frees all internal buffers used by the cVariant object and mark the instance as empty.
cVariant & operator=(const cVariant &Value)
Sets the variant value and the type.
tUInt8 GetUInt8(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tVoid Set(tUInt64 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
tVariantType GetType() const
This function returns the variant type.
tVoid Set(tInt32 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
tVoid Set(const cVariant &oVariant)
Assigns a new value to a cVariant object.
tBool IsFloat() const
This function checks, if the variant is a float, that is tFloat(32,64).
const tUInt32 * GetUInt32Array() const
Get pointer to the array buffer.
tVoid Set(tUInt8 Value)
Sets the variant value and the type.
cVariant(tBool Value)
Constructor that initializes the variant with a certain type and value.
cVariant & operator=(const tFloat32 Value)
Sets the variant value and the type.
tBool IsEmpty() const
This function checks, if the variant object is empty.
const tFloat32 * GetFloat32Array() const
Get pointer to the array buffer.
cVariant & operator=(const tUInt8 Value)
Sets the variant value and the type.
cVariant(const cString &Value)
Constructor that initializes the variant with a certain type and value.
cVariant & operator=(const tInt8 Value)
Sets the variant value and the type.
tFloat64 AsFloat(tBool *pIsOk=nullptr) const
Converts the variant value to tFloat64 if neccessary.
cVariant(const cVariant &oVariant)
Constructor that initializes the variant with an existing cVariant object.
tVoid Set(tFloat64 Value)
Sets the variant value and the type.
cVariant(tUInt64 Value)
Constructor that initializes the variant with a certain type and value.
tBool IsBool() const
This function checks, if the variant is a bool.
tVoid Set(tInt64 Value)
Sets the variant value and the type.
const tInt64 * GetInt64Array() const
Get pointer to the array buffer.
tInt32 GetInt32(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
tVoid Set(tFloat64 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
cVariant & operator=(const tUInt16 Value)
Sets the variant value and the type.
cVariant & operator=(const tInt32 Value)
Sets the variant value and the type.
tUInt32 GetUInt32(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
cVariant(tInt64 Value)
Constructor that initializes the variant with a certain type and value.
cVariant(tInt16 Value)
Constructor that initializes the variant with a certain type and value.
tVoid Set(tUInt16 *pArray, tSize nSize)
Assigns an array as variant value and sets the variant type.
cVariant & operator=(const tChar *Value)
Sets the variant value and the type.
tVoid Set(tFloat32 Value)
Sets the variant value and the type.
const tChar * GetStringPtr(tBool *pIsOk=nullptr) const
Get variant value as TYPE.
cVariant(tFloat32 Value)
Constructor that initializes the variant with a certain type and value.
ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
Definition: d_ptr.h:11
tBool operator==(const cMultiArrayIndex &o_A, const cMultiArrayIndex &o_B)
Comparison operator.
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
tBool operator!=(const cMultiArrayIndex &o_A, const cMultiArrayIndex &o_B)
Comparison operator.