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)
177 template <
typename T>
178 cProperty(std::string_view strName,
const T& xValue):
184 template <
typename T>
185 cProperty(
const char* strName,
const T& xValue):
cProperty(std::string_view(strName), xValue)
189 template <
typename T>
197 const IPropertyValue* GetValue()
const override;
198 IPropertyValue* GetValue()
override;
199 tResult SetValue(
const IPropertyValue& oValue)
override;
201 template <
typename T>
202 tResult SetValue(
const T& xValue)
204 if constexpr(std::is_base_of_v<ant::IPropertyValue, T>)
206 return this->SetValue(
static_cast<const IPropertyValue&
>(xValue));
216 tResult GetName(IString&& strName)
const override;
217 tResult SetName(
const IString& strName)
override;
218 tResult Set(
const IProperty& oProp)
override;
219 bool HasProperties()
const override;
220 bool HasAttachedProperties()
const override;
234 void NotifyObservers();
235 void CreateProperties()
const;
238 std::string m_strName;
240 std::vector<IPropertyObserver*> m_oObservers;
241 bool m_bAttached =
false;
244 template <
typename T,
typename Enable =
void>
250 RegisterObserver(*
this);
256 RegisterObserver(*
this);
269 property(
const char* strName,
const T& oValue):
property(std::string_view(strName), oValue)
275 UnregisterObserver(*
this);
278 const T& GetValueT()
const
283 bool operator==(
const T& xOther)
const
285 return GetValueT() == xOther;
288 property& operator=(
const T& xValue)
290 ConvertAndSetValue(xValue);
294 property& operator=(
property&& oProp)
304 void InitValue(
const T& oValue)
306 ConvertAndSetValue(oValue);
307 RegisterObserver(*
this);
310 void ConvertAndSetValue(
const T& oValue)
325 template <
typename T>
326 class property<T, typename std::enable_if<!detail::is_user_defined_property_value<T>::value>::type>:
public cProperty
333 using cProperty::cProperty;
335 const T& GetValueT()
const
340 bool operator==(
const T& xOther)
const
342 return GetValueT() == xOther;
345 property& operator=(
const T& xValue)
357 bool Exists(
const char* strName)
const override;
360 size_t GetSize()
const override;
361 tResult GetProperty(
const char* strName,
IProperty& pProperty)
const override;
365 cProperties& CreateProperty(std::string_view strName,
const T& xValue)
367 const auto emplaced = m_oProperties.emplace(std::piecewise_construct,
368 std::forward_as_tuple(strName),
369 std::forward_as_tuple(strName, xValue));
370 if (!emplaced.second)
372 emplaced.first->second.SetValue(xValue);
375 return static_cast<cProperties&
>(emplaced.first->second.GetProperties());
378 tResult SetPropertyByPath(
const char* strParentPath,
const IProperty& pProperty)
override;
379 tResult RemoveProperty(
const char* strName)
override;
380 tResult RegisterPropertyObserver(
const char* strPropertyName,
385 std::map<std::string, cProperty, std::less<>> m_oProperties;
394 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 DetachProperties() override
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
cProperty & operator=(const ant::IProperty &oProp)
Copy assignment, mind that this will perform a merge of the subproperties of oProp into this,...
cProperty & operator=(cProperty &&oProp)
Move assignment, mind that this will perform a merge of the subproperties of oProp into this (via cop...
cProperty & operator=(const cProperty &oProp)
Copy assignment, mind that this will perform a merge of the subproperties of oProp into this,...
tResult GetAttachedProperties(IProperty &pProperty) const override
tResult SetProperties(const IProperties &pProperties) override
will copy given properties
tResult AttachProperties(const ucom::ant::iobject_ptr< IProperties > &pProperties) override
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.
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