From 28ce277bbae2108a51768321a7602ea76eddc12f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 24 Feb 2016 22:27:54 +0100 Subject: [PATCH] [DEV] better property (simplify and remove stupid comportment --- eproperty/List.h | 65 +++++++++++++++++++++----------------- eproperty/Property.h | 13 ++++++++ eproperty/Range.h | 74 ++++++++++++++++++++++++-------------------- eproperty/Value.h | 59 +++++++++++++++++++---------------- 4 files changed, 122 insertions(+), 89 deletions(-) diff --git a/eproperty/List.h b/eproperty/List.h index c33b93a..0526c4d 100644 --- a/eproperty/List.h +++ b/eproperty/List.h @@ -14,11 +14,11 @@ #include namespace eproperty { - template class List : public Property { + template class List : public Property { private: - MY_TYPE m_value; //!< Element value ==> can be directly used. - MY_TYPE m_default; //!< Default value. - std::map m_list; //!< pointer on the list of all elements. + TYPE m_value; //!< Element value ==> can be directly used. + TYPE m_default; //!< Default value. + std::map m_list; //!< pointer on the list of all elements. public: /** * @brief Create a parameter with List of element parameter. @@ -28,7 +28,7 @@ namespace eproperty { */ List(eproperty::Interface& _paramInterfaceLink, const std::string& _name, - const MY_TYPE& _defaultValue, + const TYPE& _defaultValue, const std::string& _description="") : Property(_paramInterfaceLink, _name), m_value(_defaultValue), @@ -39,7 +39,7 @@ namespace eproperty { * @brief Destructor. */ virtual ~List() = default; - void add(const MY_TYPE& _value, const std::string& _name, const std::string& _description = "") { + void add(const TYPE& _value, const std::string& _name, const std::string& _description = "") { auto it = m_list.find(_name); if (it != m_list.end()) { it->second = _value; @@ -53,7 +53,7 @@ namespace eproperty { } // herited methode virtual std::string getType() const { - return typeid(MY_TYPE).name(); + return typeid(TYPE).name(); } // herited methode virtual std::string getString() const { @@ -94,24 +94,21 @@ namespace eproperty { virtual void setDefault() { set(m_default); } - void setDefaultValue(const MY_TYPE& _value) { + void setDefaultValue(const TYPE& _value) { m_default = _value; } /** * @brief Get the value of the current parameter. * @return the Reference value */ - inline MY_TYPE& get() { - return m_value; - }; - const inline MY_TYPE& get() const { + const inline TYPE& get() const { return m_value; }; /** * @brief Set the value of the current parameter. * @param[in] _newVal New value of the parameter. (not set if out of range) */ - void set(MY_TYPE _newVal) { + void set(TYPE _newVal) { if (_newVal == m_value) { return; } @@ -124,13 +121,33 @@ namespace eproperty { } EPROPERTY_WARNING("paramList value=??? is not un the list ... ==> no change"); } + /** + * @brief Set the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @param[in] newVal New value to set + */ + inline void setDirect(const TYPE& _newVal) { + m_value = _newVal; + }; + /** + * @brief Get the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @return a reference on the value + */ + TYPE& getDirect() { + return m_value; + } private: /** * @brief Get the element description from real Value. * @param[in] _intValue value that might be converted in string. * @return the description string coresponding to this ID. */ - std::string getElement(MY_TYPE _intValue) const { + std::string getElement(TYPE _intValue) const { for (auto &it : m_list) { if (it.second == _intValue) { return it.first; @@ -139,28 +156,18 @@ namespace eproperty { return "???"; } public: - /** - * @brief assignement operator. - * @param[in] newVal The new value of the parameter. - */ - const List& operator= (MY_TYPE _newVal) { - set(_newVal); - return *this; - } - operator const MY_TYPE&() const { + const List& operator= (const TYPE& _newVal) = delete; + operator const TYPE&() const { return m_value; } - MY_TYPE& operator *() const noexcept { + const TYPE& operator *() const noexcept { return m_value; } - const MY_TYPE* operator->() const noexcept { - return &m_value; - } - MY_TYPE* operator->() noexcept { + const TYPE* operator->() const noexcept { return &m_value; } }; - template std::ostream& operator <<(std::ostream& _os, const eproperty::List& _obj) { + template std::ostream& operator <<(std::ostream& _os, const eproperty::List& _obj) { _os << _obj.get(); return _os; } diff --git a/eproperty/Property.h b/eproperty/Property.h index 26b6d01..964c487 100644 --- a/eproperty/Property.h +++ b/eproperty/Property.h @@ -70,6 +70,19 @@ namespace eproperty { * @brief Reset the value to the default value. */ virtual void setDefault() = 0; + public: + template + bool operator== (const TYPE& _obj) const = delete; + template + bool operator!= (const TYPE& _obj) const = delete; + template + bool operator<= (const TYPE& _obj) const = delete; + template + bool operator>= (const TYPE& _obj) const = delete; + template + bool operator< (const TYPE& _obj) const = delete; + template + bool operator> (const TYPE& _obj) const = delete; }; class Ref { public: diff --git a/eproperty/Range.h b/eproperty/Range.h index ce96ad0..6d02307 100644 --- a/eproperty/Range.h +++ b/eproperty/Range.h @@ -12,12 +12,12 @@ #include namespace eproperty { - template class Range : public Property { + template class Range : public Property { private: - MY_TYPE m_value; //!< Current value. - MY_TYPE m_min; //!< Minimum value. - MY_TYPE m_max; //!< Maximum value. - MY_TYPE m_default; //!< Default value. + TYPE m_value; //!< Current value. + TYPE m_min; //!< Minimum value. + TYPE m_max; //!< Maximum value. + TYPE m_default; //!< Default value. public: /** * @brief Create a parameter with a specific type. @@ -30,9 +30,9 @@ namespace eproperty { */ Range(eproperty::Interface& _paramInterfaceLink, const std::string& _name, - const MY_TYPE& _defaultValue, - const MY_TYPE& _min, - const MY_TYPE& _max, + const TYPE& _defaultValue, + const TYPE& _min, + const TYPE& _max, const std::string& _description = "") : Property(_paramInterfaceLink, _name), m_value(_defaultValue), @@ -51,7 +51,7 @@ namespace eproperty { } // herited methode virtual std::string getType() const { - return typeid(MY_TYPE).name(); + return typeid(TYPE).name(); } // herited methode virtual std::string getString() const { @@ -63,7 +63,7 @@ namespace eproperty { }; // herited methode virtual void setString(const std::string& _newVal) { - MY_TYPE val; + TYPE val; // when you want to set an element in parameter you will implement the function template std::from_string etk::from_string(val, _newVal); set(val); @@ -83,65 +83,71 @@ namespace eproperty { public: /** * @brief Get the value of the current parameter. - * @note For performence, this function must be inline - * @return the Reference value + * @return The reference value */ - inline MY_TYPE& get() { - return m_value; - }; - const inline MY_TYPE& get() const { + const inline TYPE& get() const { return m_value; }; /** * @brief Set a new value for this parameter * @param[in] newVal New value to set (set the nearest value if range is set) */ - void set(const MY_TYPE& _newVal) { + void set(const TYPE& _newVal) { if (m_min == m_max) { if (_newVal != m_value) { m_value = _newVal; notifyChange(); } } else { - MY_TYPE newVal = std::avg(m_min, _newVal, m_max); + TYPE newVal = std::avg(m_min, _newVal, m_max); if (newVal != m_value) { m_value = newVal; notifyChange(); } } } + /** + * @brief Set the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @param[in] newVal New value to set + */ + inline void setDirect(const TYPE& _newVal) { + m_value = _newVal; + }; + /** + * @brief Get the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @return a reference on the value + */ + TYPE& getDirect() { + return m_value; + } private: /** * @brief Get the string of the specify value. * @return convetion of the velue in string. */ - std::string getValueSpecific(const MY_TYPE& _valueRequested) const { + std::string getValueSpecific(const TYPE& _valueRequested) const { return etk::to_string(_valueRequested); } public: - /** - * @brief assignement operator. - * @param[in] newVal The new value of the parameter. - */ - const Range& operator= (const MY_TYPE& _newVal) { - set(_newVal); - return *this; - }; - operator const MY_TYPE&() const { + const Range& operator= (const TYPE& _newVal) = delete; + operator const TYPE&() const { return m_value; } - MY_TYPE& operator *() const noexcept { + const TYPE& operator*() const noexcept { return m_value; } - const MY_TYPE* operator->() const noexcept { - return &m_value; - } - MY_TYPE* operator->() noexcept { + const TYPE* operator->() const noexcept { return &m_value; } }; - template std::ostream& operator <<(std::ostream& _os, const eproperty::Range& _obj) { + template std::ostream& operator <<(std::ostream& _os, const eproperty::Range& _obj) { _os << _obj.get(); return _os; } diff --git a/eproperty/Value.h b/eproperty/Value.h index 047a323..f1d7c37 100644 --- a/eproperty/Value.h +++ b/eproperty/Value.h @@ -12,10 +12,10 @@ namespace eproperty { - template class Value : public Property { + template class Value : public Property { private: - MY_TYPE m_value; //!< Current value. - MY_TYPE m_default; //!< Default value. + TYPE m_value; //!< Current value. + TYPE m_default; //!< Default value. public: /** * @brief Create a parameter with a specific type. @@ -28,7 +28,7 @@ namespace eproperty { */ Value(eproperty::Interface& _paramInterfaceLink, const std::string& _name, - const MY_TYPE& _defaultValue, + const TYPE& _defaultValue, const std::string& _description = "") : Property(_paramInterfaceLink, _name), m_value(_defaultValue), @@ -53,7 +53,7 @@ namespace eproperty { } // herited methode virtual std::string getType() const { - return typeid(MY_TYPE).name(); + return typeid(TYPE).name(); } // herited methode virtual std::string getString() const { @@ -88,54 +88,61 @@ namespace eproperty { * @note For performence, this function must be inline * @return the Reference value */ - inline MY_TYPE& get() { - return m_value; - }; - const inline MY_TYPE& get() const { + const inline TYPE& get() const { return m_value; }; /** * @brief Set a new value for this parameter * @param[in] newVal New value to set (set the nearest value if range is set) */ - void set(const MY_TYPE& _newVal) { + void set(const TYPE& _newVal) { if (_newVal != m_value) { m_value = _newVal; notifyChange(); } } + /** + * @brief Set the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @param[in] newVal New value to set + */ + inline void setDirect(const TYPE& _newVal) { + m_value = _newVal; + } + /** + * @brief Get the value of the current parameter (no check (for internal set with no check). + * @note For performence, this function must be inline + * @note Only use by the owner of the property (can not be check on compile time for now ...) + * TODO: Do it better ... compile check + * @return a reference on the value + */ + TYPE& getDirect() { + return m_value; + } private: /** * @brief Get the string of the specify value. * @return convetion of the velue in string. */ - std::string getValueSpecific(const MY_TYPE& _valueRequested) const { + std::string getValueSpecific(const TYPE& _valueRequested) const { return etk::to_string(_valueRequested); } public: - /** - * @brief assignement operator. - * @param[in] newVal The new value of the parameter. - */ - const Value& operator= (const MY_TYPE& _newVal) { - set(_newVal); - return *this; - }; - operator const MY_TYPE&() const { + operator const TYPE&() const { return m_value; } - MY_TYPE& operator *() const noexcept { + const TYPE& operator *() const noexcept { return m_value; } - const MY_TYPE* operator->() const noexcept { - return &m_value; - } - MY_TYPE* operator->() noexcept { + const TYPE* operator->() const noexcept { return &m_value; } + const Value& operator= (const TYPE& _newVal) = delete; }; - template std::ostream& operator <<(std::ostream& _os, const eproperty::Value& _obj) { + template std::ostream& operator <<(std::ostream& _os, const eproperty::Value& _obj) { _os << _obj.get(); return _os; }