ADTF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
configuration.h
Go to the documentation of this file.
1
7#pragma once
9#include "property.h"
10#include "properties.h"
11
12#include <memory>
13#include <string>
14#include <vector>
15#include <utility>
16#include <functional>
17#include <cinttypes>
18
19namespace adtf
20{
21namespace base
22{
23namespace ant
24{
28
29 template<>
31 {
32 constexpr static const char* const TYPE_NAME = "attached_config";
33 typedef property_type_conversion_nothing <property_attached_configuration_type> con_type;
34 };
35
36 namespace detail
37 {
38 class cRefConfigProperty : public ::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type>
39 {
43 typedef ::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type> base_type;
44 public:
48 cRefConfigProperty(const adtf_util::cString& strConfigurationName,
49 ucom::ant::iobject_ptr<IProperties>& pPropertiesAttach) : base_type(strConfigurationName, value_type())
50 {
51 AttachProperties(pPropertiesAttach);
52 }
53 };
54 }
55
56
57 class cPropertyVariable;
59 {
60 public:
61 virtual tResult UnregisterPropertyVariable(cPropertyVariable& oPropertyVariable) = 0;
62 };
63
68 {
69 private:
70 IMemberPropertyUnregister* m_pUnregister = nullptr;
71
72 public:
73 virtual ~cPropertyVariable();
74 void SetUnregister(IMemberPropertyUnregister& oUnregister);
75
81 virtual tResult GetType(IString&& strType) const = 0;
82
86 virtual const IPropertyValue* GetValue() const = 0;
87 };
88
99 template <typename T>
100 class property_variable: public cPropertyVariable, private property_value<T>
101 {
102 private:
104 using base_type = property_value<T>;
105
106 public:
109 {
110 }
111
113 property_variable(const T& oValue): base_type(oValue)
114 {
115 }
116
117 void Notify(const IProperty& oProperty) override
118 {
119 base_type::Set(*oProperty.GetValue());
120 }
121
122 tResult GetType(IString&& strType) const override
123 {
124 return base_type::GetType(std::forward<IString>(strType));
125 }
126
127 const IPropertyValue* GetValue() const override
128 {
129 return this;
130 }
131
132 const T& operator*() const
133 {
134 return base_type::GetValue();
135 }
136
137 operator const T&() const
138 {
139 return base_type::GetValue();
140 }
141
142 bool operator==(const T& oVal)
143 {
144 return base_type::GetValue() == oVal;
145 }
146
147 bool operator!=(const T& oVal)
148 {
149 return base_type::GetValue() != oVal;
150 }
151 };
152 namespace detail
153 {
157 class cPropertyVariableHelper: public cPropertyBase
158 {
159 private:
160 const IPropertyValue* m_pValue;
161
162 public:
166 cPropertyVariableHelper(const adtf_util::cString& strName, const IPropertyValue& oValue):
167 m_pValue(&oValue)
168 {
169 m_strName = strName;
170 }
171
172 const IPropertyValue* GetValue() const override
173 {
174 return m_pValue;
175 }
176
177 IPropertyValue* GetValue() override
178 {
179 return nullptr;
180 }
181
182 tResult SetValue(const IPropertyValue& /* oValue */) override
183 {
184 RETURN_ERROR(ERR_NOT_SUPPORTED);
185 }
186
187 tResult Set(const IProperty& /* oProp */) override
188 {
189 RETURN_ERROR(ERR_NOT_SUPPORTED);
190 }
191 };
192 } // ns detail
193
198 template <typename Interface = IConfiguration>
199 class configuration: public ucom::catwo::object<IConfiguration, Interface>, public IMemberPropertyUnregister
200 {
201 protected:
204
205 public:
211
212 virtual ~configuration() = default;
213 public:
219 {
221 pProperties.Reset(pConstProps);
223 }
224
234
235 tResult AttachConfiguration(const char* strName,
236 IConfiguration& pAttachedConfiguration) override
237 {
239 RETURN_IF_FAILED(pAttachedConfiguration.GetProperties(pProps));
240 adtf_util::cString strConfigName(strName);
241 detail::cRefConfigProperty oAttachedConfig(strConfigName, pProps);
242 RETURN_IF_FAILED(m_pProperties->SetProperty(oAttachedConfig));
244 }
245
246 tResult DetachConfiguration(const char* strName) override
247 {
248 return m_pProperties->RemoveProperty(strName);
249 }
250
251 public:
252 tResult RegisterPropertyVariable(const char* strName,
253 cPropertyVariable& oPropertyVariable);
254
255 tResult UnregisterPropertyVariable(cPropertyVariable& oPropertyVariable)
256 {
257 return m_pProperties->UnregisterPropertyObserver(oPropertyVariable);
258 }
259 };
260
270 template<typename VALUETYPE>
271 VALUETYPE get_property(const IConfiguration& oConfiguration, const char* strNameOfValue, VALUETYPE oDefaultValue)
272 {
274 if (IS_OK(oConfiguration.GetProperties(pProperties)))
275 {
276 return get_property<VALUETYPE>(*pProperties, strNameOfValue, oDefaultValue);
277 }
278 else
279 {
280 return oDefaultValue;
281 }
282 }
283
291 template<typename VALUETYPE>
292 VALUETYPE get_property(const IConfiguration& oConfiguration, const char* strNameOfValue)
293 {
294 return get_property<VALUETYPE>(oConfiguration, strNameOfValue, VALUETYPE());
295 }
296
306 template<typename VALUETYPE>
307 tResult set_property(IConfiguration& oConfiguration, const char* strNameOfValue, VALUETYPE oValue)
308 {
310 RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
311 return set_property<VALUETYPE>(*pProperties, strNameOfValue, oValue);
312 }
313
322 inline tResult set_property(IConfiguration& oConfiguration, const char* strNameOfValue, const char* poValue)
323 {
325 RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
326 return set_property<adtf_util::cString>(*pProperties, strNameOfValue, adtf_util::cString(poValue));
327 }
328
329
330} //namespace ant
331
332namespace catwo
333{
334
335template <typename VALUETYPE>
336tResult set_property_by_path(IConfiguration& oConfiguration, const char* strPathAndName, VALUETYPE oValue)
337{
339 RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
340 return set_property_by_path<VALUETYPE>(*pProperties, strPathAndName, oValue);
341}
342
343template <typename VALUETYPE>
344VALUETYPE get_property_by_path(const IConfiguration& oConfiguration, const char* strPathAndName, VALUETYPE oDefaultValue)
345{
347 if (IS_FAILED(oConfiguration.GetProperties(pProperties)))
348 {
349 return oDefaultValue;
350 }
351 return get_property_by_path<VALUETYPE>(*pProperties, strPathAndName, oDefaultValue);
352}
353
354template <typename VALUETYPE>
355VALUETYPE get_property_by_path(const IConfiguration& oConfiguration, const char* strPathAndName)
356{
357 return get_property_by_path(oConfiguration, strPathAndName, VALUETYPE());
358}
359
360}
361
362namespace flash
363{
364
369{
370 public:
375
381 tResult AttachConfiguration(const char* strName,
382 IConfiguration& oAttachedConfiguration);
384 tResult DetachConfiguration(const char* strName);
385
393 ant::cPropertyVariable& oPropertyVariable);
394
395 private:
396 class cImplementation;
397 std::unique_ptr<cImplementation> m_pImplementation;
398};
399
404template<typename T>
406{
407 public:
409
410 const T* operator->()
411 {
412 return &static_cast<const T&>(*this);
413 }
414};
415
416}
417
418namespace giant
419{
420
421namespace detail
422{
423
425{
426 static constexpr const char* const strReservedPrefix = "#__";
427 static constexpr const char* const strDisplayName = "#__display_name";
428 static constexpr const char* const strDescription = "#__description";
429 static constexpr const char* const strRangeMin = "#__range_min";
430 static constexpr const char* const strRangeMax = "#__range_max";
431 static constexpr const char* const strValueListCount = "#__value_list_count";
432 static constexpr const char* const strValueListValueFormat = "#__value_list_value_%zu";
433 static constexpr const char* const strValueListNameFormat = "#__value_list_name_%zu";
434 static constexpr const char* const strValueListRestricted = "#__value_list_restricted";
435 static constexpr const char* const strEditorListCount = "#__editor_list_count";
436 static constexpr const char* const strEditorListNameFormat = "#__editor_list_name_%zu";
437 static constexpr const char* const strEditorListUrlFormat = "#__editor_list_url_%zu";
438 static constexpr const char* const strServiceDefaultRunlevel = "#__service_default_runlevel";
439 static constexpr const char* const strFilenameExtensionFilter = "#__filename_extension_filter";
440 static constexpr const char* const strFilenameOpenForWriting = "#__filename_open_for_writing";
441 static constexpr const char* const strHelpLink = "#__help_link";
442 static constexpr const char* const strItemDescriptions = "#__item_descriptions";
443 static constexpr const char* const strResolveMacros = "#__resolve_macros";
444};
445
446template <typename U, typename Enable = void>
448
449template<typename U>
450struct storage_type<U, std::enable_if_t<!std::is_enum<U>::value>>
451{
452 typedef U type;
453 static const type& assign(const type& value)
454 {
455 return value;
456 }
457};
458
459template <typename U>
460struct storage_type<U, std::enable_if_t<std::is_enum<U>::value>>
461{
462 typedef typename std::underlying_type<U>::type type;
463 static type assign(const U& value)
464 {
465 return static_cast<type>(value);
466 }
467};
468
469template <typename T, typename ValueType>
470void set_value_list(IProperties& oSubProperties,
471 const std::vector<std::pair<ValueType, std::string>>& oValueList,
472 bool bRestrictToValues = true)
473{
474 set_property<unsigned int>(oSubProperties,
475 detail::tReservedProperties::strValueListCount,
476 static_cast<unsigned int>(oValueList.size()));
477 set_property<bool>(oSubProperties,
478 detail::tReservedProperties::strValueListRestricted,
479 bRestrictToValues);
480
481 size_t nIndex = 0;
482 for (const auto& oValue: oValueList)
483 {
484 set_property<T>(oSubProperties,
485 util::cString::Format(detail::tReservedProperties::strValueListValueFormat, nIndex),
486 storage_type<ValueType>::assign(oValue.first));
487 set_property<util::cString>(oSubProperties,
488 util::cString::Format(detail::tReservedProperties::strValueListNameFormat, nIndex),
489 oValue.second.c_str());
490 ++nIndex;
491 }
492}
493
494template <typename T>
495void set_valid_range(IProperties& oSubProperties, const T& xMin, const T& xMax)
496{
497 set_property<T>(oSubProperties,
498 detail::tReservedProperties::strRangeMin,
499 xMin);
500 set_property<T>(oSubProperties,
501 detail::tReservedProperties::strRangeMax,
502 xMax);
503}
504
505}
506
511{
512 public:
517
523
529
536
543
548
553
558 void SetDisplayName(const char* strDisplayName);
559
564 void SetDescription(const char* strDescription);
565
572 void SetFilenameExtensionFilter(const char* strFilenameExtensionFilter);
573
578 void SetFilenameOpenForWriting(bool bWriteMode);
579
584 tVoid SetResolveMacros(tBool bResolveMacros);
585
586 protected:
591
592 protected:
593 class cImplementation;
594 std::unique_ptr<cImplementation> m_pImplementation;
595};
596
600template <typename T>
602{
603 private:
604 typedef typename giant::detail::storage_type<T>::type property_type;
605
606 public:
610 property_variable() = default;
611
616 property_variable(const T& xValue):
617 m_oValue(giant::detail::storage_type<T>::assign(xValue))
618 {
619 }
620
621 property_variable& operator=(const T& xValue)
622 {
624 return *this;
625 }
626
627 void Notify(const IProperty& oProperty) override
628 {
629 m_oValue.Set(*oProperty.GetValue());
630 }
631
632 tResult GetType(IString&& strType) const override
633 {
634 return m_oValue.GetType(std::forward<IString>(strType));
635 }
636
637 const IPropertyValue* GetValue() const override
638 {
639 return &m_oValue;
640 }
641
642 const T& operator*() const
643 {
644 return GetReference();
645 }
646
647 operator const T&() const
648 {
649 return GetReference();
650 }
651
652 bool operator==(const T& oVal)
653 {
654 return GetReference() == oVal;
655 }
656
657 bool operator!=(const T& oVal)
658 {
659 return GetReference() != oVal;
660 }
661
662 const T* operator->()
663 {
664 return &GetReference();
665 }
666
667 const T* operator->() const
668 {
669 return &GetReference();
670 }
671
677 void SetValueList(const std::vector<std::pair<T, std::string>>& oValueList,
678 bool bRestrictToValues = true)
679 {
680 detail::set_value_list<property_type>(GetSubProperties(), oValueList, bRestrictToValues);
681 }
682
688 void SetValidRange(const T& xMin, const T& xMax)
689 {
690 detail::set_valid_range<property_type>(GetSubProperties(),
693 }
694
695 protected:
697
698 private:
699 const T& GetReference() const
700 {
701 return reinterpret_cast<const T&>(m_oValue.GetValue());
702 }
703};
704
705}
706
707namespace ant
708{
709
710template<typename Interface>
711tResult configuration<Interface>::RegisterPropertyVariable(const char* strName, cPropertyVariable& oPropertyVariable)
712{
713 auto oParentsAndName = elasto::split_parents_and_leaf(strName);
714 detail::cPropertyVariableHelper oHelper(oParentsAndName.second.c_str(), *oPropertyVariable.GetValue());
715
716 try
717 {
718 const auto& oGiantPropertyVariable = dynamic_cast<const giant::cPropertyVariable&>(oPropertyVariable);
719 RETURN_IF_FAILED(oHelper.SetProperties(oGiantPropertyVariable.GetSubProperties()));
720 }
721 catch (...)
722 {
723 }
724
725 RETURN_IF_FAILED(elasto::create_property_tree(*m_pProperties, oParentsAndName.first.c_str()));
726 RETURN_IF_FAILED(m_pProperties->SetPropertyByPath(oParentsAndName.first.c_str(), oHelper));
727 RETURN_IF_FAILED(m_pProperties->RegisterPropertyObserver(strName, oPropertyVariable));
728 oPropertyVariable.SetUnregister(*this);
730}
731
732}
733
734namespace hollow
735{
736
746 const char* strPropertyPathAndName,
747 ant::IProperty& oProperty);
748
753template <typename T>
755{
756public:
759
762 {
763 giant::property_variable<T>::operator=(oVal);
764 return *this;
765 }
766
771 void SetPropertyChangedCallback(const std::function<void()> & fnCallback)
772 {
773 m_fnPropertyChangedCallback = fnCallback;
774 }
775
776 void Notify(const IProperty& oProperty) override
777 {
779
780 if (m_fnPropertyChangedCallback)
781 {
782 m_fnPropertyChangedCallback();
783 }
784 }
785
786private:
787 std::function<void()> m_fnPropertyChangedCallback;
788
789};
790}
791
792namespace ultron
793{
794namespace detail
795{
797{
798 static constexpr const char* const strRuntimeNode = "#__runtime";
799 static constexpr const char* const strRuntimeStartOnStartup = "#__runtime/start_on_startup";
800};
801} // namespace detail
802} // namespace ultron
803
806
810
811using catwo::set_property_by_path;
812using catwo::get_property_by_path;
813
816
817} //namespace base
818} //namespace adtf
void tVoid
The tVoid is always the definition for the void (non-type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#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.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
tBool operator!=(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for inequality.
tBool operator==(const tErrorCode &lhs, const tErrorCode &rhs)
Compare two POD error code types for equality.
ucom Interface to a objects configuration.
virtual tResult GetProperties(ucom::ant::iobject_ptr< const IProperties > &pProperties) const =0
Gets the properties with read access.
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 IString interface provides methods for getting and setting strings through abstract interfaces.
Definition string_intf.h:28
tResult AttachProperties(const ucom::ant::iobject_ptr< IProperties > &pAttachedProperties) override
will set given properties to be attached
Default implemementation of a property_variable.
virtual const IPropertyValue * GetValue() const =0
virtual tResult GetType(IString &&strType) const =0
Returns the identifier of the type.
Implementation helper template to enriches an implementation with the default implementation of IConf...
virtual ~configuration()=default
DTOR.
adtf::ucom::object_ptr< spider::cProperties > m_pProperties
the current runtiem property set
tResult GetProperties(adtf::ucom::ant::iobject_ptr< const IProperties > &pProperties) const override
Gets the configuration with only read access.
tResult GetProperties(adtf::ucom::ant::iobject_ptr< IProperties > &pProperties) override
Gets the properties of configuration with only read/write access.
cPropertyVariableHelper(const adtf_util::cString &strName, const IPropertyValue &oValue)
CTOR initializer.
cRefConfigProperty(const adtf_util::cString &strConfigurationName, ucom::ant::iobject_ptr< IProperties > &pPropertiesAttach)
initializer CTOR
::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type > base_type
internal base type
::adtf::base::ant::property_attached_configuration_type value_type
internal value type
tResult Set(const IPropertyValue &oValue)
Sets the value by a deep copy.
Definition property.h:76
tResult GetType(IString &&strType) const
Retrieves the string for the property value type.
Definition property.h:139
Property Variable template for the given T.
void Notify(const IProperty &oProperty) override
Implements the observer pattern.
const IPropertyValue * GetValue() const override
tResult GetType(IString &&strType) const override
Returns the identifier of the type.
property_value< T > base_type
internal base type
property_variable(const T &oValue)
type initializing CTOR
Property property implementation template.
Definition property.h:212
cConfiguration()
Default constructor.
Implementation helper template to enriches an implementation with the default implementation of IConf...
Implements all functionality required by ant::IConfiguration.
cConfiguration()
Default constructor.
tResult GetProperties(adtf::ucom::ant::iobject_ptr< IProperties > &pProperties)
Gets the properties with read access.
tResult AttachConfiguration(const char *strName, IConfiguration &oAttachedConfiguration)
Attaches the given configuration and its properties as property tree item of this.
tResult DetachConfiguration(const char *strName)
Detaches a configuration with the specified name.
tResult GetProperties(adtf::ucom::ant::iobject_ptr< const IProperties > &pProperties) const
Gets the properties with read access.
tResult RegisterPropertyVariable(const char *strName, ant::cPropertyVariable &oPropertyVariable)
Registers a property variable that always reflects the current value of the property.
virtual ~cConfiguration()
Destructor.
cPropertyVariable & operator=(const cPropertyVariable &oOther)
Assignment operator.
cPropertyVariable()
The default constructor.
void SetDescription(const char *strDescription)
Sets the description text associated with the Property.
~cPropertyVariable() override
Destructor.
void SetFilenameOpenForWriting(bool bWriteMode)
Sets the write mode for the file property.
ant::IProperties & GetSubProperties()
tVoid SetResolveMacros(tBool bResolveMacros)
Sets whether or not macros should be resolved by the session manager or not.
cPropertyVariable(const cPropertyVariable &oOther)
Copy constructor.
void SetDisplayName(const char *strDisplayName)
Sets the name that tools should display.
const ant::IProperties & GetSubProperties() const
cPropertyVariable & operator=(cPropertyVariable &&oOther)
Move assignment operator.
void SetFilenameExtensionFilter(const char *strFilenameExtensionFilter)
Sets optional file filters for Configuration Editor FileDialogs of cFilename and cFilenameList proper...
cPropertyVariable(cPropertyVariable &&oOther)
Move constructor.
Property Variable template for the given T.
property_variable(const T &xValue)
Initializes the property variable with the given value.
void Notify(const IProperty &oProperty) override
Implements the observer pattern.
property_variable()=default
Initializes the property variable with the default value of T.
void SetValueList(const std::vector< std::pair< T, std::string > > &oValueList, bool bRestrictToValues=true)
Sets a value list, that the user can choose from.
const IPropertyValue * GetValue() const override
tResult GetType(IString &&strType) const override
Returns the identifier of the type.
void SetValidRange(const T &xMin, const T &xMax)
Sets the valid range of values.
Property Variable template for the given T.
void Notify(const IProperty &oProperty) override
Implements the observer pattern.
void SetPropertyChangedCallback(const std::function< void()> &fnCallback)
Set a callback to get notified about property changes.
property_variable & operator=(const T &oVal)
Assignment operator.
virtual tResult Reset(const iobject_ptr< T > &i_oOther)=0
Reset this object_ptr<> with the content of another iobject_ptr<>
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...
Definition object.h:397
Copyright © Audi Electronics Venture GmbH.
Namespace for all internally used functionality implemented.
Namespace for all functionality of the ADTF Base SDK provided since v3.0.
VALUETYPE get_property(const IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oDefaultValue)
Get the property content converted to the VALUETYPE.
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
std::pair< std::string, std::string > split_parents_and_leaf(const char *strPropertyPathAndName)
Splits a property path into the parent path and the property name.
tResult create_property_tree(ant::IProperties &oProperties, const char *strPath)
Creates a property tree structure.
Namespace for all functionality of the ADTF Base SDK provided since v3.5.
Namespace for all internally used functionality implemented.
Namespace for all functionality of the ADTF Base SDK provided since v3.6.
Namespace for all functionality of the ADTF Base SDK provided since v3.7.
tResult get_property_object_by_path(const ant::IConfiguration &oConfiguration, const char *strPropertyPathAndName, ant::IProperty &oProperty)
Retrieves a property reference under the given oConfiguration by path.
Namespace for the ADTF Base SDK.
tResult set_property(IConfiguration &oConfiguration, const char *strNameOfValue, VALUETYPE oValue)
Set the property.
object_ptr< Implementation > make_object_ptr(Args &&... args)
Alias always bringing the latest version of ant::make_object_ptr() into scope.
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.