From b0dc65af0dadba329142efb39ca2f510a85d51c4 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 2 Mar 2016 21:51:44 +0100 Subject: [PATCH] [DEV] correct interface declaration --- eproperty/Interface.cpp | 2 +- eproperty/Interface.h | 10 ++++------ eproperty/List.h | 16 +++++++++++----- eproperty/Property.cpp | 28 +++++++++++++++++----------- eproperty/Property.h | 25 ++++++++++--------------- eproperty/Range.h | 18 +++++++++++++----- eproperty/Value.h | 25 ++++++++++--------------- 7 files changed, 66 insertions(+), 58 deletions(-) diff --git a/eproperty/Interface.cpp b/eproperty/Interface.cpp index 24fe31e..db093fe 100644 --- a/eproperty/Interface.cpp +++ b/eproperty/Interface.cpp @@ -73,7 +73,7 @@ void eproperty::Interface::propertyDisplay(bool _changeOnly) const { } } -void eproperty::Interface::onPropertyChangeValue(const eproperty::Ref& _paramPointer) { +void eproperty::Interface::onPropertyChangeValue() { // nothing to do ... } diff --git a/eproperty/Interface.h b/eproperty/Interface.h index 2fb6ec4..1eecf89 100644 --- a/eproperty/Interface.h +++ b/eproperty/Interface.h @@ -16,7 +16,7 @@ namespace eproperty { class Interface { friend class eproperty::Property; // to register property in the list. private: - std::vector m_list; //!< list of availlable Propertys (no need to free) + std::vector m_list; //!< list of availlable Propertys (no need to free) public: /** * @brief Constructor. @@ -56,16 +56,14 @@ namespace eproperty { * @param[in] changeOnly check at true if the user want to display only property that are not at default value. */ void propertyDisplay(bool _changeOnly = false) const; - /** - * @brief Called when a property change value. - * @param[in] _paramPointer Pointer on the property (to know which property have change); - */ - virtual void onPropertyChangeValue(const eproperty::Ref& _paramPointer); /** * @brief Get All the property configuration: * @return map on the propertys */ std::map propertyGetAll(bool _notIfDefault=true) const; + + // deprecated + virtual void onPropertyChangeValue(); public: /** * @brief Get count of propertys. diff --git a/eproperty/List.h b/eproperty/List.h index 0526c4d..e73361f 100644 --- a/eproperty/List.h +++ b/eproperty/List.h @@ -22,18 +22,24 @@ namespace eproperty { public: /** * @brief Create a parameter with List of element parameter. - * @param[in] _objectLink reference on the parameter lister. + * @param[in] _owner reference on the parameter lister. * @param[in] _name Static name of the parameter. + * @param[in] _defaultValue Default value of the parameter. * @param[in] _description description of the parameter. + * @param[in] _setObs function of the class that opserve the change of the value */ - List(eproperty::Interface& _paramInterfaceLink, + template + List(CLASS_TYPE* _owner, const std::string& _name, const TYPE& _defaultValue, - const std::string& _description="") : - Property(_paramInterfaceLink, _name), + const std::string& _description="", + void (CLASS_TYPE::*_setObs)()=nullptr) : + Property(_owner, _name), m_value(_defaultValue), m_default(_defaultValue) { - + if (_setObs != nullptr) { + setObserver([=](){(*_owner.*_setObs)();}); + } }; /** * @brief Destructor. diff --git a/eproperty/Property.cpp b/eproperty/Property.cpp index 12d4558..15b7043 100644 --- a/eproperty/Property.cpp +++ b/eproperty/Property.cpp @@ -11,22 +11,28 @@ #include -eproperty::Property::Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name) : +eproperty::Property::Property(eproperty::Interface* _paramInterfaceLink, const std::string& _name) : m_interfaceLink(_paramInterfaceLink), + m_setObserver(), m_name(_name) { // add a reference on the current Property ... - m_interfaceLink.propertyAdd(this); + if (m_interfaceLink != nullptr) { + m_interfaceLink->propertyAdd(this); + } +} + +void eproperty::Property::setObserver(eproperty::Property::Observer _setObs) { + m_setObserver = _setObs; +} + +std::string eproperty::Property::getName() const { + return m_name; } void eproperty::Property::notifyChange() const { - m_interfaceLink.onPropertyChangeValue(eproperty::Ref(this)); -} - -bool eproperty::operator==(const eproperty::Ref& _obj, const eproperty::Property& _obj2) noexcept { - return &_obj2 == _obj.m_ref; -} - -bool eproperty::operator==(const eproperty::Property& _obj2, const eproperty::Ref& _obj) noexcept { - return &_obj2 == _obj.m_ref; + if (m_setObserver != nullptr) { + m_setObserver(); + } + //m_interfaceLink.onPropertyChangeValue(); } diff --git a/eproperty/Property.h b/eproperty/Property.h index 964c487..e775923 100644 --- a/eproperty/Property.h +++ b/eproperty/Property.h @@ -10,16 +10,23 @@ #include #include #include +#include namespace eproperty { class Ref; class Property { + public: + using Observer = std::function; private: - eproperty::Interface& m_interfaceLink; + eproperty::Interface* m_interfaceLink; + Observer m_setObserver; std::string m_name; public: - Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name); + Property(eproperty::Interface* _paramInterfaceLink, const std::string& _name); virtual ~Property() = default; + protected: + void setObserver(eproperty::Property::Observer _setObs); + public: /** * @brief call main class that PropertyChange */ @@ -28,9 +35,7 @@ namespace eproperty { * @brief Get the name of the Property. * @return The name of the Property */ - virtual std::string getName() const { - return m_name; - }; + virtual std::string getName() const; /** * @brief Description of the Propertys. * @return Descriptive information of the Property (for remote UI). @@ -84,15 +89,5 @@ namespace eproperty { template bool operator> (const TYPE& _obj) const = delete; }; - class Ref { - public: - const Property* m_ref; - Ref(const Property* _ref) : - m_ref(_ref) { - // nothing to do ... - } - }; - bool operator==(const Ref& _obj, const Property& _obj2) noexcept; - bool operator==(const Property& _obj2, const Ref& _obj) noexcept; } diff --git a/eproperty/Range.h b/eproperty/Range.h index 6d02307..9f1247e 100644 --- a/eproperty/Range.h +++ b/eproperty/Range.h @@ -21,25 +21,33 @@ namespace eproperty { public: /** * @brief Create a parameter with a specific type. - * @param[in] _objectLink reference on the parameter lister. + * @param[in] _owner reference on the parameter lister. * @param[in] _name Static name of the parameter. * @param[in] _defaultValue Default value of the parameter. * @param[in] _min Minumum value. * @param[in] _max Maximum value. * @param[in] _description description of the parameter. + * @param[in] _setObs function of the class that opserve the change of the value */ - Range(eproperty::Interface& _paramInterfaceLink, + template + Range(CLASS_TYPE* _owner, const std::string& _name, const TYPE& _defaultValue, const TYPE& _min, const TYPE& _max, - const std::string& _description = "") : - Property(_paramInterfaceLink, _name), + const std::string& _description = "", + void (CLASS_TYPE::*_setObs)()=nullptr) : + Property(_owner, _name), m_value(_defaultValue), m_min(_min), m_max(_max), m_default(_defaultValue) { - + if (m_min > m_max) { + //EPROPERTY_CRITICAL("min > max..."); + } + if (_setObs != nullptr) { + setObserver([=](){(*_owner.*_setObs)();}); + } }; /** * @brief Destructor. diff --git a/eproperty/Value.h b/eproperty/Value.h index f1d7c37..97d8f5c 100644 --- a/eproperty/Value.h +++ b/eproperty/Value.h @@ -19,29 +19,24 @@ namespace eproperty { public: /** * @brief Create a parameter with a specific type. - * @param[in] _objectLink reference on the parameter lister. + * @param[in] _owner Owner of the parameter. * @param[in] _name Static name of the parameter. * @param[in] _defaultValue Default value of the parameter. - * @param[in] _min Minumum value. - * @param[in] _max Maximum value. * @param[in] _description description of the parameter. + * @param[in] _setObs function of the class that opserve the change of the value */ - Value(eproperty::Interface& _paramInterfaceLink, + template + Value(CLASS_TYPE* _owner, const std::string& _name, const TYPE& _defaultValue, - const std::string& _description = "") : - Property(_paramInterfaceLink, _name), + const std::string& _description = "", + void (CLASS_TYPE::*_setObs)()=nullptr) : + Property(_owner, _name), m_value(_defaultValue), m_default(_defaultValue) { - - } - Value(eproperty::Interface& _paramListLink, - const std::string& _name, - const std::string& _description = "") : - Property(_paramListLink, _name), - m_value(), - m_default() { - + if (_setObs != nullptr) { + setObserver([=](){(*_owner.*_setObs)();}); + } } /** * @brief Destructor.