ADTF  3.16.2
configuration.h
Go to the documentation of this file.
1 
7 #pragma once
8 #include "configuration_intf.h"
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 
18 namespace adtf
19 {
20 namespace base
21 {
22 namespace ant
23 {
25  {
26  };
27 
28  template<>
30  {
31  constexpr static const tChar* const TYPE_NAME = "attached_config";
33  };
34 
35  namespace detail
36  {
37  class cRefConfigProperty : public ::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type>
38  {
40  typedef ::adtf::base::ant::property_attached_configuration_type value_type;
42  typedef ::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type> base_type;
43  public:
47  cRefConfigProperty(const adtf_util::cString& strConfigurationName,
48  ucom::ant::iobject_ptr<IProperties>& pPropertiesAttach) : base_type(strConfigurationName, value_type())
49  {
50  AttachProperties(pPropertiesAttach);
51  }
52  };
53  }
54 
55 
56  class cPropertyVariable;
58  {
59  public:
60  virtual tResult UnregisterPropertyVariable(cPropertyVariable& oPropertyVariable) = 0;
61  };
62 
67  {
68  private:
69  IMemberPropertyUnregister* m_pUnregister = nullptr;
70 
71  public:
72  virtual ~cPropertyVariable();
73  void SetUnregister(IMemberPropertyUnregister& oUnregister);
74 
80  virtual tResult GetType(IString&& strType) const = 0;
81 
85  virtual const IPropertyValue* GetValue() const = 0;
86  };
87 
98  template <typename T>
100  {
101  private:
104 
105  public:
108  {
109  }
112  property_variable(const T& oValue): base_type(oValue)
113  {
114  }
115 
116  void Notify(const IProperty& oProperty) override
117  {
118  base_type::Set(*oProperty.GetValue());
119  }
120 
121  tResult GetType(IString&& strType) const override
122  {
123  return base_type::GetType(std::forward<IString>(strType));
124  }
125 
126  const IPropertyValue* GetValue() const override
127  {
128  return this;
129  }
130 
131  const T& operator*() const
132  {
133  return base_type::GetValue();
134  }
135 
136  operator const T&() const
137  {
138  return base_type::GetValue();
139  }
140 
141  bool operator==(const T& oVal)
142  {
143  return base_type::GetValue() == oVal;
144  }
145 
146  bool operator!=(const T& oVal)
147  {
148  return base_type::GetValue() != oVal;
149  }
150  };
151  namespace detail
152  {
157  {
158  private:
159  const IPropertyValue* m_pValue;
160 
161  public:
166  m_pValue(&oValue)
167  {
168  m_strName = strName;
169  }
170 
171  const IPropertyValue* GetValue() const override
172  {
173  return m_pValue;
174  }
175 
176  IPropertyValue* GetValue() override
177  {
178  return nullptr;
179  }
180 
181  tResult SetValue(const IPropertyValue& /* oValue */) override
182  {
183  RETURN_ERROR(ERR_NOT_SUPPORTED);
184  }
185 
186  tResult Set(const IProperty& /* oProp */) override
187  {
188  RETURN_ERROR(ERR_NOT_SUPPORTED);
189  }
190  };
191  } // ns detail
192 
197  template <typename Interface = IConfiguration>
198  class configuration: public ucom::catwo::object<IConfiguration, Interface>, public IMemberPropertyUnregister
199  {
200  protected:
203 
204  public:
207  {
208  m_pProperties = adtf::ucom::make_object_ptr < cProperties >();
209  }
211  virtual ~configuration() = default;
212  public:
218  {
220  pProperties.Reset(pConstProps);
222  }
228  {
230  pProperties.Reset(pProps);
232  }
233 
234  tResult AttachConfiguration(const char* strName,
235  IConfiguration& pAttachedConfiguration) override
236  {
238  RETURN_IF_FAILED(pAttachedConfiguration.GetProperties(pProps));
239  adtf_util::cString strConfigName(strName);
240  detail::cRefConfigProperty oAttachedConfig(strConfigName, pProps);
241  RETURN_IF_FAILED(m_pProperties->SetProperty(oAttachedConfig));
243  }
244 
245  tResult DetachConfiguration(const char* strName) override
246  {
247  return m_pProperties->RemoveProperty(strName);
248  }
249 
250  public:
251  tResult RegisterPropertyVariable(const char* strName,
252  cPropertyVariable& oPropertyVariable);
253 
254  tResult UnregisterPropertyVariable(cPropertyVariable& oPropertyVariable)
255  {
256  return m_pProperties->UnregisterPropertyObserver(oPropertyVariable);
257  }
258  };
259 
269  template<typename VALUETYPE>
270  VALUETYPE get_property(const IConfiguration& oConfiguration, const char* strNameOfValue, VALUETYPE oDefaultValue)
271  {
273  if (IS_OK(oConfiguration.GetProperties(pProperties)))
274  {
275  return get_property<VALUETYPE>(*pProperties, strNameOfValue, oDefaultValue);
276  }
277  else
278  {
279  return oDefaultValue;
280  }
281  }
290  template<typename VALUETYPE>
291  VALUETYPE get_property(const IConfiguration& oConfiguration, const char* strNameOfValue)
292  {
293  return get_property<VALUETYPE>(oConfiguration, strNameOfValue, VALUETYPE());
294  }
295 
305  template<typename VALUETYPE>
306  tResult set_property(IConfiguration& oConfiguration, const char* strNameOfValue, VALUETYPE oValue)
307  {
309  RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
310  return set_property<VALUETYPE>(*pProperties, strNameOfValue, oValue);
311  }
312 
321  inline tResult set_property(IConfiguration& oConfiguration, const char* strNameOfValue, const char* poValue)
322  {
324  RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
325  return set_property<adtf_util::cString>(*pProperties, strNameOfValue, adtf_util::cString(poValue));
326  }
327 
328 
329 } //namespace ant
330 
331 namespace catwo
332 {
333 
334 template <typename VALUETYPE>
335 tResult set_property_by_path(IConfiguration& oConfiguration, const char* strPathAndName, VALUETYPE oValue)
336 {
338  RETURN_IF_FAILED(oConfiguration.GetProperties(pProperties));
339  return set_property_by_path<VALUETYPE>(*pProperties, strPathAndName, oValue);
340 }
341 
342 template <typename VALUETYPE>
343 VALUETYPE get_property_by_path(const IConfiguration& oConfiguration, const char* strPathAndName, VALUETYPE oDefaultValue)
344 {
346  if (IS_FAILED(oConfiguration.GetProperties(pProperties)))
347  {
348  return oDefaultValue;
349  }
350  return get_property_by_path<VALUETYPE>(*pProperties, strPathAndName, oDefaultValue);
351 }
352 
353 template <typename VALUETYPE>
354 VALUETYPE get_property_by_path(const IConfiguration& oConfiguration, const char* strPathAndName)
355 {
356  return get_property_by_path(oConfiguration, strPathAndName, VALUETYPE());
357 }
358 
359 }
360 
361 namespace flash
362 {
363 
368 {
369  public:
373  virtual ~cConfiguration();
374 
380  tResult AttachConfiguration(const char* strName,
381  IConfiguration& oAttachedConfiguration);
383  tResult DetachConfiguration(const char* strName);
384 
391  tResult RegisterPropertyVariable(const char* strName,
392  ant::cPropertyVariable& oPropertyVariable);
393 
394  private:
395  class cImplementation;
396  std::unique_ptr<cImplementation> m_pImplementation;
397 };
398 
403 template<typename T>
405 {
406  public:
408 
409  const T* operator->()
410  {
411  return &static_cast<const T&>(*this);
412  }
413 };
414 
415 }
416 
417 namespace giant
418 {
419 
420 namespace detail
421 {
422 
424 {
425  static constexpr const tChar* const strReservedPrefix = "#__";
426  static constexpr const tChar* const strDisplayName = "#__display_name";
427  static constexpr const tChar* const strDescription = "#__description";
428  static constexpr const tChar* const strRangeMin = "#__range_min";
429  static constexpr const tChar* const strRangeMax = "#__range_max";
430  static constexpr const tChar* const strValueListCount = "#__value_list_count";
431  static constexpr const tChar* const strValueListValueFormat = "#__value_list_value_%u";
432  static constexpr const tChar* const strValueListNameFormat = "#__value_list_name_%u";
433  static constexpr const tChar* const strValueListRestricted = "#__value_list_restricted";
434  static constexpr const tChar* const strEditorListCount = "#__editor_list_count";
435  static constexpr const tChar* const strEditorListNameFormat = "#__editor_list_name_%u";
436  static constexpr const tChar* const strEditorListUrlFormat = "#__editor_list_url_%u";
437  static constexpr const tChar* const strServiceDefaultRunlevel = "#__service_default_runlevel";
438  static constexpr const tChar* const strFilenameExtensionFilter = "#__filename_extension_filter";
439  static constexpr const tChar* const strFilenameOpenForWriting = "#__filename_open_for_writing";
440  static constexpr const tChar* const strHelpLink = "#__help_link";
441  static constexpr const tChar* const strItemDescriptions = "#__item_descriptions";
442  static constexpr const tChar* const strResolveMacros = "#__resolve_macros";
443 };
444 
445 template <typename U, typename Enable = void>
447 
448 template<typename U>
449 struct storage_type<U, std::enable_if_t<!std::is_enum<U>::value>>
450 {
451  typedef U type;
452  static const type& assign(const type& value)
453  {
454  return value;
455  }
456 };
457 
458 template <typename U>
459 struct storage_type<U, std::enable_if_t<std::is_enum<U>::value>>
460 {
461  typedef typename std::underlying_type<U>::type type;
462  static type assign(const U& value)
463  {
464  return static_cast<type>(value);
465  }
466 };
467 
468 template <typename T, typename ValueType>
469 void set_value_list(IProperties& oSubProperties,
470  const std::vector<std::pair<ValueType, std::string>>& oValueList,
471  bool bRestrictToValues = true)
472 {
473  set_property<unsigned int>(oSubProperties,
474  detail::tReservedProperties::strValueListCount,
475  static_cast<unsigned int>(oValueList.size()));
476  set_property<bool>(oSubProperties,
477  detail::tReservedProperties::strValueListRestricted,
478  bRestrictToValues);
479 
480  size_t nIndex = 0;
481  for (const auto& oValue: oValueList)
482  {
483  set_property<T>(oSubProperties,
484  util::cString::Format(detail::tReservedProperties::strValueListValueFormat, nIndex),
485  storage_type<ValueType>::assign(oValue.first));
486  set_property<util::cString>(oSubProperties,
487  util::cString::Format(detail::tReservedProperties::strValueListNameFormat, nIndex),
488  oValue.second.c_str());
489  ++nIndex;
490  }
491 }
492 
493 template <typename T>
494 void set_valid_range(IProperties& oSubProperties, const T& xMin, const T& xMax)
495 {
496  set_property<T>(oSubProperties,
497  detail::tReservedProperties::strRangeMin,
498  xMin);
499  set_property<T>(oSubProperties,
500  detail::tReservedProperties::strRangeMax,
501  xMax);
502 }
503 
504 }
505 
510 {
511  public:
516 
522 
528 
535 
542 
546  ~cPropertyVariable() override;
547 
552 
557  void SetDisplayName(const char* strDisplayName);
558 
563  void SetDescription(const char* strDescription);
564 
571  void SetFilenameExtensionFilter(const char* strFilenameExtensionFilter);
572 
577  void SetFilenameOpenForWriting(bool bWriteMode);
578 
583  tVoid SetResolveMacros(tBool bResolveMacros);
584 
585  protected:
590 
591  protected:
592  class cImplementation;
593  std::unique_ptr<cImplementation> m_pImplementation;
594 };
595 
599 template <typename T>
601 {
602  private:
603  typedef typename giant::detail::storage_type<T>::type property_type;
604 
605  public:
609  property_variable() = default;
610 
615  property_variable(const T& xValue):
616  m_oValue(giant::detail::storage_type<T>::assign(xValue))
617  {
618  }
619 
620  property_variable& operator=(const T& xValue)
621  {
622  m_oValue = giant::detail::storage_type<T>::assign(xValue);
623  return *this;
624  }
625 
626  void Notify(const IProperty& oProperty) override
627  {
628  m_oValue.Set(*oProperty.GetValue());
629  }
630 
631  tResult GetType(IString&& strType) const override
632  {
633  return m_oValue.GetType(std::forward<IString>(strType));
634  }
635 
636  const IPropertyValue* GetValue() const override
637  {
638  return &m_oValue;
639  }
640 
641  const T& operator*() const
642  {
643  return GetReference();
644  }
645 
646  operator const T&() const
647  {
648  return GetReference();
649  }
650 
651  bool operator==(const T& oVal)
652  {
653  return GetReference() == oVal;
654  }
655 
656  bool operator!=(const T& oVal)
657  {
658  return GetReference() != oVal;
659  }
660 
661  const T* operator->()
662  {
663  return &GetReference();
664  }
665 
666  const T* operator->() const
667  {
668  return &GetReference();
669  }
670 
676  void SetValueList(const std::vector<std::pair<T, std::string>>& oValueList,
677  bool bRestrictToValues = true)
678  {
679  detail::set_value_list<property_type>(GetSubProperties(), oValueList, bRestrictToValues);
680  }
681 
687  void SetValidRange(const T& xMin, const T& xMax)
688  {
689  detail::set_valid_range<property_type>(GetSubProperties(),
692  }
693 
694  protected:
696 
697  private:
698  const T& GetReference() const
699  {
700  return reinterpret_cast<const T&>(m_oValue.GetValue());
701  }
702 };
703 
704 }
705 
706 namespace ant
707 {
708 
709 template<typename Interface>
710 tResult configuration<Interface>::RegisterPropertyVariable(const char* strName, cPropertyVariable& oPropertyVariable)
711 {
712  auto oParentsAndName = elasto::split_parents_and_leaf(strName);
713  detail::cPropertyVariableHelper oHelper(oParentsAndName.second.c_str(), *oPropertyVariable.GetValue());
714 
715  try
716  {
717  const auto& oGiantPropertyVariable = dynamic_cast<const giant::cPropertyVariable&>(oPropertyVariable);
718  RETURN_IF_FAILED(oHelper.SetProperties(oGiantPropertyVariable.GetSubProperties()));
719  }
720  catch (...)
721  {
722  }
723 
724  RETURN_IF_FAILED(elasto::create_property_tree(*m_pProperties, oParentsAndName.first.c_str()));
725  RETURN_IF_FAILED(m_pProperties->SetPropertyByPath(oParentsAndName.first.c_str(), oHelper));
726  RETURN_IF_FAILED(m_pProperties->RegisterPropertyObserver(strName, oPropertyVariable));
727  oPropertyVariable.SetUnregister(*this);
729 }
730 
731 }
732 
733 namespace hollow
734 {
735 
745  const char* strPropertyPathAndName,
746  ant::IProperty& oProperty);
747 
752 template <typename T>
754 {
755 public:
758 
760  property_variable& operator=(const T& oVal)
761  {
763  return *this;
764  }
765 
770  void SetPropertyChangedCallback(const std::function<void()> & fnCallback)
771  {
772  m_fnPropertyChangedCallback = fnCallback;
773  }
774 
775  void Notify(const IProperty& oProperty) override
776  {
778 
779  if (m_fnPropertyChangedCallback)
780  {
781  m_fnPropertyChangedCallback();
782  }
783  }
784 
785 private:
786  std::function<void()> m_fnPropertyChangedCallback;
787 
788 };
789 }
790 
791 using ant::get_property;
792 using ant::set_property;
793 
794 using ant::configuration;
795 using hollow::property_variable;
796 using ant::property_attached_configuration_type;
797 
798 using catwo::set_property_by_path;
799 using catwo::get_property_by_path;
800 
801 using flash::cConfiguration;
803 
804 } //namespace base
805 } //namespace adtf
A common result class usable as return value throughout.
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.
Definition: property_intf.h:60
The IString interface provides methods for getting and setting strings through abstract interfaces.
Definition: string_intf.h:26
tResult AttachProperties(const ucom::ant::iobject_ptr< IProperties > &pAttachedProperties) override
will set given properties to be attached
Default implemementation of a property_variable.
Definition: configuration.h:67
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...
adtf::ucom::object_ptr< cProperties > m_pProperties
the current runtiem property set
virtual ~configuration()=default
DTOR.
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.
Internal class helper to wrap e property variable for the SetProperty call without copy.
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
Definition: configuration.h:47
::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type > base_type
internal base type
Definition: configuration.h:42
::adtf::base::ant::property_attached_configuration_type value_type
internal value type
Definition: configuration.h:40
tResult Set(const IPropertyValue &oValue)
Sets the value by a deep copy.
Definition: property.h:260
tResult GetType(IString &&strType) const
Retrieves the string for the property value type.
Definition: property.h:310
Property Variable template for the given T.
void Notify(const IProperty &oProperty) override
Implements the observer pattern.
tResult GetType(IString &&strType) const override
Returns the identifier of the type.
property_variable(const T &oValue)
type initializing CTOR
const IPropertyValue * GetValue() const override
Property property implementation template.
Definition: property.h:380
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.
Property Variable template for the given T.
Base class for property_variable.
cPropertyVariable()
The default constructor.
void SetDescription(const char *strDescription)
Sets the description text associated with the Property.
~cPropertyVariable() override
Destructor.
ant::IProperties & GetSubProperties()
void SetFilenameOpenForWriting(bool bWriteMode)
Sets the write mode for the file property.
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.
cPropertyVariable & operator=(cPropertyVariable &&oOther)
Move assignment operator.
cPropertyVariable & operator=(const cPropertyVariable &oOther)
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.
const ant::IProperties & GetSubProperties() const
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.
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.
const IPropertyValue * GetValue() const override
void SetValueList(const std::vector< std::pair< T, std::string >> &oValueList, bool bRestrictToValues=true)
Sets a value list, that the user can choose from.
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.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:158
Use this template if you want to implement an ucom::ant::IObject based Interface and/or subclass an e...
Definition: object.h:379
Copyright © Audi Electronics Venture GmbH.
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2772
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.
tResult create_property_tree(ant::IProperties &oProperties, const char *strPath)
Creates a property tree structure.
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 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 entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define IS_FAILED(s)
Check if result is failed.
#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.
#define IS_OK(s)
Check if result is OK.
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
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).
Concept template to define the Name and the conversion type for the given type TYPE.
Definition: property.h:39