diff --git a/eproperty/Interface.cpp b/eproperty/Interface.cpp index 3dee7a7..93a9e44 100644 --- a/eproperty/Interface.cpp +++ b/eproperty/Interface.cpp @@ -10,6 +10,9 @@ #include #include +#undef __class__ +#define __class__ "Interface" + eproperty::Interface::Interface() { } diff --git a/eproperty/List.h b/eproperty/List.h index 4e91532..93349fb 100644 --- a/eproperty/List.h +++ b/eproperty/List.h @@ -11,8 +11,11 @@ #include #include +#undef __class__ +#define __class__ "List" + namespace eproperty { - template class List : public PropertyType { + template class List : public PropertyType { private: std::map m_list; //!< pointer on the list of all elements. public: @@ -47,10 +50,30 @@ namespace eproperty { } void remove(const std::string& _name) { auto it = m_list.find(_name); + bool firstValue = false; + bool firstDefault = false; if (it != m_list.end()) { + if (it->second == eproperty::PropertyType::m_value) { + EPROPERTY_ERROR("property value='" << it->first << "' has been removed and this value was set ... change it before removing value to remove this error"); + firstValue = true; + } + if (it->second == eproperty::PropertyType::m_default) { + EPROPERTY_ERROR("property default='" << it->first << "' has been removed and this value was set ... change it before removing value to remove this error"); + firstDefault = true; + } m_list.erase(it); return; } + if (m_list.size() == 0) { + EPROPERTY_INFO("property All value removed ==> can not change default and value"); + return; + } + if (firstDefault == true) { + eproperty::PropertyType::m_default = m_list.begin()->second; + } + if (firstValue == true) { + eproperty::PropertyType::m_value = m_list.begin()->second; + } } void rename(const std::string& _nameOld, const std::string& _nameNew) { //get old value @@ -89,6 +112,13 @@ namespace eproperty { } return list + "]"; } + std::vector getListValue() const override { + std::vector out; + for (auto &it : m_list) { + out.push_back(it.first); + } + return out; + } /** * @brief Set the value of the current parameter. * @param[in] _newVal New value of the parameter. (not set if out of range) @@ -139,3 +169,6 @@ namespace eproperty { } } + +#undef __class__ +#define __class__ nullptr diff --git a/eproperty/Property.h b/eproperty/Property.h index e775923..ed5aa95 100644 --- a/eproperty/Property.h +++ b/eproperty/Property.h @@ -75,6 +75,13 @@ namespace eproperty { * @brief Reset the value to the default value. */ virtual void setDefault() = 0; + /** + * @brief Specific for eproperty::List to get all the possible values + * @return Descriptive information of the Property (for remote UI). + */ + virtual std::vector getListValue() const { + return std::vector(); + } public: template bool operator== (const TYPE& _obj) const = delete; diff --git a/eproperty/PropertyType.h b/eproperty/PropertyType.h index 1554536..7b3da0f 100644 --- a/eproperty/PropertyType.h +++ b/eproperty/PropertyType.h @@ -11,9 +11,11 @@ #include #include +#undef __class__ +#define __class__ "PropertyType" namespace eproperty { - template class PropertyType : public Property { + template class PropertyType : public Property { protected: TYPE m_value; //!< Current value. TYPE m_default; //!< Default value. @@ -64,6 +66,9 @@ namespace eproperty { void setDefault() override { set(m_default); } + virtual void changeDefault(const TYPE& _newDefault) { + m_default = _newDefault; + } public: /** * @brief Get the value of the current parameter. @@ -126,3 +131,5 @@ namespace eproperty { } } +#undef __class__ +#define __class__ nullptr diff --git a/eproperty/Range.h b/eproperty/Range.h index 1f86a7e..9dbfc17 100644 --- a/eproperty/Range.h +++ b/eproperty/Range.h @@ -11,8 +11,11 @@ #include #include +#undef __class__ +#define __class__ "Range" + namespace eproperty { - template class Range : public Value { + template class Range : public Value { private: TYPE m_min; //!< Minimum value. TYPE m_max; //!< Maximum value. @@ -46,49 +49,12 @@ namespace eproperty { * @brief Destructor. */ virtual ~Range() = default; - std::string getPropertyType() const override { - return "eproperty::Range"; - } - void setString(const std::string& _newVal) override { - 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); - } - std::string getInfo() const override { - return eproperty::Value::getType() + " default=" + eproperty::Value::getDefault(); - } + std::string getPropertyType() const override; + void setString(const std::string& _newVal) override; + std::string getInfo() const override; public: - /** - * @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 TYPE& _newVal) override { - if (m_min == m_max) { - if (_newVal != eproperty::Value::m_value) { - eproperty::Value::m_value = _newVal; - eproperty::Value::notifyChange(); - } - } else { - TYPE newVal = std::avg(m_min, _newVal, m_max); - if (newVal != eproperty::Value::m_value) { - eproperty::Value::m_value = newVal; - eproperty::Value::notifyChange(); - } - } - } - void setDirectCheck(const TYPE& _newVal) override { - if (m_min == m_max) { - if (_newVal != eproperty::Value::m_value) { - eproperty::Value::m_value = _newVal; - } - } else { - TYPE newVal = std::avg(m_min, _newVal, m_max); - if (newVal != eproperty::Value::m_value) { - eproperty::Value::m_value = newVal; - } - } - } + void set(const TYPE& _newVal) override; + void setDirectCheck(const TYPE& _newVal) override; }; template std::ostream& operator <<(std::ostream& _os, const eproperty::Range& _obj) { @@ -97,3 +63,6 @@ namespace eproperty { } } + +#undef __class__ +#define __class__ nullptr diff --git a/eproperty/Value.h b/eproperty/Value.h index 69faf92..4537b9b 100644 --- a/eproperty/Value.h +++ b/eproperty/Value.h @@ -8,10 +8,16 @@ #pragma once #include +#include +#include +#include +#include +#undef __class__ +#define __class__ "Value" namespace eproperty { - template class Value : public PropertyType { + template class Value : public PropertyType { public: /** * @brief Create a parameter with a specific type. @@ -35,15 +41,8 @@ namespace eproperty { * @brief Get the string of the specify value. * @return convetion of the velue in string. */ - std::string getValueSpecific(const TYPE& _valueRequested) const override { - return etk::to_string(_valueRequested); - } - void setString(const std::string& _newVal) override { - // when you want to set an element in parameter you will implement the function template std::from_string - etk::from_string(eproperty::PropertyType::m_value, _newVal); - // TODO : Do it better ... - eproperty::PropertyType::notifyChange(); - } + std::string getValueSpecific(const TYPE& _valueRequested) const override; + void setString(const std::string& _newVal) override; }; template std::ostream& operator <<(std::ostream& _os, const eproperty::Value& _obj) { @@ -52,3 +51,7 @@ namespace eproperty { } } +#undef __class__ +#define __class__ nullptr + + diff --git a/eproperty/details/Range.cpp b/eproperty/details/Range.cpp new file mode 100644 index 0000000..995d958 --- /dev/null +++ b/eproperty/details/Range.cpp @@ -0,0 +1,46 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ +#include +#include +#include +#include +#include + +#undef __class__ +#define __class__ "Range" +// void generic properties +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; + +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; + +template class eproperty::Range; +template class eproperty::Range; + +// etk generic vetor 2D +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +// etk generic vetor 3D +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +template class eproperty::Range; +// etk generic color +/* +template class eproperty::Range>; +template class eproperty::Range>; +template class eproperty::Range>; +template class eproperty::Range>; +*/ diff --git a/eproperty/details/Range.hxx b/eproperty/details/Range.hxx new file mode 100644 index 0000000..3101088 --- /dev/null +++ b/eproperty/details/Range.hxx @@ -0,0 +1,64 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include + +#undef __class__ +#define __class__ "Range" + +template +std::string eproperty::Range::getPropertyType() const { + return "eproperty::Range"; +} + +template +void eproperty::Range::setString(const std::string& _newVal) { + 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); +} + +template +std::string eproperty::Range::getInfo() const { + return eproperty::Value::getType() + " default=" + eproperty::Value::getDefault(); +} + +template +void eproperty::Range::set(const TYPE& _newVal) { + if (m_min == m_max) { + if (_newVal != eproperty::Value::m_value) { + eproperty::Value::m_value = _newVal; + eproperty::Value::notifyChange(); + } + } else { + TYPE newVal = std::avg(m_min, _newVal, m_max); + if (newVal != eproperty::Value::m_value) { + eproperty::Value::m_value = newVal; + eproperty::Value::notifyChange(); + } + } +} + +template +void eproperty::Range::setDirectCheck(const TYPE& _newVal) { + if (m_min == m_max) { + if (_newVal != eproperty::Value::m_value) { + eproperty::Value::m_value = _newVal; + } + } else { + TYPE newVal = std::avg(m_min, _newVal, m_max); + if (newVal != eproperty::Value::m_value) { + eproperty::Value::m_value = newVal; + } + } +} + + + diff --git a/eproperty/details/Value.cpp b/eproperty/details/Value.cpp new file mode 100644 index 0000000..891fb64 --- /dev/null +++ b/eproperty/details/Value.cpp @@ -0,0 +1,50 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ +#include + +#include +#include +#include +#include + +#undef __class__ +#define __class__ "Value" +// void generic properties +template class eproperty::Value; +template class eproperty::Value; +#if __CPP_VERSION__ >= 2011 + template class eproperty::Value; +#endif +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; + +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; + +template class eproperty::Value; +template class eproperty::Value; + +// etk generic vetor 2D +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +// etk generic vetor 3D +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +template class eproperty::Value; +// etk generic color +template class eproperty::Value>; +template class eproperty::Value>; +template class eproperty::Value>; +template class eproperty::Value>; diff --git a/eproperty/details/Value.hxx b/eproperty/details/Value.hxx new file mode 100644 index 0000000..46ecdc8 --- /dev/null +++ b/eproperty/details/Value.hxx @@ -0,0 +1,31 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2016, Edouard DUPIN, all right reserved + * + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include + +#undef __class__ +#define __class__ "Value" + +template +std::string eproperty::Value::getValueSpecific(const TYPE& _valueRequested) const { + return etk::to_string(_valueRequested); +} + +template +void eproperty::Value::setString(const std::string& _newVal) { + // when you want to set an element in parameter you will implement the function template std::from_string + etk::from_string(eproperty::PropertyType::m_value, _newVal); + // TODO : Do it better ... + eproperty::PropertyType::notifyChange(); +} + + +#undef __class__ +#define __class__ nullptr + diff --git a/lutin_eproperty.py b/lutin_eproperty.py index 884dcb7..9bdb27f 100644 --- a/lutin_eproperty.py +++ b/lutin_eproperty.py @@ -33,6 +33,8 @@ def create(target, module_name): 'eproperty/debug.cpp', 'eproperty/Property.cpp', 'eproperty/Interface.cpp', + 'eproperty/details/Range.cpp', + 'eproperty/details/Value.cpp', ]) my_module.add_header_file([ 'eproperty/debug.h', @@ -42,6 +44,8 @@ def create(target, module_name): 'eproperty/PropertyType.h', 'eproperty/Range.h', 'eproperty/List.h', + 'eproperty/details/Range.hxx', + 'eproperty/details/Value.hxx', ]) my_module.add_module_depend(['etk']) my_module.add_path(tools.get_current_path(__file__))