14 #define ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(_type_, _getter_functionname_) \
17 inline _type_ GetArrayValueByType(const a_util::variant::Variant& oValue, size_t nIdx, _type_ ) \
19 return (&(oValue))->_getter_functionname_(nIdx); \
23 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(int8_t, getInt8)
24 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(uint8_t, getUInt8)
25 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(int16_t, getInt16)
26 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(uint16_t, getUInt16)
27 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(int32_t, getInt32)
28 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(uint32_t, getUInt32)
29 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(int64_t, getInt64)
30 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(uint64_t, getUInt64)
31 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(
bool, getBool)
32 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(
float, getFloat)
33 ADTF_DEFINE_GET_AUTIL_VARIANT_VALUE_BY_TYPE(
double, getDouble)
35 template<
typename T,
typename U = T>
38 cVariant oResultVariant;
41 oResultVariant.Set(
static_cast<T
>(oValue));
45 std::vector<U> oValueArray;
46 for (
size_t nIdx = 0; nIdx < oValue.
getArraySize(); ++nIdx)
48 oValueArray.push_back(detail::GetArrayValueByType(oValue, nIdx, U{}));
50 oResultVariant.Set(
static_cast<U*
>(oValueArray.data()), oValueArray.size());
52 return oResultVariant;
57 cVariant oResultVariant;
61 oResultVariant = ConvertToADTFVariantByType<bool, uint8_t>(oValue);
64 oResultVariant = ConvertToADTFVariantByType<double>(oValue);
67 oResultVariant = ConvertToADTFVariantByType<float>(oValue);
70 oResultVariant = ConvertToADTFVariantByType<int8_t>(oValue);
73 oResultVariant = ConvertToADTFVariantByType<uint8_t>(oValue);
76 oResultVariant = ConvertToADTFVariantByType<int16_t>(oValue);
79 oResultVariant = ConvertToADTFVariantByType<uint16_t>(oValue);
82 oResultVariant = ConvertToADTFVariantByType<int32_t>(oValue);
85 oResultVariant = ConvertToADTFVariantByType<uint32_t>(oValue);
88 oResultVariant = ConvertToADTFVariantByType<int64_t>(oValue);
91 oResultVariant = ConvertToADTFVariantByType<uint64_t>(oValue);
94 oResultVariant.Set(oValue.
asString().c_str());
103 return oResultVariant;
109 bool bIsArray = oValue.IsArray();
110 switch (oValue.GetType())
112 case adtf_util::VT_Bool:
119 oResultVariant.
reset(oValue.GetBoolArray(), oValue.GetArraySize());
122 case adtf_util::VT_Float64:
129 oResultVariant.
reset(oValue.GetFloat64Array(), oValue.GetArraySize());
132 case adtf_util::VT_Float32:
139 oResultVariant.
reset(oValue.GetFloat32Array(), oValue.GetArraySize());
142 case adtf_util::VT_Int8:
149 oResultVariant.
reset(oValue.GetInt8Array(), oValue.GetArraySize());
152 case adtf_util::VT_UInt8:
159 oResultVariant.
reset(oValue.GetUInt8Array(), oValue.GetArraySize());
162 case adtf_util::VT_Int16:
169 oResultVariant.
reset(oValue.GetInt16Array(), oValue.GetArraySize());
172 case adtf_util::VT_UInt16:
179 oResultVariant.
reset(oValue.GetUInt16Array(), oValue.GetArraySize());
182 case adtf_util::VT_Int32:
189 oResultVariant.
reset(oValue.GetInt32Array(), oValue.GetArraySize());
192 case adtf_util::VT_UInt32:
199 oResultVariant.
reset(oValue.GetUInt32Array(), oValue.GetArraySize());
202 case adtf_util::VT_Int64:
209 oResultVariant.
reset(oValue.GetInt64Array(), oValue.GetArraySize());
212 case adtf_util::VT_UInt64:
219 oResultVariant.
reset(oValue.GetUInt64Array(), oValue.GetArraySize());
222 case adtf_util::VT_String:
225 case adtf_util::VT_Empty:
230 return oResultVariant;
233 inline bool GetVariantInfoIsString(
const cVariant& oValue)
235 return oValue.GetType() == adtf_util::VT_String;
238 inline bool GetVariantInfoIsUnsignedInt(
const cVariant& oValue)
240 switch (oValue.GetType())
242 case adtf_util::VT_Bool:
243 case adtf_util::VT_UInt8:
244 case adtf_util::VT_UInt16:
245 case adtf_util::VT_UInt32:
246 case adtf_util::VT_UInt64:
247 case adtf_util::VT_Empty:
Copyright © Audi Electronics Venture GmbH.
Container type, able to store any primitive data type (and arrays thereof)
std::string asString() const
Convert the value of the variant.
VariantType getType() const
Returns the current underlying data type of the instance.
std::size_t getArraySize() const
Get the current array size of the instance.
void reset()
Resets the instance to VT_Empty.
bool isArray() const
Returns whether the instance stores an array of any kind.
@ 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_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_UInt32
Variant type is std::uint32_t.
ADTF adtf_util Namespace - Within adtf this is used as adtf::util or adtf_util and also defined as A_...
Common include for component a_util::variant.