[DOC] base documentation and change API of 'properties.xxx' for interface

This commit is contained in:
Edouard DUPIN 2016-04-05 21:02:05 +02:00
parent 5907ee7abd
commit dfaa1bd035
18 changed files with 267 additions and 154 deletions

42
doc/mainpage.md Normal file
View File

@ -0,0 +1,42 @@
EPROPERTY library {#mainpage}
=================
What is EPROPERTY, and how can I use it?
----------------------------------------
EPROPERTY, or Ewol signal engine is a simple messaging layer, managing multiple connection and manage disconnection
EPROPERTY is designed for
- Expose property on generic class
- Call class when the parameter change
What languages are supported?
-----------------------------
EPROPERTY is written in C++.
Are there any licensing restrictions?
-------------------------------------
EPROPERTY is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
License (APACHE-2.0)
--------------------
Copyright EPROPERTY Edouard DUPIN
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<http://www.apache.org/licenses/LICENSE-2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -10,7 +10,10 @@ def create(target, module_name):
my_module.set_title("eproperty: Ewol property interface")
my_module.set_website("http://atria-soft.github.io/" + module_name)
my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
my_module.set_path(os.path.join(tools.get_current_path(__file__), module_name))
my_module.add_path([
module_name,
"doc"
])
my_module.add_module_depend([
'etk'
])

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -9,73 +9,16 @@
#include <vector>
#include <map>
#include <eproperty/InterfaceData.h>
namespace eproperty {
class Property;
class Ref;
/**
* @brief Interface to collect the property list (for abstarction "set" and "get")
* It create a simple "properties" member that permit to access at the properties.
*/
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 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.
* @param[in] _id Id of the property.
* @param[in] _name name of the property.
* @return pointer on the property.
*/
eproperty::Property* getPropertyRaw(const size_t& _id) const;
//! @previous
eproperty::Property* getPropertyRaw(const std::string _name) const;
eproperty::InterfaceData properties; //!< Interface to access at all properties...
};
}

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -9,20 +9,18 @@
#include <eproperty/debug.h>
#include <eproperty/List.h>
#include <eproperty/Property.h>
#include <eproperty/InterfaceData.h>
#undef __class__
#define __class__ "Interface"
eproperty::Interface::Interface() {
eproperty::InterfaceData::InterfaceData() {
}
eproperty::Interface::~Interface() {
propertyClean();
eproperty::InterfaceData::~InterfaceData() {
clean();
}
// note this pointer is not allocated and not free at the end of the class
void eproperty::Interface::propertyAdd(eproperty::Property* _pointerOnProperty) {
void eproperty::InterfaceData::add(eproperty::Property* _pointerOnProperty) {
if (_pointerOnProperty == nullptr) {
EPROPERTY_ERROR("Try to link a nullptr properties");
return;
@ -36,14 +34,14 @@ void eproperty::Interface::propertyAdd(eproperty::Property* _pointerOnProperty)
m_list.push_back(_pointerOnProperty);
}
void eproperty::Interface::propertyClean() {
void eproperty::InterfaceData::clean() {
// 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) {
bool eproperty::InterfaceData::set(const std::string& _property, const std::string& _value) {
for (auto &it : m_list) {
if( it != nullptr
&& it->getName() == _property) {
@ -55,7 +53,7 @@ bool eproperty::Interface::propertySet(const std::string& _property, const std::
return false;
}
std::string eproperty::Interface::propertyGet(const std::string& _property) const {
std::string eproperty::InterfaceData::get(const std::string& _property) const {
for (auto &it : m_list) {
if( it != nullptr
&& it->getName() == _property) {
@ -65,7 +63,7 @@ std::string eproperty::Interface::propertyGet(const std::string& _property) cons
return "???";
}
void eproperty::Interface::propertyDisplay(bool _changeOnly) const {
void eproperty::InterfaceData::display(bool _changeOnly) const {
EPROPERTY_INFO(" Object propertys:");
for (auto &it : m_list) {
if(it != nullptr) {
@ -82,7 +80,7 @@ void eproperty::Interface::propertyDisplay(bool _changeOnly) const {
}
}
std::map<std::string, std::string> eproperty::Interface::propertyGetAll(bool _notIfDefault) const {
std::map<std::string, std::string> eproperty::InterfaceData::getAll(bool _notIfDefault) const {
std::map<std::string, std::string> out;
for (auto &it : m_list) {
if(it != nullptr) {
@ -98,11 +96,11 @@ std::map<std::string, std::string> eproperty::Interface::propertyGetAll(bool _no
}
size_t eproperty::Interface::getPropertyCount() const {
size_t eproperty::InterfaceData::size() const {
return m_list.size();
}
eproperty::Property* eproperty::Interface::getPropertyRaw(const size_t& _id) const {
eproperty::Property* eproperty::InterfaceData::getRaw(const size_t& _id) const {
if (_id >= m_list.size()) {
EPROPERTY_ERROR("Wrong ID for property list. " << _id << " >= " << m_list.size());
return nullptr;
@ -110,11 +108,12 @@ eproperty::Property* eproperty::Interface::getPropertyRaw(const size_t& _id) con
return m_list[_id];
}
eproperty::Property* eproperty::Interface::getPropertyRaw(const std::string _name) const {
eproperty::Property* eproperty::InterfaceData::getRaw(const std::string _name) const {
for (auto &it : m_list) {
if(it->getName() == _name) {
return it;
}
}
return nullptr;
}
}

87
eproperty/InterfaceData.h Normal file
View File

@ -0,0 +1,87 @@
/** @file
* @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;
/**
* @brief Interface data to collect the property list (for abstarction connection)
*/
class InterfaceData {
private:
std::vector<eproperty::Property*> m_list; //!< list of availlable Propertys (no need to free)
public:
/**
* @brief Constructor.
*/
InterfaceData();
/**
* @brief Destructor.
*/
virtual ~InterfaceData();
/**
* @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 add(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 clean();
/**
* @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 set(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 get(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 display(bool _changeOnly = false) const;
/**
* @brief Get All the property configuration:
* @param[in] _notIfDefault if true the parameter value with default value are not extracted.
* @return map on the propertys
*/
std::map<std::string, std::string> getAll(bool _notIfDefault=true) const;
public:
/**
* @brief Get count of propertys.
* @return The number of the property.
*/
size_t size() const;
/**
* @brief Get name of a propertys.
* @param[in] _id Id of the property.
* @return pointer on the property.
*/
eproperty::Property* getRaw(const size_t& _id) const;
/**
* @brief Get name of a propertys.
* @param[in] _name name of the property.
* @return pointer on the property.
*/
eproperty::Property* getRaw(const std::string _name) const;
};
}

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -11,10 +11,10 @@
#include <map>
#include <typeinfo>
#undef __class__
#define __class__ "List<T>"
namespace eproperty {
/**
* @brief Set a list of value availlable (for enumeration)
*/
template<class TYPE> class List : public PropertyType<TYPE> {
private:
std::map<std::string, TYPE> m_list; //!< pointer on the list of all elements.
@ -37,9 +37,15 @@ namespace eproperty {
};
/**
* @brief Destructor.
* @brief virtualisation of Destructor.
*/
virtual ~List() = default;
/**
* @brief Add a value in the list of parameter
* @param[in] _value Value of the string
* @param[in] _name String of the value
* @param[in] _description Description of the parameter value
*/
void add(const TYPE& _value, const std::string& _name, const std::string& _description = "") {
auto it = m_list.find(_name);
if (it != m_list.end()) {
@ -48,6 +54,10 @@ namespace eproperty {
}
m_list.insert(std::make_pair(_name, _value));
}
/**
* @brief Remove a value of the element availlable
* @param[in] _name Name of the value to remove
*/
void remove(const std::string& _name) {
auto it = m_list.find(_name);
bool firstValue = false;
@ -75,6 +85,11 @@ namespace eproperty {
eproperty::PropertyType<TYPE>::m_value = m_list.begin()->second;
}
}
/**
* @brief Rename a value of the property
* @param[in] _nameOld Old property name to replace
* @param[in] _nameNew New name of the property
*/
void rename(const std::string& _nameOld, const std::string& _nameNew) {
//get old value
TYPE value;
@ -101,9 +116,11 @@ namespace eproperty {
return;
}
EPROPERTY_WARNING("paramList value='" << _newVal << "' is not un the list ... ==> no change");
for (auto &it : m_list) {
EPROPERTY_VERBOSE(" element : " << it.first);
}
#ifdef DEBUG
for (auto &it : m_list) {
EPROPERTY_VERBOSE(" element : " << it.first);
}
#endif
}
std::string getInfo() const override {
std::string list = "List default=" + getValueSpecific(eproperty::PropertyType<TYPE>::m_default) + " in : [";
@ -163,12 +180,10 @@ namespace eproperty {
return "???";
}
};
//! @not_in_doc
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::List<TYPE>& _obj) {
_os << _obj.get();
return _os;
}
}
#undef __class__
#define __class__ nullptr

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -17,7 +17,7 @@ eproperty::Property::Property(eproperty::Interface* _paramInterfaceLink, const s
m_name(_name) {
// add a reference on the current Property ...
if (m_interfaceLink != nullptr) {
m_interfaceLink->propertyAdd(this);
m_interfaceLink->properties.add(this);
}
}

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -12,19 +12,38 @@
#include <typeinfo>
#include <functional>
/**
* @brief eproperty global interface for all property implementation
*/
namespace eproperty {
class Ref;
/**
* @brief Base of the property With all generic element needed
*/
class Property {
public:
using Observer = std::function<void()>;
using Observer = std::function<void()>; //!< Local main object observer of changing value of the property
private:
eproperty::Interface* m_interfaceLink;
Observer m_setObserver;
std::string m_name;
eproperty::Interface* m_interfaceLink; //!< Base interface class to group all the property
Observer m_setObserver; //!< Observer of the changing value
std::string m_name; //!< Name of the property
public:
/**
* @brief Basic property elements
* @param[in] _paramInterfaceLink Link on the esignal::Interface class to register parameter (can be nullptr)
* @param[in] _name Name of the parameter (must be unique if _paramInterfaceLink is define)
*/
Property(eproperty::Interface* _paramInterfaceLink, const std::string& _name);
/**
* @brief Virtualize the destructor
* @internal
*/
virtual ~Property() = default;
protected:
/**
* @brief Set the change observer of the property
* @param[in] _setObs New observer of the property
*/
void setObserver(eproperty::Property::Observer _setObs);
public:
/**
@ -83,16 +102,22 @@ namespace eproperty {
return std::vector<std::string>();
}
public:
//! @not_in_doc
template<class TYPE>
bool operator== (const TYPE& _obj) const = delete;
//! @not_in_doc
template<class TYPE>
bool operator!= (const TYPE& _obj) const = delete;
//! @not_in_doc
template<class TYPE>
bool operator<= (const TYPE& _obj) const = delete;
//! @not_in_doc
template<class TYPE>
bool operator>= (const TYPE& _obj) const = delete;
//! @not_in_doc
template<class TYPE>
bool operator< (const TYPE& _obj) const = delete;
//! @not_in_doc
template<class TYPE>
bool operator> (const TYPE& _obj) const = delete;
};

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -11,10 +11,10 @@
#include <eproperty/Property.h>
#include <eproperty/debug.h>
#undef __class__
#define __class__ "PropertyType<T>"
namespace eproperty {
/**
* @brief Template base of the property (have a generic set and get for string)
*/
template<class TYPE> class PropertyType : public Property {
protected:
TYPE m_value; //!< Current value.
@ -66,6 +66,10 @@ namespace eproperty {
void setDefault() override {
set(m_default);
}
/**
* @brief Set new default value on the property
* @param[in] _newDefault New value to set
*/
virtual void changeDefault(const TYPE& _newDefault) {
m_default = _newDefault;
}
@ -80,7 +84,7 @@ namespace eproperty {
};
/**
* @brief Set a new value for this parameter
* @param[in] newVal New value to set (set the nearest value if range is set)
* @param[in] _newVal New value to set (set the nearest value if range is set)
*/
virtual void set(const TYPE& _newVal) {
if (_newVal != m_value) {
@ -93,11 +97,16 @@ namespace eproperty {
* @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
* @param[in] _newVal New value to set
*/
inline void setDirect(const TYPE& _newVal) {
m_value = _newVal;
}
/**
* @brief Set the value of the current parameter (check range and ... if needed).
* @note Only use by the owner of the property/
* @param[in] _newVal New value to set
*/
virtual void setDirectCheck(const TYPE& _newVal) {
m_value = _newVal;
}
@ -111,25 +120,40 @@ namespace eproperty {
TYPE& getDirect() {
return m_value;
}
/**
* @brief Get the string of the specify value.
* @param[in] _valueRequested Value to convert in string
* @return convertion of the value in string.
*/
virtual std::string getValueSpecific(const TYPE& _valueRequested) const = 0;
public:
/**
* @brief Const cast the property in the Type of the data
* @return Const reference on the value.
*/
operator const TYPE&() const {
return m_value;
}
/**
* @brief Get the property Value
* @return Const reference on the value.
*/
const TYPE& operator *() const noexcept {
return m_value;
}
/**
* @brief Get the property Value
* @return Const reference on the value.
*/
const TYPE* operator->() const noexcept {
return &m_value;
}
//! @not_in_doc
const PropertyType<TYPE>& operator= (const TYPE& _newVal) = delete;
};
//! @not_in_doc
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::PropertyType<TYPE>& _obj) {
_os << _obj.get();
return _os;
}
}
#undef __class__
#define __class__ nullptr

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -11,10 +11,11 @@
#include <eproperty/Value.h>
#include <typeinfo>
#undef __class__
#define __class__ "Range<T>"
namespace eproperty {
/**
* @brief Range template of the property (limit with a min and a max value)
* @tparam TYPE Tpe of the range value
*/
template<class TYPE> class Range : public Value<TYPE> {
private:
TYPE m_min; //!< Minimum value.
@ -56,13 +57,9 @@ namespace eproperty {
void set(const TYPE& _newVal) override;
void setDirectCheck(const TYPE& _newVal) override;
};
//! @not_in_doc
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Range<TYPE>& _obj) {
_os << _obj.get();
return _os;
}
}
#undef __class__
#define __class__ nullptr

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -13,10 +13,10 @@
#include <etk/math/Vector3D.h>
#include <etk/Color.h>
#undef __class__
#define __class__ "Value<T>"
namespace eproperty {
/**
* @brief Simple Value of the property (need to implement fuction etk::from_string<TYPE> to use it)
*/
template<class TYPE> class Value : public PropertyType<TYPE> {
public:
/**
@ -37,21 +37,13 @@ namespace eproperty {
}
protected:
/**
* @brief Get the string of the specify value.
* @return convetion of the velue in string.
*/
std::string getValueSpecific(const TYPE& _valueRequested) const override;
void setString(const std::string& _newVal) override;
};
//! @not_in_doc
template<typename TYPE> std::ostream& operator <<(std::ostream& _os, const eproperty::Value<TYPE>& _obj) {
_os << _obj.get();
return _os;
}
}
#undef __class__
#define __class__ nullptr

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -11,8 +11,6 @@
#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>;

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -9,9 +9,6 @@
#include <eproperty/Range.h>
#undef __class__
#define __class__ "Range<T>"
template<class TYPE>
std::string eproperty::Range<TYPE>::getPropertyType() const {
return "eproperty::Range";

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -12,8 +12,6 @@
#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>;

View File

@ -1,4 +1,4 @@
/**
/** @file
* @author Edouard DUPIN
*
* @copyright 2016, Edouard DUPIN, all right reserved
@ -9,9 +9,6 @@
#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);
@ -24,8 +21,3 @@ void eproperty::Value<TYPE>::setString(const std::string& _newVal) {
// TODO : Do it better ...
eproperty::PropertyType<TYPE>::notifyChange();
}
#undef __class__
#define __class__ nullptr

View File

@ -32,7 +32,7 @@ def create(target, module_name):
my_module.add_src_file([
'eproperty/debug.cpp',
'eproperty/Property.cpp',
'eproperty/Interface.cpp',
'eproperty/InterfaceData.cpp',
'eproperty/details/Range.cpp',
'eproperty/details/Value.cpp',
])
@ -40,6 +40,7 @@ def create(target, module_name):
'eproperty/debug.h',
'eproperty/Value.h',
'eproperty/Interface.h',
'eproperty/InterfaceData.h',
'eproperty/Property.h',
'eproperty/PropertyType.h',
'eproperty/Range.h',