diff --git a/eproperty/InterfaceData.cpp b/eproperty/InterfaceData.cpp index 24e3742..71fe9ab 100644 --- a/eproperty/InterfaceData.cpp +++ b/eproperty/InterfaceData.cpp @@ -34,8 +34,22 @@ void eproperty::InterfaceData::add(eproperty::Property* _pointerOnProperty) { m_list.pushBack(_pointerOnProperty); } +void eproperty::InterfaceData::remove(eproperty::Property* _pointerOnProperty) { + if (_pointerOnProperty == nullptr) { + EPROPERTY_ERROR("Try to un-link a nullptr properties"); + return; + } + auto it = m_list.begin(); + while (it != m_list.end()) { + if(*it == _pointerOnProperty) { + it = m_list.erase(it); + } else { + ++it; + } + } +} void eproperty::InterfaceData::clean() { - // remove all pointer on these propertys + // remove all pointer on these properties m_list.clear(); } @@ -49,7 +63,7 @@ bool eproperty::InterfaceData::set(const etk::String& _property, const etk::Stri return true; } } - // can not find the propertys : + // can not find the properties : return false; } @@ -64,7 +78,7 @@ etk::String eproperty::InterfaceData::get(const etk::String& _property) const { } void eproperty::InterfaceData::display(bool _changeOnly) const { - EPROPERTY_INFO(" Object propertys:"); + EPROPERTY_INFO(" Object properties:"); for (auto &it : m_list) { if(it != nullptr) { etk::String paramName = it->getName(); diff --git a/eproperty/InterfaceData.hpp b/eproperty/InterfaceData.hpp index 0885f60..29aa476 100644 --- a/eproperty/InterfaceData.hpp +++ b/eproperty/InterfaceData.hpp @@ -18,7 +18,7 @@ namespace eproperty { */ class InterfaceData { private: - etk::Vector m_list; //!< list of availlable Propertys (no need to free) + etk::Vector m_list; //!< list of availlable properties (no need to free) public: /** * @brief Constructor. @@ -29,11 +29,16 @@ namespace eproperty { */ virtual ~InterfaceData(); /** - * @brief Register a property class pointer in the List of propertys + * @brief Register a property class pointer in the List of properties * @note This class does not destroy the property pointer!!! * @param[in] _pointerOnProperty Pointer on the property that might be added. */ void add(Property* _pointerOnProperty); + /** + * @brief Un-Register a property class pointer in the List of properties + * @param[in] _pointerOnProperty Pointer on the property that might be removed. + */ + void remove(Property* _pointerOnProperty); /** * @brief Remove all the property reference in this class. * @note no delete, just clean and inform that a property has not been removed. @@ -61,23 +66,23 @@ namespace eproperty { /** * @brief Get All the property configuration: * @param[in] _notIfDefault if true the parameter value with default value are not extracted. - * @return map on the propertys + * @return map on the properties */ etk::Map getAll(bool _notIfDefault=true) const; public: /** - * @brief Get count of propertys. + * @brief Get count of properties. * @return The number of the property. */ size_t size() const; /** - * @brief Get name of a propertys. + * @brief Get name of a properties. * @param[in] _id Id of the property. * @return pointer on the property. */ eproperty::Property* getRaw(const size_t& _id) const; /** - * @brief Get name of a propertys. + * @brief Get name of a properties. * @param[in] _name name of the property. * @return pointer on the property. */ diff --git a/eproperty/List.hpp b/eproperty/List.hpp index 04d82e8..a66b82c 100644 --- a/eproperty/List.hpp +++ b/eproperty/List.hpp @@ -43,10 +43,38 @@ namespace eproperty { eproperty::PropertyType(_defaultValue) { }; + /** + * @brief Remove copy contructor + */ + List(List& _obj) = delete; + /** + * @brief Enable move contructor + */ + List(List&& _obj) : + PropertyType::PropertyType(_obj.m_default) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + etk::swap(m_list, _obj.m_list); + }; /** * @brief virtualisation of Destructor. */ virtual ~List() = default; + /** + * @brief Remove copy operator + */ + List& operator=(List& _obj) = delete; + /** + * @brief Enable move operator + */ + List& operator=(List&& _obj) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + etk::swap(m_list, _obj.m_list); + return *this; + }; /** * @brief Add a value in the list of parameter * @param[in] _value Value of the string diff --git a/eproperty/Property.cpp b/eproperty/Property.cpp index 10c93cf..1ccfb9a 100644 --- a/eproperty/Property.cpp +++ b/eproperty/Property.cpp @@ -11,23 +11,72 @@ #include -eproperty::Property::Property(eproperty::Interface* _paramInterfaceLink, const etk::String& _name) : - m_interfaceLink(_paramInterfaceLink), - m_setObserver(), - m_name(_name) { +void eproperty::Property::linkInterface() { // add a reference on the current Property ... if (m_interfaceLink != nullptr) { m_interfaceLink->properties.add(this); } } -eproperty::Property::Property() : - m_interfaceLink(nullptr), +void eproperty::Property::unLinkInterface() { + if (m_interfaceLink != nullptr) { + m_interfaceLink->properties.remove(this); + } +} + +eproperty::Property::Property(eproperty::Interface* _paramInterfaceLink, const etk::String& _name) : + m_interfaceLink(_paramInterfaceLink), m_setObserver(), - m_name("") { + m_name(_name) { + linkInterface(); +} + +void eproperty::Property::internalSwap(Property* _obj) { + // unplug main class + _obj->unLinkInterface(); + unLinkInterface(); + // change data + etk::swap(m_interfaceLink, _obj->m_interfaceLink); + etk::swap(m_setObserver, _obj->m_setObserver); + etk::swap(m_name, _obj->m_name); + // replug main class + linkInterface(); + _obj->linkInterface(); +} + +eproperty::Property::Property() { } +eproperty::Property::Property(Property&& _obj) { + // unplug main class + _obj.unLinkInterface(); + // change data + etk::swap(m_interfaceLink, _obj.m_interfaceLink); + etk::swap(m_setObserver, _obj.m_setObserver); + etk::swap(m_name, _obj.m_name); + // replug main class + linkInterface(); +} + +eproperty::Property::~Property(){ + unLinkInterface(); +} + +eproperty::Property& eproperty::Property::operator=(Property&& _obj) { + // unplug main class + _obj.unLinkInterface(); + unLinkInterface(); + // change data + etk::swap(m_interfaceLink, _obj.m_interfaceLink); + etk::swap(m_setObserver, _obj.m_setObserver); + etk::swap(m_name, _obj.m_name); + // replug main class + _obj.linkInterface(); + linkInterface(); + return *this; +} + void eproperty::Property::setObserver(eproperty::Property::Observer _setObs) { m_setObserver = _setObs; } diff --git a/eproperty/Property.hpp b/eproperty/Property.hpp index 156adee..c5b0d6b 100644 --- a/eproperty/Property.hpp +++ b/eproperty/Property.hpp @@ -19,12 +19,13 @@ namespace eproperty { class Ref; /** * @brief Base of the property With all generic element needed + * @note A property is movable but not comiable ==> the atachement of an interface is a critical thngs */ class Property { public: using Observer = etk::Function; //!< Local main object observer of changing value of the property - private: - eproperty::Interface* m_interfaceLink; //!< Base interface class to group all the property + protected: + eproperty::Interface* m_interfaceLink = nullptr; //!< Base interface class to group all the property Observer m_setObserver; //!< Observer of the changing value etk::String m_name; //!< Name of the property public: @@ -38,17 +39,46 @@ namespace eproperty { * @brief Basic property elements */ Property(); + /** + * @brief Remove copy contructor + */ + Property(const Property& _obj) = delete; + /** + * @brief Enable move contructor + */ + Property(Property&& _obj); /** * @brief Virtualize the destructor * @internal */ - virtual ~Property() = default; + virtual ~Property(); + /** + * @brief Remove copy operator + */ + Property& operator=(const Property& _obj) = delete; + /** + * @brief Enable move operator + */ + Property& operator=(Property&& _obj); protected: /** * @brief Set the change observer of the property * @param[in] _setObs New observer of the property */ void setObserver(eproperty::Property::Observer _setObs); + /** + * @brief Link with the interface reference. + */ + void linkInterface(); + /** + * @brief Un-link with the interface reference. + */ + void unLinkInterface(); + /** + * @brief swap local data class. + * @note Must be Nullptr. + */ + void internalSwap(Property* _obj); public: /** * @brief call main class that PropertyChange diff --git a/eproperty/PropertyType.hpp b/eproperty/PropertyType.hpp index ffccd1c..789a63e 100644 --- a/eproperty/PropertyType.hpp +++ b/eproperty/PropertyType.hpp @@ -51,10 +51,35 @@ namespace eproperty { m_default(_defaultValue) { } + /** + * @brief Remove copy contructor + */ + PropertyType(PropertyType& _obj) = delete; + /** + * @brief Enable move contructor + */ + PropertyType(PropertyType&& _obj) { + Property::internalSwap(&_obj); + etk::swap(m_default, _obj.m_default); + etk::swap(m_value, _obj.m_value); + } /** * @brief Destructor. */ virtual ~PropertyType() = default; + /** + * @brief Remove copy operator + */ + PropertyType& operator=(PropertyType& _obj) = delete; + /** + * @brief Enable move operator + */ + PropertyType& operator=(PropertyType&& _obj) { + Property::internalSwap(&_obj); + etk::swap(m_default, _obj.m_default); + etk::swap(m_value, _obj.m_value); + return *this; + } etk::String getPropertyType() const override { return "eproperty::Value"; } diff --git a/eproperty/Range.hpp b/eproperty/Range.hpp index 97145f1..2527fa1 100644 --- a/eproperty/Range.hpp +++ b/eproperty/Range.hpp @@ -54,10 +54,40 @@ namespace eproperty { Range(const TYPE& _defaultValue, const TYPE& _min, const TYPE& _max); + /** + * @brief Remove copy contructor + */ + Range(Range& _obj) = delete; + /** + * @brief Enable move contructor + */ + Range(Range&& _obj) : + Value::Value(_obj.m_default) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + etk::swap(m_min, _obj.m_min); + etk::swap(m_max, _obj.m_max); + }; /** * @brief Destructor. */ virtual ~Range() = default; + /** + * @brief Remove copy operator + */ + Range& operator=(Range& _obj) = delete; + /** + * @brief Enable move operator + */ + Range& operator=(Range&& _obj) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + etk::swap(m_min, _obj.m_min); + etk::swap(m_max, _obj.m_max); + return *this; + }; etk::String getPropertyType() const override; void setString(const etk::String& _newVal) override; etk::String getInfo() const override; diff --git a/eproperty/Value.hpp b/eproperty/Value.hpp index dbeb31c..8af347a 100644 --- a/eproperty/Value.hpp +++ b/eproperty/Value.hpp @@ -41,6 +41,36 @@ namespace eproperty { * @param[in] _defaultValue Default value of the parameter. */ Value(const TYPE& _defaultValue); + /** + * @brief Remove copy contructor + */ + Value(Value& _obj) = delete; + /** + * @brief Enable move contructor + */ + Value(Value&& _obj) : + PropertyType::PropertyType(_obj.m_default) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + }; + /** + * @brief default destructor + */ + virtual ~Value() = default; + /** + * @brief Remove copy operator + */ + Value& operator=(Value& _obj) = delete; + /** + * @brief Enable move operator + */ + Value& operator=(Value&& _obj) { + Property::internalSwap(&_obj); + etk::swap(PropertyType::m_default, _obj.m_default); + etk::swap(PropertyType::m_value, _obj.m_value); + return *this; + }; public: etk::String getValueSpecific(const TYPE& _valueRequested) const override; void setString(const etk::String& _newVal) override;