ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/a_util/variant/variant.h
Go to the documentation of this file.
1 
15 #ifndef _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
16 #define _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
17 
18 #include <memory>
19 #include <string>
20 #include <cstdint>
21 
22 namespace a_util {
23 namespace variant {
25 typedef enum {
26  VT_Empty = 0,
27  VT_Bool = 1,
28  VT_Int8 = 2,
29  VT_UInt8 = 3,
30  VT_Int16 = 4,
31  VT_UInt16 = 5,
32  VT_Int32 = 6,
33  VT_UInt32 = 7,
34  VT_Int64 = 8,
35  VT_UInt64 = 9,
36  VT_Float = 10,
37  VT_Double = 11,
38  VT_String = 12,
41 } VariantType;
42 
46 class Variant {
47 public:
54  Variant(bool value);
59  Variant(std::int8_t value);
64  Variant(std::uint8_t value);
69  Variant(std::int16_t value);
74  Variant(std::uint16_t value);
79  Variant(std::int32_t value);
84  Variant(std::uint32_t value);
89  Variant(std::int64_t value);
94  Variant(std::uint64_t value);
99  Variant(float value);
104  Variant(double value);
109  Variant(const char* value);
110 
115  Variant(const Variant& other);
116 
122  Variant& operator=(const Variant& other);
123 
126 
132  Variant(Variant&& other) noexcept;
133 
141  Variant& operator=(Variant&& other) noexcept;
142 
145 
150  std::size_t getArraySize() const;
151 
153  bool isArray() const;
154 
156  bool isEmpty() const;
157 
159  void reset();
160 
165  void reset(bool value);
170  void reset(std::int8_t value);
175  void reset(std::uint8_t value);
180  void reset(std::int16_t value);
185  void reset(std::uint16_t value);
190  void reset(std::int32_t value);
195  void reset(std::uint32_t value);
200  void reset(std::int64_t value);
205  void reset(std::uint64_t value);
210  void reset(float value);
215  void reset(double value);
220  void reset(const char* value);
221 
228  void reset(const bool* array_storage, std::size_t array_size);
235  void reset(const std::int8_t* array_storage, std::size_t array_size);
242  void reset(const std::uint8_t* array_storage, std::size_t array_size);
249  void reset(const std::int16_t* array_storage, std::size_t array_size);
256  void reset(const std::uint16_t* array_storage, std::size_t array_size);
263  void reset(const std::int32_t* array_storage, std::size_t array_size);
270  void reset(const std::uint32_t* array_storage, std::size_t array_size);
277  void reset(const std::int64_t* array_storage, std::size_t array_size);
284  void reset(const std::uint64_t* array_storage, std::size_t array_size);
291  void reset(const float* array_storage, std::size_t array_size);
298  void reset(const double* array_storage, std::size_t array_size);
299 
308  bool getBool(std::size_t array_index = 0) const;
310  std::int8_t getInt8(std::size_t array_index = 0) const;
312  std::uint8_t getUInt8(std::size_t array_index = 0) const;
314  std::int16_t getInt16(std::size_t array_index = 0) const;
316  std::uint16_t getUInt16(std::size_t array_index = 0) const;
318  std::int32_t getInt32(std::size_t array_index = 0) const;
320  std::uint32_t getUInt32(std::size_t array_index = 0) const;
322  std::int64_t getInt64(std::size_t array_index = 0) const;
324  std::uint64_t getUInt64(std::size_t array_index = 0) const;
326  float getFloat(std::size_t array_index = 0) const;
328  double getDouble(std::size_t array_index = 0) const;
330  float getFloat32(std::size_t array_index = 0) const;
332  double getFloat64(std::size_t array_index = 0) const;
338  const char* getString() const;
339 
345  bool asBool() const;
347  std::int8_t asInt8() const;
349  std::uint8_t asUInt8() const;
351  std::int16_t asInt16() const;
353  std::uint16_t asUInt16() const;
355  std::int32_t asInt32() const;
357  std::uint32_t asUInt32() const;
359  std::int64_t asInt64() const;
361  std::uint64_t asUInt64() const;
363  float asFloat() const;
365  double asDouble() const;
367  std::string asString() const;
368 
374  operator bool() const;
380  operator std::int8_t() const;
386  operator std::uint8_t() const;
392  operator std::int16_t() const;
398  operator std::uint16_t() const;
404  operator std::int32_t() const;
410  operator std::uint32_t() const;
416  operator std::int64_t() const;
422  operator std::uint64_t() const;
428  operator float() const;
434  operator double() const;
440  operator std::string() const;
441 
447  Variant& operator=(bool value);
453  Variant& operator=(std::int8_t value);
459  Variant& operator=(std::uint8_t value);
465  Variant& operator=(std::int16_t value);
471  Variant& operator=(std::uint16_t value);
477  Variant& operator=(std::int32_t value);
483  Variant& operator=(std::uint32_t value);
489  Variant& operator=(std::int64_t value);
495  Variant& operator=(std::uint64_t value);
501  Variant& operator=(float value);
507  Variant& operator=(double value);
513  Variant& operator=(const char* value);
514 
521  friend bool operator==(const Variant& lhs, const Variant& rhs);
522 
523 private:
524  class Implementation;
525  std::unique_ptr<Implementation> _impl;
526 };
527 
534 bool operator!=(const Variant& lhs, const Variant& rhs);
535 
536 } // namespace variant
537 } // namespace a_util
538 
539 #endif // _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
Variant & operator=(std::int8_t value)
Assignment operator for implicit type conversion to VT_Int8.
void reset(const std::uint16_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_UInt16.
std::int32_t getInt32(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
void reset(const float *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Float.
float getFloat32(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
std::uint32_t getUInt32(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
Variant(const Variant &other)
Copy CTOR.
double getFloat64(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
void reset(const std::uint8_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_UInt8.
float getFloat(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
Variant(std::uint8_t value)
CTOR: VT_UInt8.
std::string asString() const
Convert the value of the variant.
Variant & operator=(double value)
Assignment operator for implicit type conversion to VT_Double.
bool getBool(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
const char * getString() const
Get current string value.
std::uint16_t asUInt16() const
Convert the value of the variant.
Variant & operator=(std::uint8_t value)
Assignment operator for implicit type conversion to VT_UInt8.
void reset(const char *value)
Resets the instance to VT_String.
Variant()
CTOR: VT_Empty.
void reset(std::uint64_t value)
Resets the instance to VT_UInt64.
std::int8_t asInt8() const
Convert the value of the variant.
void reset(std::uint8_t value)
Resets the instance to VT_UInt8.
std::uint16_t getUInt16(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
void reset(std::int64_t value)
Resets the instance to VT_Int64.
std::int8_t getInt8(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
void reset(bool value)
Resets the instance to VT_Bool.
double getDouble(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
Variant & operator=(const char *value)
Assignment operator for implicit type conversion to VT_String.
void reset(const std::uint64_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_UInt64.
void reset(std::uint16_t value)
Resets the instance to VT_UInt16.
Variant(const char *value)
CTOR: VT_String.
void reset(float value)
Resets the instance to VT_Float.
void reset(std::int8_t value)
Resets the instance to VT_Int8.
void reset(const std::int8_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Int8.
Variant(bool value)
CTOR: VT_Bool.
std::uint64_t asUInt64() const
Convert the value of the variant.
~Variant()
Non-virtual DTOR.
Variant(float value)
CTOR: VT_Float32.
Variant & operator=(std::int64_t value)
Assignment operator for implicit type conversion to VT_Int64.
Variant(std::uint16_t value)
CTOR: VT_UInt16.
Variant(double value)
CTOR: VT_Float64.
float asFloat() const
Convert the value of the variant.
void reset(const std::int64_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Int64.
Variant(std::uint64_t value)
CTOR: VT_UInt64.
Variant & operator=(const Variant &other)
Assignment operator.
Variant(std::int64_t value)
CTOR: VT_Int64.
Variant & operator=(std::uint32_t value)
Assignment operator for implicit type conversion to VT_UInt32.
bool asBool() const
Convert the value of the variant.
Variant(std::uint32_t value)
CTOR: VT_UInt32.
std::uint8_t asUInt8() const
Convert the value of the variant.
VariantType getType() const
Returns the current underlying data type of the instance.
Variant & operator=(std::int16_t value)
Assignment operator for implicit type conversion to VT_Int16.
std::int16_t asInt16() const
Convert the value of the variant.
std::uint8_t getUInt8(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
friend bool operator==(const Variant &lhs, const Variant &rhs)
Compare for equality.
std::uint64_t getUInt64(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
std::int16_t getInt16(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
Variant(std::int8_t value)
CTOR: VT_Int8.
Variant & operator=(bool value)
Assignment operator for implicit type conversion to VT_Bool.
double asDouble() const
Convert the value of the variant.
std::size_t getArraySize() const
Get the current array size of the instance.
Variant(std::int32_t value)
CTOR: VT_Int32.
std::int64_t asInt64() const
Convert the value of the variant.
void reset(const bool *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Bool.
bool isEmpty() const
Returns whether the instance is in the empty state (VT_Empty)
Variant & operator=(std::int32_t value)
Assignment operator for implicit type conversion to VT_Int32.
void reset()
Resets the instance to VT_Empty.
Variant & operator=(std::uint64_t value)
Assignment operator for implicit type conversion to VT_UInt64.
Variant(Variant &&other) noexcept
Move CTOR.
void reset(std::int32_t value)
Resets the instance to VT_Int32.
Variant & operator=(float value)
Assignment operator for implicit type conversion to VT_Float.
void reset(std::int16_t value)
Resets the instance to VT_Int16.
Variant & operator=(Variant &&other) noexcept
Move assignment.
void reset(std::uint32_t value)
Resets the instance to VT_UInt32.
std::uint32_t asUInt32() const
Convert the value of the variant.
Variant & operator=(std::uint16_t value)
Assignment operator for implicit type conversion to VT_UInt16.
bool isArray() const
Returns whether the instance stores an array of any kind.
void reset(const std::uint32_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_UInt32.
std::int32_t asInt32() const
Convert the value of the variant.
void reset(const std::int32_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Int32.
void reset(double value)
Resets the instance to VT_Double.
Variant(std::int16_t value)
CTOR: VT_Int16.
void reset(const double *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Double.
std::int64_t getInt64(std::size_t array_index=0) const
Get current value or alternatively from an array index of the variants value.
void reset(const std::int16_t *array_storage, std::size_t array_size)
Resets the instance to an array of VT_Int16.
bool operator!=(const Variant &lhs, const Variant &rhs)
Compare for inequality.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:24