[DEV] correct interface declaration

This commit is contained in:
Edouard DUPIN 2016-03-02 21:51:44 +01:00
parent 28ce277bba
commit b0dc65af0d
7 changed files with 66 additions and 58 deletions

View File

@ -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 ... // nothing to do ...
} }

View File

@ -16,7 +16,7 @@ namespace eproperty {
class Interface { class Interface {
friend class eproperty::Property; // to register property in the list. friend class eproperty::Property; // to register property in the list.
private: private:
std::vector<eproperty::Property*> m_list; //!< list of availlable Propertys (no need to free) std::vector<eproperty::Property*> m_list; //!< list of availlable Propertys (no need to free)
public: public:
/** /**
* @brief Constructor. * @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. * @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; 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: * @brief Get All the property configuration:
* @return map on the propertys * @return map on the propertys
*/ */
std::map<std::string, std::string> propertyGetAll(bool _notIfDefault=true) const; std::map<std::string, std::string> propertyGetAll(bool _notIfDefault=true) const;
// deprecated
virtual void onPropertyChangeValue();
public: public:
/** /**
* @brief Get count of propertys. * @brief Get count of propertys.

View File

@ -22,18 +22,24 @@ namespace eproperty {
public: public:
/** /**
* @brief Create a parameter with List of element parameter. * @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] _name Static name of the parameter.
* @param[in] _defaultValue Default value of the parameter.
* @param[in] _description description 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<class CLASS_TYPE>
List(CLASS_TYPE* _owner,
const std::string& _name, const std::string& _name,
const TYPE& _defaultValue, const TYPE& _defaultValue,
const std::string& _description="") : const std::string& _description="",
Property(_paramInterfaceLink, _name), void (CLASS_TYPE::*_setObs)()=nullptr) :
Property(_owner, _name),
m_value(_defaultValue), m_value(_defaultValue),
m_default(_defaultValue) { m_default(_defaultValue) {
if (_setObs != nullptr) {
setObserver([=](){(*_owner.*_setObs)();});
}
}; };
/** /**
* @brief Destructor. * @brief Destructor.

View File

@ -11,22 +11,28 @@
#include <eproperty/Property.h> #include <eproperty/Property.h>
eproperty::Property::Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name) : eproperty::Property::Property(eproperty::Interface* _paramInterfaceLink, const std::string& _name) :
m_interfaceLink(_paramInterfaceLink), m_interfaceLink(_paramInterfaceLink),
m_setObserver(),
m_name(_name) { m_name(_name) {
// add a reference on the current Property ... // 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 { void eproperty::Property::notifyChange() const {
m_interfaceLink.onPropertyChangeValue(eproperty::Ref(this)); if (m_setObserver != nullptr) {
} m_setObserver();
}
bool eproperty::operator==(const eproperty::Ref& _obj, const eproperty::Property& _obj2) noexcept { //m_interfaceLink.onPropertyChangeValue();
return &_obj2 == _obj.m_ref;
}
bool eproperty::operator==(const eproperty::Property& _obj2, const eproperty::Ref& _obj) noexcept {
return &_obj2 == _obj.m_ref;
} }

View File

@ -10,16 +10,23 @@
#include <eproperty/Interface.h> #include <eproperty/Interface.h>
#include <string> #include <string>
#include <typeinfo> #include <typeinfo>
#include <functional>
namespace eproperty { namespace eproperty {
class Ref; class Ref;
class Property { class Property {
public:
using Observer = std::function<void()>;
private: private:
eproperty::Interface& m_interfaceLink; eproperty::Interface* m_interfaceLink;
Observer m_setObserver;
std::string m_name; std::string m_name;
public: public:
Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name); Property(eproperty::Interface* _paramInterfaceLink, const std::string& _name);
virtual ~Property() = default; virtual ~Property() = default;
protected:
void setObserver(eproperty::Property::Observer _setObs);
public:
/** /**
* @brief call main class that PropertyChange * @brief call main class that PropertyChange
*/ */
@ -28,9 +35,7 @@ namespace eproperty {
* @brief Get the name of the Property. * @brief Get the name of the Property.
* @return The name of the Property * @return The name of the Property
*/ */
virtual std::string getName() const { virtual std::string getName() const;
return m_name;
};
/** /**
* @brief Description of the Propertys. * @brief Description of the Propertys.
* @return Descriptive information of the Property (for remote UI). * @return Descriptive information of the Property (for remote UI).
@ -84,15 +89,5 @@ namespace eproperty {
template<class TYPE> template<class TYPE>
bool operator> (const TYPE& _obj) const = delete; 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;
} }

View File

@ -21,25 +21,33 @@ namespace eproperty {
public: public:
/** /**
* @brief Create a parameter with a specific type. * @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] _name Static name of the parameter.
* @param[in] _defaultValue Default value of the parameter. * @param[in] _defaultValue Default value of the parameter.
* @param[in] _min Minumum value. * @param[in] _min Minumum value.
* @param[in] _max Maximum value. * @param[in] _max Maximum value.
* @param[in] _description description of the parameter. * @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<class CLASS_TYPE>
Range(CLASS_TYPE* _owner,
const std::string& _name, const std::string& _name,
const TYPE& _defaultValue, const TYPE& _defaultValue,
const TYPE& _min, const TYPE& _min,
const TYPE& _max, const TYPE& _max,
const std::string& _description = "") : const std::string& _description = "",
Property(_paramInterfaceLink, _name), void (CLASS_TYPE::*_setObs)()=nullptr) :
Property(_owner, _name),
m_value(_defaultValue), m_value(_defaultValue),
m_min(_min), m_min(_min),
m_max(_max), m_max(_max),
m_default(_defaultValue) { m_default(_defaultValue) {
if (m_min > m_max) {
//EPROPERTY_CRITICAL("min > max...");
}
if (_setObs != nullptr) {
setObserver([=](){(*_owner.*_setObs)();});
}
}; };
/** /**
* @brief Destructor. * @brief Destructor.

View File

@ -19,29 +19,24 @@ namespace eproperty {
public: public:
/** /**
* @brief Create a parameter with a specific type. * @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] _name Static name of the parameter.
* @param[in] _defaultValue Default value 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] _description description of the parameter.
* @param[in] _setObs function of the class that opserve the change of the value
*/ */
Value(eproperty::Interface& _paramInterfaceLink, template<class CLASS_TYPE>
Value(CLASS_TYPE* _owner,
const std::string& _name, const std::string& _name,
const TYPE& _defaultValue, const TYPE& _defaultValue,
const std::string& _description = "") : const std::string& _description = "",
Property(_paramInterfaceLink, _name), void (CLASS_TYPE::*_setObs)()=nullptr) :
Property(_owner, _name),
m_value(_defaultValue), m_value(_defaultValue),
m_default(_defaultValue) { m_default(_defaultValue) {
if (_setObs != nullptr) {
} setObserver([=](){(*_owner.*_setObs)();});
Value(eproperty::Interface& _paramListLink, }
const std::string& _name,
const std::string& _description = "") :
Property(_paramListLink, _name),
m_value(),
m_default() {
} }
/** /**
* @brief Destructor. * @brief Destructor.