ADTF  3.14.3
variant/variant.h
Go to the documentation of this file.
1 
21 #ifndef _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
22 #define _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
23 
24 #include <memory>
25 #include <string>
26 
27 namespace a_util {
28 namespace variant {
30 typedef enum {
31  VT_Empty = 0,
32  VT_Bool = 1,
33  VT_Int8 = 2,
34  VT_UInt8 = 3,
35  VT_Int16 = 4,
36  VT_UInt16 = 5,
37  VT_Int32 = 6,
38  VT_UInt32 = 7,
39  VT_Int64 = 8,
40  VT_UInt64 = 9,
41  VT_Float = 10,
42  VT_Double = 11,
43  VT_String = 12,
46 } VariantType;
47 
51 class Variant {
52 public:
59  Variant(bool value);
64  Variant(std::int8_t value);
69  Variant(std::uint8_t value);
74  Variant(std::int16_t value);
79  Variant(std::uint16_t value);
84  Variant(std::int32_t value);
89  Variant(std::uint32_t value);
94  Variant(std::int64_t value);
99  Variant(std::uint64_t value);
104  Variant(float value);
109  Variant(double value);
114  Variant(const char* value);
115 
120  Variant(const Variant& other);
121 
127  Variant& operator=(const Variant& other);
128 
131 
137  Variant(Variant&& other) noexcept;
138 
146  Variant& operator=(Variant&& other) noexcept;
147 
150 
155  std::size_t getArraySize() const;
156 
158  bool isArray() const;
159 
161  bool isEmpty() const;
162 
164  void reset();
165 
170  void reset(bool value);
175  void reset(std::int8_t value);
180  void reset(std::uint8_t value);
185  void reset(std::int16_t value);
190  void reset(std::uint16_t value);
195  void reset(std::int32_t value);
200  void reset(std::uint32_t value);
205  void reset(std::int64_t value);
210  void reset(std::uint64_t value);
215  void reset(float value);
220  void reset(double value);
225  void reset(const char* value);
226 
233  void reset(const bool* array_storage, std::size_t array_size);
240  void reset(const std::int8_t* array_storage, std::size_t array_size);
247  void reset(const std::uint8_t* array_storage, std::size_t array_size);
254  void reset(const std::int16_t* array_storage, std::size_t array_size);
261  void reset(const std::uint16_t* array_storage, std::size_t array_size);
268  void reset(const std::int32_t* array_storage, std::size_t array_size);
275  void reset(const std::uint32_t* array_storage, std::size_t array_size);
282  void reset(const std::int64_t* array_storage, std::size_t array_size);
289  void reset(const std::uint64_t* array_storage, std::size_t array_size);
296  void reset(const float* array_storage, std::size_t array_size);
303  void reset(const double* array_storage, std::size_t array_size);
304 
313  bool getBool(std::size_t array_index = 0) const;
315  std::int8_t getInt8(std::size_t array_index = 0) const;
317  std::uint8_t getUInt8(std::size_t array_index = 0) const;
319  std::int16_t getInt16(std::size_t array_index = 0) const;
321  std::uint16_t getUInt16(std::size_t array_index = 0) const;
323  std::int32_t getInt32(std::size_t array_index = 0) const;
325  std::uint32_t getUInt32(std::size_t array_index = 0) const;
327  std::int64_t getInt64(std::size_t array_index = 0) const;
329  std::uint64_t getUInt64(std::size_t array_index = 0) const;
331  float getFloat(std::size_t array_index = 0) const;
333  double getDouble(std::size_t array_index = 0) const;
335  float getFloat32(std::size_t array_index = 0) const;
337  double getFloat64(std::size_t array_index = 0) const;
343  const char* getString() const;
344 
350  bool asBool() const;
352  std::int8_t asInt8() const;
354  std::uint8_t asUInt8() const;
356  std::int16_t asInt16() const;
358  std::uint16_t asUInt16() const;
360  std::int32_t asInt32() const;
362  std::uint32_t asUInt32() const;
364  std::int64_t asInt64() const;
366  std::uint64_t asUInt64() const;
368  float asFloat() const;
370  double asDouble() const;
372  std::string asString() const;
373 
379  operator bool() const;
385  operator std::int8_t() const;
391  operator std::uint8_t() const;
397  operator std::int16_t() const;
403  operator std::uint16_t() const;
409  operator std::int32_t() const;
415  operator std::uint32_t() const;
421  operator std::int64_t() const;
427  operator std::uint64_t() const;
433  operator float() const;
439  operator double() const;
445  operator std::string() const;
446 
452  Variant& operator=(bool value);
458  Variant& operator=(std::int8_t value);
464  Variant& operator=(std::uint8_t value);
470  Variant& operator=(std::int16_t value);
476  Variant& operator=(std::uint16_t value);
482  Variant& operator=(std::int32_t value);
488  Variant& operator=(std::uint32_t value);
494  Variant& operator=(std::int64_t value);
500  Variant& operator=(std::uint64_t value);
506  Variant& operator=(float value);
512  Variant& operator=(double value);
518  Variant& operator=(const char* value);
519 
526  friend bool operator==(const Variant& lhs, const Variant& rhs);
527 
528 private:
529  class Implementation;
530  std::unique_ptr<Implementation> _impl;
531 };
532 
539 bool operator!=(const Variant& lhs, const Variant& rhs);
540 
541 } // namespace variant
542 } // namespace a_util
543 
544 #endif // _A_UTILS_UTIL_VARIANT_VARIANT_HEADER_INCLUDED_
Container type, able to store any primitive data type (and arrays thereof)
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.
VariantType
Enumeration of supported Variant types.
@ VT_UInt64
Variant type is std::uint64_t.
@ VT_UInt16
Variant type is std::uint16_t.
@ VT_Float
Variant type is float.
@ VT_Int8
Variant type is std::int8_t.
@ VT_Bool
Variant type is bool.
@ VT_Int16
Variant type is std::int16_t.
@ VT_UInt8
Variant type is std::uint8_t.
@ VT_Int64
Variant type is std::int64_t.
@ VT_Float64
Variant type is double.
@ VT_Double
Variant type is double.
@ VT_String
Variant type is const char*.
@ VT_Int32
Variant type is std::int32_t.
@ VT_Empty
Variant type is empty.
@ VT_Float32
Variant type is float.
@ VT_UInt32
Variant type is std::uint32_t.
Serves as the root component, with common functionality documented in core functionality.
Definition: base.h:30

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Thu Jun 9 2022 by doxygen 1.9.1)