[DEV] good enouth

This commit is contained in:
Edouard DUPIN 2016-03-07 22:06:46 +01:00
parent 53bb23e1c2
commit 57320dad30
11 changed files with 63 additions and 101 deletions

View File

@ -21,9 +21,15 @@ eproperty::Interface::~Interface() {
// note this pointer is not allocated and not free at the end of the class
void eproperty::Interface::propertyAdd(eproperty::Property* _pointerOnProperty) {
if (_pointerOnProperty == nullptr) {
EPROPERTY_ERROR("Try to link a nullptr propertys");
EPROPERTY_ERROR("Try to link a nullptr properties");
return;
}
for (auto &it : m_list) {
if( it != nullptr
&& it->getName() == _pointerOnProperty->getName()) {
EPROPERTY_CRITICAL("2 property can not have the same name ... ==> generate runtime error");
}
}
m_list.push_back(_pointerOnProperty);
}
@ -105,3 +111,11 @@ eproperty::Property* eproperty::Interface::getPropertyRaw(const size_t& _id) con
return m_list[_id];
}
eproperty::Property* eproperty::Interface::getPropertyRaw(const std::string _name) const {
for (auto &it : m_list) {
if(it->getName() == _name) {
return it;
}
}
return nullptr;
}

View File

@ -76,6 +76,7 @@ namespace eproperty {
* @return pointer on the property.
*/
eproperty::Property* getPropertyRaw(const size_t& _id) const;
eproperty::Property* getPropertyRaw(const std::string _name) const;
};
}

View File

@ -45,6 +45,26 @@ namespace eproperty {
}
m_list.insert(std::make_pair(_name, _value));
}
void remove(const std::string& _name) {
auto it = m_list.find(_name);
if (it != m_list.end()) {
m_list.erase(it);
return;
}
}
void rename(const std::string& _nameOld, const std::string& _nameNew) {
//get old value
TYPE value;
auto it = m_list.find(_nameOld);
if (it != m_list.end()) {
value = it->second;
} else {
EPROPERTY_ERROR("paramList rename can not be done '" << _nameOld << "' in '" << _nameNew << "' parameter name does not exist");
return;
}
remove(_nameOld);
add(value, _nameNew);
}
std::string getPropertyType() const override {
return "eproperty::List";
}
@ -86,6 +106,18 @@ namespace eproperty {
}
EPROPERTY_WARNING("paramList value=??? is not un the list ... ==> no change");
}
void setDirectCheck(const TYPE& _newVal) override {
if (_newVal == eproperty::PropertyType<TYPE>::m_value) {
return;
}
for (auto &it : m_list) {
if (it.second == _newVal) {
eproperty::PropertyType<TYPE>::m_value = it.second;
return;
}
}
EPROPERTY_WARNING("paramList value=??? is not un the list ... ==> no change");
}
private:
/**
* @brief Get the element description from real Value.

View File

@ -8,7 +8,6 @@
#pragma once
#include <eproperty/Interface.h>
#include <eproperty/VariantBase.h>
#include <string>
#include <typeinfo>
#include <functional>
@ -76,7 +75,6 @@ namespace eproperty {
* @brief Reset the value to the default value.
*/
virtual void setDefault() = 0;
virtual void setVariant(eproperty::VariantBase* _variantValue) = 0;
public:
template<class TYPE>
bool operator== (const TYPE& _obj) const = delete;

View File

@ -9,29 +9,10 @@
#include <eproperty/Interface.h>
#include <eproperty/Property.h>
#include <eproperty/VariantBase.h>
#include <eproperty/debug.h>
namespace eproperty {
template<typename TYPE> class VariantSpecify : public eproperty::VariantBase {
private:
TYPE m_value;
public:
VariantSpecify() :
eproperty::VariantBase(uint64_t(typeid(TYPE))),
m_value() {
}
VariantSpecify(TYPE&& _value) :
eproperty::VariantBase(uint64_t(typeid(TYPE))),
m_value(_value) {
}
const TYPE& get() {
return m_value;
}
};
template<typename TYPE> class PropertyType : public Property {
protected:
TYPE m_value; //!< Current value.
@ -102,15 +83,6 @@ namespace eproperty {
notifyChange();
}
}
void setVariant(eproperty::VariantBase* _variantValue) override {
eproperty::VariantSpecify<TYPE>* value = dynamic_cast<eproperty::VariantSpecify<TYPE>*>(_variantValue);
if (value == nullptr) {
EPROPERTY_ERROR("Can not set property : '" << getName() << "' wrong variant type ...");
return;
}
// TODO : Check range ...
setDirect(value->get());
}
/**
* @brief Set the value of the current parameter (no check (for internal set with no check).
* @note For performence, this function must be inline
@ -121,6 +93,9 @@ namespace eproperty {
inline void setDirect(const TYPE& _newVal) {
m_value = _newVal;
}
virtual void setDirectCheck(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

View File

@ -77,6 +77,18 @@ namespace eproperty {
}
}
}
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;
}
}
}
};
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Range<TYPE>& _obj) {

View File

@ -1,14 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <eproperty/debug.h>
#include <eproperty/Variant.h>
eproperty::Variant::~Variant() {
}

View File

@ -1,28 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <eproperty/Interface.h>
#include <eproperty/Property.h>
#include <eproperty/VariantBase.h>
#include <eproperty/Value.h>
namespace eproperty {
class Variant {
private:
std::unique_ptr<VariantBase> m_value;
public:
template<class TYPE>
Variant(TYPE&& _value):
m_value() {
eproperty::VariantSpecify<TYPE>* _val = new eproperty::VariantSpecify<TYPE>();
}
~Variant();
};
}

View File

@ -1,25 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#pragma once
#include <eproperty/Interface.h>
#include <eproperty/Property.h>
namespace eproperty {
class VariantBase {
protected:
uint64_t m_type;
public:
VariantBase(const uint64_t& _type) :
m_type(_type) {
}
virtual ~VariantBase() = default;
};
}

View File

@ -33,7 +33,6 @@ def create(target, module_name):
'eproperty/debug.cpp',
'eproperty/Property.cpp',
'eproperty/Interface.cpp',
'eproperty/Variant.cpp',
])
my_module.add_header_file([
'eproperty/debug.h',
@ -43,8 +42,6 @@ def create(target, module_name):
'eproperty/PropertyType.h',
'eproperty/Range.h',
'eproperty/List.h',
'eproperty/Variant.h',
'eproperty/VariantBase.h'
])
my_module.add_module_depend(['etk'])
my_module.add_path(tools.get_current_path(__file__))