[DEV] create first version of the lib (extract from ewol)
This commit is contained in:
parent
92d35be9ae
commit
25ae84bf1e
107
eproperty/Interface.cpp
Normal file
107
eproperty/Interface.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <eproperty/debug.h>
|
||||
#include <eproperty/List.h>
|
||||
#include <eproperty/Property.h>
|
||||
|
||||
eproperty::Interface::Interface() {
|
||||
|
||||
}
|
||||
|
||||
eproperty::Interface::~Interface() {
|
||||
propertyClean();
|
||||
}
|
||||
|
||||
// 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");
|
||||
return;
|
||||
}
|
||||
m_list.push_back(_pointerOnProperty);
|
||||
}
|
||||
|
||||
void eproperty::Interface::propertyClean() {
|
||||
// remove all pointer on these propertys
|
||||
m_list.clear();
|
||||
}
|
||||
|
||||
// Note no lock is needed at this level, because the lock is done is the upper elements ...
|
||||
// the property set might be done with a pool of property, allone, the overhed is bigger ...
|
||||
bool eproperty::Interface::propertySet(const std::string& _property, const std::string& _value) {
|
||||
for (auto &it : m_list) {
|
||||
if( it != nullptr
|
||||
&& it->getName() == _property) {
|
||||
it->setString(_value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// can not find the propertys :
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string eproperty::Interface::propertyGet(const std::string& _property) const {
|
||||
for (auto &it : m_list) {
|
||||
if( it != nullptr
|
||||
&& it->getName() == _property) {
|
||||
return it->getString();
|
||||
}
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
void eproperty::Interface::propertyDisplay(bool _changeOnly) const {
|
||||
EPROPERTY_INFO(" Object propertys:");
|
||||
for (auto &it : m_list) {
|
||||
if(it != nullptr) {
|
||||
std::string paramName = it->getName();
|
||||
std::string paramVal = it->getString();
|
||||
std::string paramInfo = it->getInfo();
|
||||
if ( _changeOnly == false
|
||||
|| it->isDefault() == false) {
|
||||
EPROPERTY_INFO(" | param='" << paramName << "' value=" << paramVal << " (" << paramInfo << ")");
|
||||
}
|
||||
} else {
|
||||
EPROPERTY_INFO(" | param=nullptr");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void eproperty::Interface::onPropertyChangeValue(const eproperty::Ref& _paramPointer) {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> eproperty::Interface::propertyGetAll(bool _notIfDefault) const {
|
||||
std::map<std::string, std::string> out;
|
||||
for (auto &it : m_list) {
|
||||
if(it != nullptr) {
|
||||
std::string paramName = it->getName();
|
||||
std::string paramVal = it->getString();
|
||||
if ( _notIfDefault == false
|
||||
|| it->isDefault() == false) {
|
||||
out.insert(std::make_pair(paramName, paramVal));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
size_t eproperty::Interface::getPropertyCount() const {
|
||||
return m_list.size();
|
||||
}
|
||||
|
||||
eproperty::Property* eproperty::Interface::getPropertyRaw(const size_t& _id) const {
|
||||
if (_id >= m_list.size()) {
|
||||
EPROPERTY_ERROR("Wrong ID for property list. " << _id << " >= " << m_list.size());
|
||||
return nullptr;
|
||||
}
|
||||
return m_list[_id];
|
||||
}
|
||||
|
83
eproperty/Interface.h
Normal file
83
eproperty/Interface.h
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace eproperty {
|
||||
class Property;
|
||||
class Ref;
|
||||
class Interface {
|
||||
friend class eproperty::Property; // to register property in the list.
|
||||
private:
|
||||
std::vector<eproperty::Property*> m_list; //!< list of availlable Propertys (no need to free)
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor.
|
||||
*/
|
||||
Interface();
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~Interface();
|
||||
/**
|
||||
* @brief Register a property class pointer in the List of propertys
|
||||
* @note This class does not destroy the property pointer!!!
|
||||
* @param[in] pointerOnProperty Pointer on the property that might be added.
|
||||
*/
|
||||
void propertyAdd(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.
|
||||
*/
|
||||
void propertyClean();
|
||||
/**
|
||||
* @brief Set a specific value to the property reference name.
|
||||
* @param[in] property The property string name.
|
||||
* @param[in] value The new value of the property (string).
|
||||
* @return true Property update.
|
||||
* @return false Property not update.
|
||||
*/
|
||||
bool propertySet(const std::string& _property, const std::string& _value);
|
||||
/**
|
||||
* @brief Get a specific value of the property reference name.
|
||||
* @param[in] property The property string name.
|
||||
* @return The value of the property (string).
|
||||
*/
|
||||
std::string propertyGet(const std::string& _property) const;
|
||||
/**
|
||||
* @brief Display all the property value with there name.
|
||||
* @param[in] changeOnly check at true if the user want to display only property that are not at default value.
|
||||
*/
|
||||
void propertyDisplay(bool _changeOnly = false) const;
|
||||
/**
|
||||
* @brief Called when a property change value.
|
||||
* @param[in] _paramPointer Pointer on the property (to know which property have change);
|
||||
*/
|
||||
virtual void onPropertyChangeValue(const eproperty::Ref& _paramPointer);
|
||||
/**
|
||||
* @brief Get All the property configuration:
|
||||
* @return map on the propertys
|
||||
*/
|
||||
std::map<std::string, std::string> propertyGetAll(bool _notIfDefault=true) const;
|
||||
public:
|
||||
/**
|
||||
* @brief Get count of propertys.
|
||||
* @return The number of the property.
|
||||
*/
|
||||
size_t getPropertyCount() const;
|
||||
/**
|
||||
* @brief Get name of a propertys.
|
||||
* @return _id Id of the property.
|
||||
* @return pointer on the property.
|
||||
*/
|
||||
eproperty::Property* getPropertyRaw(const size_t& _id) const;
|
||||
};
|
||||
}
|
||||
|
168
eproperty/List.h
Normal file
168
eproperty/List.h
Normal file
@ -0,0 +1,168 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <eproperty/debug.h>
|
||||
#include <eproperty/Interface.h>
|
||||
#include <eproperty/Property.h>
|
||||
#include <map>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace eproperty {
|
||||
template<typename MY_TYPE, bool isEventReceiving=false> class List : public Property {
|
||||
private:
|
||||
MY_TYPE m_value; //!< Element value ==> can be directly used.
|
||||
MY_TYPE m_default; //!< Default value.
|
||||
std::map<std::string, MY_TYPE> m_list; //!< pointer on the list of all elements.
|
||||
public:
|
||||
/**
|
||||
* @brief Create a parameter with List of element parameter.
|
||||
* @param[in] _objectLink reference on the parameter lister.
|
||||
* @param[in] _name Static name of the parameter.
|
||||
* @param[in] _description description of the parameter.
|
||||
*/
|
||||
List(eproperty::Interface& _paramInterfaceLink,
|
||||
const std::string& _name,
|
||||
const MY_TYPE& _defaultValue,
|
||||
const std::string& _description="") :
|
||||
Property(_paramInterfaceLink, _name),
|
||||
m_value(_defaultValue),
|
||||
m_default(_defaultValue) {
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~List() = default;
|
||||
void add(const MY_TYPE& _value, const std::string& _name, const std::string& _description = "") {
|
||||
auto it = m_list.find(_name);
|
||||
if (it != m_list.end()) {
|
||||
it->second = _value;
|
||||
return;
|
||||
}
|
||||
m_list.insert(std::make_pair(_name, _value));
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getPropertyType() const {
|
||||
return "eproperty::List";
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getType() const {
|
||||
return typeid(MY_TYPE).name();
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getString() const {
|
||||
return getElement(m_value);
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getDefault() const {
|
||||
return getElement(m_default);
|
||||
}
|
||||
// herited methode
|
||||
virtual void setString(const std::string& _newVal) {
|
||||
auto it = m_list.find(_newVal);
|
||||
if (it != m_list.end()) {
|
||||
if (it->second != m_value) {
|
||||
m_value = it->second;
|
||||
notifyChange();
|
||||
}
|
||||
return;
|
||||
}
|
||||
EPROPERTY_WARNING("paramList value='" << _newVal << "' is not un the list ... ==> no change");
|
||||
for (auto &it : m_list) {
|
||||
EPROPERTY_VERBOSE(" element : " << it.first);
|
||||
}
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getInfo() const {
|
||||
std::string list = "List default=" + getElement(m_default) + " in : [";
|
||||
for (auto &it : m_list) {
|
||||
list += it.first + "/";
|
||||
}
|
||||
return list + "]";
|
||||
}
|
||||
// herited methode
|
||||
virtual bool isDefault() const {
|
||||
return m_value == m_default;
|
||||
}
|
||||
// herited methode
|
||||
virtual void setDefault() {
|
||||
set(m_default);
|
||||
}
|
||||
void setDefaultValue(const MY_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 {
|
||||
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) {
|
||||
if (_newVal == m_value) {
|
||||
return;
|
||||
}
|
||||
for (auto &it : m_list) {
|
||||
if (it.second == _newVal) {
|
||||
m_value = it.second;
|
||||
notifyChange();
|
||||
return;
|
||||
}
|
||||
}
|
||||
EPROPERTY_WARNING("paramList value=??? is not un the list ... ==> no change");
|
||||
}
|
||||
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 {
|
||||
for (auto &it : m_list) {
|
||||
if (it.second == _intValue) {
|
||||
return it.first;
|
||||
}
|
||||
}
|
||||
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 {
|
||||
return m_value;
|
||||
}
|
||||
MY_TYPE& operator *() const noexcept {
|
||||
return m_value;
|
||||
}
|
||||
const MY_TYPE* operator->() const noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
MY_TYPE* operator->() noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
};
|
||||
template<typename MY_TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::List<MY_TYPE>& _obj) {
|
||||
_os << _obj.get();
|
||||
return _os;
|
||||
}
|
||||
}
|
||||
|
32
eproperty/Property.cpp
Normal file
32
eproperty/Property.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <eproperty/debug.h>
|
||||
#include <eproperty/Interface.h>
|
||||
#include <eproperty/Property.h>
|
||||
|
||||
|
||||
eproperty::Property::Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name) :
|
||||
m_interfaceLink(_paramInterfaceLink),
|
||||
m_name(_name) {
|
||||
// add a reference on the current Property ...
|
||||
m_interfaceLink.propertyAdd(this);
|
||||
}
|
||||
|
||||
void eproperty::Property::notifyChange() const {
|
||||
m_interfaceLink.onPropertyChangeValue(eproperty::Ref(this));
|
||||
}
|
||||
|
||||
bool eproperty::operator==(const eproperty::Ref& _obj, const eproperty::Property& _obj2) noexcept {
|
||||
return &_obj2 == _obj.m_ref;
|
||||
}
|
||||
|
||||
bool eproperty::operator==(const eproperty::Property& _obj2, const eproperty::Ref& _obj) noexcept {
|
||||
return &_obj2 == _obj.m_ref;
|
||||
}
|
||||
|
85
eproperty/Property.h
Normal file
85
eproperty/Property.h
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <eproperty/Interface.h>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace eproperty {
|
||||
class Ref;
|
||||
class Property {
|
||||
private:
|
||||
eproperty::Interface& m_interfaceLink;
|
||||
std::string m_name;
|
||||
public:
|
||||
Property(eproperty::Interface& _paramInterfaceLink, const std::string& _name);
|
||||
virtual ~Property() = default;
|
||||
/**
|
||||
* @brief call main class that PropertyChange
|
||||
*/
|
||||
void notifyChange() const;
|
||||
/**
|
||||
* @brief Get the name of the Property.
|
||||
* @return The name of the Property
|
||||
*/
|
||||
virtual std::string getName() const {
|
||||
return m_name;
|
||||
};
|
||||
/**
|
||||
* @brief Description of the Propertys.
|
||||
* @return Descriptive information of the Property (for remote UI).
|
||||
*/
|
||||
virtual std::string getInfo() const = 0;
|
||||
/**
|
||||
* @brief Get the Property type of the class in string mode.
|
||||
* @return The string type of the Property.
|
||||
*/
|
||||
virtual std::string getPropertyType() const = 0;
|
||||
/**
|
||||
* @brief Get the type of the Property in string mode.
|
||||
* @return The string type of the Property.
|
||||
*/
|
||||
virtual std::string getType() const = 0;
|
||||
/**
|
||||
* @brief Get the string of the current value of the Property.
|
||||
* @return The string description of the value.
|
||||
*/
|
||||
virtual std::string getString() const = 0;
|
||||
/**
|
||||
* @brief Get the string of the default value of the Property.
|
||||
* @return the string decription of the default value.
|
||||
*/
|
||||
virtual std::string getDefault() const = 0;
|
||||
/**
|
||||
* @brief Set a new value of the Property (with string interface).
|
||||
* @param[in] _newVal New value of the Propertys.
|
||||
*/
|
||||
virtual void setString(const std::string& _newVal) = 0;
|
||||
/**
|
||||
* @brief Check if the value is the default
|
||||
* @return true : the vakue is the default one, false otherwise.
|
||||
*/
|
||||
virtual bool isDefault() const = 0;
|
||||
/**
|
||||
* @brief Reset the value to the default value.
|
||||
*/
|
||||
virtual void setDefault() = 0;
|
||||
};
|
||||
class Ref {
|
||||
public:
|
||||
const Property* m_ref;
|
||||
Ref(const Property* _ref) :
|
||||
m_ref(_ref) {
|
||||
// nothing to do ...
|
||||
}
|
||||
};
|
||||
bool operator==(const Ref& _obj, const Property& _obj2) noexcept;
|
||||
bool operator==(const Property& _obj2, const Ref& _obj) noexcept;
|
||||
}
|
||||
|
149
eproperty/Range.h
Normal file
149
eproperty/Range.h
Normal file
@ -0,0 +1,149 @@
|
||||
/**
|
||||
* @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 <typeinfo>
|
||||
|
||||
namespace eproperty {
|
||||
template<typename MY_TYPE, bool isEventReceiving=false> 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.
|
||||
public:
|
||||
/**
|
||||
* @brief Create a parameter with a specific type.
|
||||
* @param[in] _objectLink reference on the parameter lister.
|
||||
* @param[in] _name Static name of the parameter.
|
||||
* @param[in] _defaultValue Default value of the parameter.
|
||||
* @param[in] _min Minumum value.
|
||||
* @param[in] _max Maximum value.
|
||||
* @param[in] _description description of the parameter.
|
||||
*/
|
||||
Range(eproperty::Interface& _paramInterfaceLink,
|
||||
const std::string& _name,
|
||||
const MY_TYPE& _defaultValue,
|
||||
const MY_TYPE& _min,
|
||||
const MY_TYPE& _max,
|
||||
const std::string& _description = "") :
|
||||
Property(_paramInterfaceLink, _name),
|
||||
m_value(_defaultValue),
|
||||
m_min(_min),
|
||||
m_max(_max),
|
||||
m_default(_defaultValue) {
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~Range() = default;
|
||||
// herited methode
|
||||
virtual std::string getPropertyType() const {
|
||||
return "eproperty::Range";
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getType() const {
|
||||
return typeid(MY_TYPE).name();
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getString() const {
|
||||
return getValueSpecific(m_value);
|
||||
};
|
||||
// herited methode
|
||||
virtual std::string getDefault() const {
|
||||
return getValueSpecific(m_default);
|
||||
};
|
||||
// herited methode
|
||||
virtual void setString(const std::string& _newVal) {
|
||||
MY_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);
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getInfo() const {
|
||||
return getType() + " default=" + getDefault();
|
||||
}
|
||||
// herited methode
|
||||
virtual bool isDefault() const {
|
||||
return m_value == m_default;
|
||||
}
|
||||
// herited methode
|
||||
virtual void setDefault() {
|
||||
set(m_default);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Get the value of the current parameter.
|
||||
* @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 {
|
||||
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) {
|
||||
if (m_min == m_max) {
|
||||
if (_newVal != m_value) {
|
||||
m_value = _newVal;
|
||||
notifyChange();
|
||||
}
|
||||
} else {
|
||||
MY_TYPE newVal = std::avg(m_min, _newVal, m_max);
|
||||
if (newVal != m_value) {
|
||||
m_value = newVal;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* @brief Get the string of the specify value.
|
||||
* @return convetion of the velue in string.
|
||||
*/
|
||||
std::string getValueSpecific(const MY_TYPE& _valueRequested) const {
|
||||
return etk::to_string(_valueRequested);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief assignement operator.
|
||||
* @param[in] newVal The new value of the parameter.
|
||||
*/
|
||||
const Range<MY_TYPE>& operator= (const MY_TYPE& _newVal) {
|
||||
set(_newVal);
|
||||
return *this;
|
||||
};
|
||||
operator const MY_TYPE&() const {
|
||||
return m_value;
|
||||
}
|
||||
MY_TYPE& operator *() const noexcept {
|
||||
return m_value;
|
||||
}
|
||||
const MY_TYPE* operator->() const noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
MY_TYPE* operator->() noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename MY_TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Range<MY_TYPE>& _obj) {
|
||||
_os << _obj.get();
|
||||
return _os;
|
||||
}
|
||||
}
|
||||
|
143
eproperty/Value.h
Normal file
143
eproperty/Value.h
Normal file
@ -0,0 +1,143 @@
|
||||
/**
|
||||
* @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 {
|
||||
template<typename MY_TYPE, bool isEventReceiving=false> class Value : public Property {
|
||||
private:
|
||||
MY_TYPE m_value; //!< Current value.
|
||||
MY_TYPE m_default; //!< Default value.
|
||||
public:
|
||||
/**
|
||||
* @brief Create a parameter with a specific type.
|
||||
* @param[in] _objectLink reference on the parameter lister.
|
||||
* @param[in] _name Static name of the parameter.
|
||||
* @param[in] _defaultValue Default value of the parameter.
|
||||
* @param[in] _min Minumum value.
|
||||
* @param[in] _max Maximum value.
|
||||
* @param[in] _description description of the parameter.
|
||||
*/
|
||||
Value(eproperty::Interface& _paramInterfaceLink,
|
||||
const std::string& _name,
|
||||
const MY_TYPE& _defaultValue,
|
||||
const std::string& _description = "") :
|
||||
Property(_paramInterfaceLink, _name),
|
||||
m_value(_defaultValue),
|
||||
m_default(_defaultValue) {
|
||||
|
||||
};
|
||||
Value(eproperty::Interface& _paramListLink,
|
||||
const std::string& _name,
|
||||
const std::string& _description = "") :
|
||||
Property(_paramListLink, _name),
|
||||
m_value(),
|
||||
m_default() {
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
virtual ~Value() = default;
|
||||
// herited methode
|
||||
virtual std::string getPropertyType() const {
|
||||
return "eproperty::Value";
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getType() const {
|
||||
return typeid(MY_TYPE).name();
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getString() const {
|
||||
return getValueSpecific(m_value);
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getDefault() const {
|
||||
return getValueSpecific(m_default);
|
||||
}
|
||||
// herited methode
|
||||
virtual void 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(m_value, _newVal);
|
||||
// TODO : Do it better ...
|
||||
notifyChange();
|
||||
}
|
||||
// herited methode
|
||||
virtual std::string getInfo() const {
|
||||
return getType() + " default=" + getDefault();
|
||||
}
|
||||
// herited methode
|
||||
virtual bool isDefault() const {
|
||||
return m_value == m_default;
|
||||
}
|
||||
// herited methode
|
||||
virtual void setDefault() {
|
||||
set(m_default);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief Get the value of the current parameter.
|
||||
* @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 {
|
||||
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) {
|
||||
if (_newVal != m_value) {
|
||||
m_value = _newVal;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* @brief Get the string of the specify value.
|
||||
* @return convetion of the velue in string.
|
||||
*/
|
||||
std::string getValueSpecific(const MY_TYPE& _valueRequested) const {
|
||||
return etk::to_string(_valueRequested);
|
||||
}
|
||||
public:
|
||||
/**
|
||||
* @brief assignement operator.
|
||||
* @param[in] newVal The new value of the parameter.
|
||||
*/
|
||||
const Value<MY_TYPE>& operator= (const MY_TYPE& _newVal) {
|
||||
set(_newVal);
|
||||
return *this;
|
||||
};
|
||||
operator const MY_TYPE&() const {
|
||||
return m_value;
|
||||
}
|
||||
MY_TYPE& operator *() const noexcept {
|
||||
return m_value;
|
||||
}
|
||||
const MY_TYPE* operator->() const noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
MY_TYPE* operator->() noexcept {
|
||||
return &m_value;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename MY_TYPE, bool isEventReceiving=false> std::ostream& operator <<(std::ostream& _os, const eproperty::Value<MY_TYPE, isEventReceiving>& _obj) {
|
||||
_os << _obj.get();
|
||||
return _os;
|
||||
}
|
||||
}
|
||||
|
14
eproperty/debug.cpp
Normal file
14
eproperty/debug.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <eproperty/debug.h>
|
||||
|
||||
int32_t eproperty::getLogId() {
|
||||
static int32_t g_val = etk::log::registerInstance("eproperty");
|
||||
return g_val;
|
||||
}
|
40
eproperty/debug.h
Normal file
40
eproperty/debug.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2016, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/log.h>
|
||||
|
||||
namespace eproperty {
|
||||
int32_t getLogId();
|
||||
};
|
||||
#define EPROPERTY_BASE(info,data) TK_LOG_BASE(eproperty::getLogId(),info,data)
|
||||
|
||||
#define EPROPERTY_PRINT(data) EPROPERTY_BASE(-1, data)
|
||||
#define EPROPERTY_CRITICAL(data) EPROPERTY_BASE(1, data)
|
||||
#define EPROPERTY_ERROR(data) EPROPERTY_BASE(2, data)
|
||||
#define EPROPERTY_WARNING(data) EPROPERTY_BASE(3, data)
|
||||
#ifdef DEBUG
|
||||
#define EPROPERTY_INFO(data) EPROPERTY_BASE(4, data)
|
||||
#define EPROPERTY_DEBUG(data) EPROPERTY_BASE(5, data)
|
||||
#define EPROPERTY_VERBOSE(data) EPROPERTY_BASE(6, data)
|
||||
#define EPROPERTY_TODO(data) EPROPERTY_BASE(4, "TODO : " << data)
|
||||
#else
|
||||
#define EPROPERTY_INFO(data) do { } while(false)
|
||||
#define EPROPERTY_DEBUG(data) do { } while(false)
|
||||
#define EPROPERTY_VERBOSE(data) do { } while(false)
|
||||
#define EPROPERTY_TODO(data) do { } while(false)
|
||||
#endif
|
||||
|
||||
#define EPROPERTY_ASSERT(cond,data) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
EPROPERTY_CRITICAL(data); \
|
||||
assert(!#cond); \
|
||||
} \
|
||||
} while (0)
|
||||
|
51
lutin_eproperty.py
Normal file
51
lutin_eproperty.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
import lutin.module as module
|
||||
import lutin.tools as tools
|
||||
import lutin.debug as debug
|
||||
import os
|
||||
|
||||
|
||||
def get_type():
|
||||
return "LIBRARY"
|
||||
|
||||
def get_desc():
|
||||
return "eproperty is a property interface for basic class"
|
||||
|
||||
def get_licence():
|
||||
return "APACHE-2"
|
||||
|
||||
def get_compagny_type():
|
||||
return "com"
|
||||
|
||||
def get_compagny_name():
|
||||
return "atria-soft"
|
||||
|
||||
def get_maintainer():
|
||||
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
|
||||
|
||||
def get_version():
|
||||
return [0,1,"dev"]
|
||||
|
||||
def create(target, module_name):
|
||||
my_module = module.Module(__file__, module_name, get_type())
|
||||
my_module.add_extra_compile_flags()
|
||||
my_module.add_src_file([
|
||||
'eproperty/debug.cpp',
|
||||
'eproperty/Property.cpp',
|
||||
'eproperty/Interface.cpp',
|
||||
])
|
||||
my_module.add_header_file([
|
||||
'eproperty/debug.h',
|
||||
'eproperty/Value.h',
|
||||
'eproperty/Interface.h',
|
||||
'eproperty/Property.h',
|
||||
'eproperty/Range.h',
|
||||
'eproperty/List.h'
|
||||
])
|
||||
my_module.add_module_depend(['etk'])
|
||||
my_module.add_path(tools.get_current_path(__file__))
|
||||
my_module.compile_flags('c++', [
|
||||
"-DEPROPERTY_VERSION=\"\\\"" + tools.version_to_string(get_version()) + "\\\"\""
|
||||
])
|
||||
return my_module
|
||||
|
Loading…
Reference in New Issue
Block a user