16 #include <string_view>
37 if constexpr(std::is_base_of_v<ant::IPropertyValue, T>)
39 auto oResult = AssignRaw(xValue);
41 if (oResult == ERR_EMPTY)
43 oResult = AssignString(xValue);
54 cPropertyValue(
const char* strValue)
56 m_xValue = std::string(strValue);
59 cPropertyValue(std::string_view strValue)
61 m_xValue = std::string(strValue);
64 cPropertyValue(cPropertyValue&&) =
default;
65 cPropertyValue(
const cPropertyValue&) =
default;
66 cPropertyValue& operator=(cPropertyValue&&) =
default;
67 cPropertyValue& operator=(
const cPropertyValue&) =
default;
75 if constexpr(std::is_base_of_v<ant::IPropertyValue, T>)
94 return std::get<T>(m_xValue);
100 return std::get<T>(m_xValue);
107 std::variant<bool, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double, std::string, tUserDefined> m_xValue;
112 template <
typename T>
113 using is_user_defined_property_value = std::integral_constant<bool, !(std::is_same_v<T, bool> || std::is_arithmetic_v<T> || std::is_same_v<T, std::string>)>;
115 template <
typename T>
116 typename std::enable_if<is_user_defined_property_value<T>::value,
tResult>::type get_property_value(
const cPropertyValue& oValue, T& xValue)
118 const auto& strValue = oValue.Get<cPropertyValue::tUserDefined>().strValue;
123 template <
typename T>
124 typename std::enable_if<!is_user_defined_property_value<T>::value,
tResult>::type get_property_value(
const cPropertyValue& oValue, T& xValue)
126 xValue = oValue.Get<T>();
129 template <
typename T>
130 using storage_type =
typename std::conditional<is_user_defined_property_value<T>::value, cPropertyValue::tUserDefined, T>::type;
134 template <
typename T>
135 tResult get_property_value(
const IPropertyValue& oValue, T& xValue)
137 cPropertyValue oHelper(detail::storage_type<T>{});
143 template <
typename T>
144 T get_property_value(
const IPropertyValue& oValue)
169 template <
typename T>
170 cProperty(std::string_view strName,
const T& xValue):
176 template <
typename T>
177 cProperty(
const char* strName,
const T& xValue):
cProperty(std::string_view(strName), xValue)
181 template <
typename T>
191 template <
typename T>
192 tResult SetValue(
const T& xValue)
194 if constexpr(std::is_base_of_v<ant::IPropertyValue, T>)
196 return this->SetValue(
static_cast<const IPropertyValue&
>(xValue));
200 m_oValue.
Set(xValue);
209 bool HasProperties()
const override;
210 bool HasAttachedProperties()
const override;
214 tResult DetachProperties()
override;
224 void NotifyObservers();
225 void CreateProperties()
const;
228 std::string m_strName;
230 std::vector<IPropertyObserver*> m_oObservers;
231 bool m_bAttached =
false;
234 template <
typename T,
typename Enable =
void>
240 RegisterObserver(*
this);
253 property(
const char* strName,
const T& oValue):
property(std::string_view(strName), oValue)
257 const T& GetValueT()
const
262 bool operator==(
const T& xOther)
const
264 return GetValueT() == xOther;
267 property& operator=(
const T& xValue)
269 ConvertAndSetValue(xValue);
274 void InitValue(
const T& oValue)
276 ConvertAndSetValue(oValue);
277 RegisterObserver(*
this);
280 void ConvertAndSetValue(
const T& oValue)
295 template <
typename T>
296 class property<T, typename std::enable_if<!detail::is_user_defined_property_value<T>::value>::type>:
public cProperty
303 using cProperty::cProperty;
305 const T& GetValueT()
const
310 bool operator==(
const T& xOther)
const
312 return GetValueT() == xOther;
315 property& operator=(
const T& xValue)
327 bool Exists(
const char* strName)
const override;
330 size_t GetSize()
const override;
331 tResult GetProperty(
const char* strName,
IProperty& pProperty)
const override;
335 cProperties& CreateProperty(std::string_view strName,
const T& xValue)
337 const auto emplaced = m_oProperties.emplace(std::piecewise_construct,
338 std::forward_as_tuple(strName),
339 std::forward_as_tuple(strName, xValue));
340 if (!emplaced.second)
342 emplaced.first->second.SetValue(xValue);
345 return static_cast<cProperties&
>(emplaced.first->second.GetProperties());
348 tResult SetPropertyByPath(
const char* strParentPath,
const IProperty& pProperty)
override;
349 tResult RemoveProperty(
const char* strName)
override;
350 tResult RegisterPropertyObserver(
const char* strPropertyName,
355 std::map<std::string, cProperty, std::less<>> m_oProperties;
364 using spider::get_property_value;
Copyright © Audi Electronics Venture GmbH.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
A common result class usable as return value throughout.
Defintion of a property set container interface.
The IProperty interface provides methods for getting and setting property values, name of the propert...
Observer Interface to react on property changes.
The IPropertyValue interface provides methods for getting and setting property values.
The IRawMemory interface provides methods for getting and setting memory values through abstract inte...
The IString interface provides methods for getting and setting strings through abstract interfaces.
tResult GetProperties(ucom::ant::iobject_ptr< const IProperties > &pProperties) const override
get subproperties for readonly access
tResult GetProperties(ucom::ant::iobject_ptr< IProperties > &pProperties) override
get subproperties for writing access
tResult SetProperties(const IProperties &pProperties) override
will copy given properties
tResult FromRaw(const IRawMemory &oRawValue) override
Implement to create a fast value copy in memory.
tResult ToRaw(IRawMemory &&oRawValue) const override
Implement to create a fast value copy in memory.
tResult FromString(const IString &strValueAsString) override
Implement to deserialize the value from a textfile and/or to set by string.
tResult ToString(IString &&strIToString) const override
Implement to serialize the value to a textfile and/or to show it on a display.
tResult Set(const IPropertyValue &oValue) override
Sets the value by a deep copy.
tResult GetType(IString &&strType) const override
Retrieves the string for the property value type.
void Notify(const IProperty &)
Implements the observer pattern.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
Concept template to define the Name and the conversion type for the given type TYPE.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult