ADTF  3.18.1
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 #include <cinttypes>
18 
19 namespace adtf
20 {
21 namespace base
22 {
23 namespace ant
24 {
26  {
27  };
28 
29  template<>
31  {
32  constexpr static const tChar* const TYPE_NAME = "attached_config";
34  };
35 
36  namespace detail
37  {
38  class cRefConfigProperty : public ::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type>
39  {
41  typedef ::adtf::base::ant::property_attached_configuration_type value_type;
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>
101  {
102  private:
105 
106  public:
109  {
110  }
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  {
158  {
159  private:
160  const IPropertyValue* m_pValue;
161 
162  public:
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:
208  {
209  m_pProperties = adtf::ucom::make_object_ptr<spider::cProperties>();
210  }
212  virtual ~configuration() = default;
213  public:
219  {
221  pProperties.Reset(pConstProps);
223  }
229  {
231  pProperties.Reset(pProps);
233  }
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  }
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 
332 namespace catwo
333 {
334 
335 template <typename VALUETYPE>
336 tResult 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 
343 template <typename VALUETYPE>
344 VALUETYPE 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 
354 template <typename VALUETYPE>
355 VALUETYPE get_property_by_path(const IConfiguration& oConfiguration, const char* strPathAndName)
356 {
357  return get_property_by_path(oConfiguration, strPathAndName, VALUETYPE());
358 }
359 
360 }
361 
362 namespace flash
363 {
364 
369 {
370  public:
374  virtual ~cConfiguration();
375 
381  tResult AttachConfiguration(const char* strName,
382  IConfiguration& oAttachedConfiguration);
384  tResult DetachConfiguration(const char* strName);
385 
392  tResult RegisterPropertyVariable(const char* strName,
393  ant::cPropertyVariable& oPropertyVariable);
394 
395  private:
396  class cImplementation;
397  std::unique_ptr<cImplementation> m_pImplementation;
398 };
399 
404 template<typename T>
406 {
407  public:
409 
410  const T* operator->()
411  {
412  return &static_cast<const T&>(*this);
413  }
414 };
415 
416 }
417 
418 namespace giant
419 {
420 
421 namespace detail
422 {
423 
425 {
426  static constexpr const tChar* const strReservedPrefix = "#__";
427  static constexpr const tChar* const strDisplayName = "#__display_name";
428  static constexpr const tChar* const strDescription = "#__description";
429  static constexpr const tChar* const strRangeMin = "#__range_min";
430  static constexpr const tChar* const strRangeMax = "#__range_max";
431  static constexpr const tChar* const strValueListCount = "#__value_list_count";
432  static constexpr const tChar* const strValueListValueFormat = "#__value_list_value_%zu";
433  static constexpr const tChar* const strValueListNameFormat = "#__value_list_name_%zu";
434  static constexpr const tChar* const strValueListRestricted = "#__value_list_restricted";
435  static constexpr const tChar* const strEditorListCount = "#__editor_list_count";
436  static constexpr const tChar* const strEditorListNameFormat = "#__editor_list_name_%zu";
437  static constexpr const tChar* const strEditorListUrlFormat = "#__editor_list_url_%zu";
438  static constexpr const tChar* const strServiceDefaultRunlevel = "#__service_default_runlevel";
439  static constexpr const tChar* const strFilenameExtensionFilter = "#__filename_extension_filter";
440  static constexpr const tChar* const strFilenameOpenForWriting = "#__filename_open_for_writing";
441  static constexpr const tChar* const strHelpLink = "#__help_link";
442  static constexpr const tChar* const strItemDescriptions = "#__item_descriptions";
443  static constexpr const tChar* const strResolveMacros = "#__resolve_macros";
444 };
445 
446 template <typename U, typename Enable = void>
448 
449 template<typename U>
450 struct 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 
459 template <typename U>
460 struct 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 
469 template <typename T, typename ValueType>
470 void 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 
494 template <typename T>
495 void 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 
547  ~cPropertyVariable() override;
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 
600 template <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  {
623  m_oValue = giant::detail::storage_type<T>::assign(xValue);
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 
707 namespace ant
708 {
709 
710 template<typename Interface>
711 tResult 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 
734 namespace hollow
735 {
736 
746  const char* strPropertyPathAndName,
747  ant::IProperty& oProperty);
748 
753 template <typename T>
755 {
756 public:
759 
761  property_variable& operator=(const T& oVal)
762  {
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 
786 private:
787  std::function<void()> m_fnPropertyChangedCallback;
788 
789 };
790 }
791 
792 using ant::get_property;
793 using ant::set_property;
794 
795 using ant::configuration;
796 using hollow::property_variable;
797 using ant::property_attached_configuration_type;
798 
799 using catwo::set_property_by_path;
800 using catwo::get_property_by_path;
801 
802 using flash::cConfiguration;
804 
805 } //namespace base
806 } //namespace adtf
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).
#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.
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:28
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:68
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.
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:48
::adtf::base::ant::property<::adtf::base::ant::property_attached_configuration_type > base_type
internal base type
Definition: configuration.h:43
::adtf::base::ant::property_attached_configuration_type value_type
internal value type
Definition: configuration.h:41
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.
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:212
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:163
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:2778
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.
Concept template to define the Name and the conversion type for the given type TYPE.