[DEV] set maximum property in private implementation

This commit is contained in:
Edouard DUPIN 2016-03-22 22:18:16 +01:00
parent adee292ce2
commit 2960a7b970
11 changed files with 272 additions and 55 deletions

View File

@ -10,6 +10,9 @@
#include <eproperty/List.h>
#include <eproperty/Property.h>
#undef __class__
#define __class__ "Interface"
eproperty::Interface::Interface() {
}

View File

@ -11,8 +11,11 @@
#include <map>
#include <typeinfo>
#undef __class__
#define __class__ "List<T>"
namespace eproperty {
template<typename TYPE> class List : public PropertyType<TYPE> {
template<class TYPE> class List : public PropertyType<TYPE> {
private:
std::map<std::string, TYPE> 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<TYPE>::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<TYPE>::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<TYPE>::m_default = m_list.begin()->second;
}
if (firstValue == true) {
eproperty::PropertyType<TYPE>::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<std::string> getListValue() const override {
std::vector<std::string> 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

View File

@ -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<std::string> getListValue() const {
return std::vector<std::string>();
}
public:
template<class TYPE>
bool operator== (const TYPE& _obj) const = delete;

View File

@ -11,9 +11,11 @@
#include <eproperty/Property.h>
#include <eproperty/debug.h>
#undef __class__
#define __class__ "PropertyType<T>"
namespace eproperty {
template<typename TYPE> class PropertyType : public Property {
template<class TYPE> 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

View File

@ -11,8 +11,11 @@
#include <eproperty/Value.h>
#include <typeinfo>
#undef __class__
#define __class__ "Range<T>"
namespace eproperty {
template<typename TYPE> class Range : public Value<TYPE> {
template<class TYPE> class Range : public Value<TYPE> {
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<TYPE>::getType() + " default=" + eproperty::Value<TYPE>::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<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = _newVal;
eproperty::Value<TYPE>::notifyChange();
}
} else {
TYPE newVal = std::avg(m_min, _newVal, m_max);
if (newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = newVal;
eproperty::Value<TYPE>::notifyChange();
}
}
}
void setDirectCheck(const TYPE& _newVal) override {
if (m_min == m_max) {
if (_newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = _newVal;
}
} else {
TYPE newVal = std::avg(m_min, _newVal, m_max);
if (newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = newVal;
}
}
}
void set(const TYPE& _newVal) override;
void setDirectCheck(const TYPE& _newVal) override;
};
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Range<TYPE>& _obj) {
@ -97,3 +63,6 @@ namespace eproperty {
}
}
#undef __class__
#define __class__ nullptr

View File

@ -8,10 +8,16 @@
#pragma once
#include <eproperty/PropertyType.h>
#include <etk/types.h>
#include <etk/math/Vector2D.h>
#include <etk/math/Vector3D.h>
#include <etk/Color.h>
#undef __class__
#define __class__ "Value<T>"
namespace eproperty {
template<typename TYPE> class Value : public PropertyType<TYPE> {
template<class TYPE> class Value : public PropertyType<TYPE> {
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<TYPE>::m_value, _newVal);
// TODO : Do it better ...
eproperty::PropertyType<TYPE>::notifyChange();
}
std::string getValueSpecific(const TYPE& _valueRequested) const override;
void setString(const std::string& _newVal) override;
};
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Value<TYPE>& _obj) {
@ -52,3 +51,7 @@ namespace eproperty {
}
}
#undef __class__
#define __class__ nullptr

View File

@ -0,0 +1,46 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <eproperty/details/Range.hxx>
#include <etk/types.h>
#include <etk/math/Vector2D.h>
#include <etk/math/Vector3D.h>
#include <etk/Color.h>
#undef __class__
#define __class__ "Range<T>"
// void generic properties
template class eproperty::Range<int64_t>;
template class eproperty::Range<int32_t>;
template class eproperty::Range<int16_t>;
template class eproperty::Range<int8_t>;
template class eproperty::Range<uint64_t>;
template class eproperty::Range<uint32_t>;
template class eproperty::Range<uint16_t>;
template class eproperty::Range<uint8_t>;
template class eproperty::Range<float>;
template class eproperty::Range<double>;
// etk generic vetor 2D
template class eproperty::Range<vec2>;
template class eproperty::Range<bvec2>;
template class eproperty::Range<ivec2>;
template class eproperty::Range<uivec2>;
// etk generic vetor 3D
template class eproperty::Range<vec3>;
template class eproperty::Range<bvec3>;
template class eproperty::Range<ivec3>;
template class eproperty::Range<uivec3>;
// etk generic color
/*
template class eproperty::Range<etk::Color<unsigned char,4>>;
template class eproperty::Range<etk::Color<unsigned char,3>>;
template class eproperty::Range<etk::Color<float,4>>;
template class eproperty::Range<etk::Color<float,3>>;
*/

View File

@ -0,0 +1,64 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <eproperty/Range.h>
#undef __class__
#define __class__ "Range<T>"
template<class TYPE>
std::string eproperty::Range<TYPE>::getPropertyType() const {
return "eproperty::Range";
}
template<class TYPE>
void eproperty::Range<TYPE>::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<class TYPE>
std::string eproperty::Range<TYPE>::getInfo() const {
return eproperty::Value<TYPE>::getType() + " default=" + eproperty::Value<TYPE>::getDefault();
}
template<class TYPE>
void eproperty::Range<TYPE>::set(const TYPE& _newVal) {
if (m_min == m_max) {
if (_newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = _newVal;
eproperty::Value<TYPE>::notifyChange();
}
} else {
TYPE newVal = std::avg(m_min, _newVal, m_max);
if (newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = newVal;
eproperty::Value<TYPE>::notifyChange();
}
}
}
template<class TYPE>
void eproperty::Range<TYPE>::setDirectCheck(const TYPE& _newVal) {
if (m_min == m_max) {
if (_newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = _newVal;
}
} else {
TYPE newVal = std::avg(m_min, _newVal, m_max);
if (newVal != eproperty::Value<TYPE>::m_value) {
eproperty::Value<TYPE>::m_value = newVal;
}
}
}

View File

@ -0,0 +1,50 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <eproperty/details/Value.hxx>
#include <etk/types.h>
#include <etk/math/Vector2D.h>
#include <etk/math/Vector3D.h>
#include <etk/Color.h>
#undef __class__
#define __class__ "Value<T>"
// void generic properties
template class eproperty::Value<bool>;
template class eproperty::Value<std::string>;
#if __CPP_VERSION__ >= 2011
template class eproperty::Value<std::u32string>;
#endif
template class eproperty::Value<int64_t>;
template class eproperty::Value<int32_t>;
template class eproperty::Value<int16_t>;
template class eproperty::Value<int8_t>;
template class eproperty::Value<uint64_t>;
template class eproperty::Value<uint32_t>;
template class eproperty::Value<uint16_t>;
template class eproperty::Value<uint8_t>;
template class eproperty::Value<float>;
template class eproperty::Value<double>;
// etk generic vetor 2D
template class eproperty::Value<vec2>;
template class eproperty::Value<bvec2>;
template class eproperty::Value<ivec2>;
template class eproperty::Value<uivec2>;
// etk generic vetor 3D
template class eproperty::Value<vec3>;
template class eproperty::Value<bvec3>;
template class eproperty::Value<ivec3>;
template class eproperty::Value<uivec3>;
// etk generic color
template class eproperty::Value<etk::Color<unsigned char,4>>;
template class eproperty::Value<etk::Color<unsigned char,3>>;
template class eproperty::Value<etk::Color<float,4>>;
template class eproperty::Value<etk::Color<float,3>>;

View File

@ -0,0 +1,31 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <eproperty/Value.h>
#undef __class__
#define __class__ "Value<T>"
template<class TYPE>
std::string eproperty::Value<TYPE>::getValueSpecific(const TYPE& _valueRequested) const {
return etk::to_string(_valueRequested);
}
template<class TYPE>
void eproperty::Value<TYPE>::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<TYPE>::m_value, _newVal);
// TODO : Do it better ...
eproperty::PropertyType<TYPE>::notifyChange();
}
#undef __class__
#define __class__ nullptr

View File

@ -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__))