[DEV] continue integration NO STL

This commit is contained in:
Edouard DUPIN 2017-08-28 21:39:39 +02:00
parent 1d99aa0112
commit 45fbda3786
10 changed files with 67 additions and 98 deletions

View File

@ -3,11 +3,11 @@
* @copyright 2011, Edouard DUPIN, all right reserved * @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/Pair.hpp>
#pragma once #include <etk/Vector.hpp>
#include <etk/String.hpp>
namespace etk { namespace etk {
/** /**
@ -189,22 +189,20 @@ namespace etk {
*/ */
ETK_MAP_TYPE_DATA& operator-> () const { ETK_MAP_TYPE_DATA& operator-> () const {
//TK_CHECK_INOUT(m_current < m_map->size()); //TK_CHECK_INOUT(m_current < m_map->size());
return &m_map->get(m_current); return &m_map->getValue(m_current);
} }
/** /**
* @brief Get reference on the current Element * @brief Get reference on the current Element
* @return the reference on the current Element * @return the reference on the current Element
*/ */
ETK_MAP_TYPE_DATA& operator* () const { ETK_MAP_TYPE_DATA& operator* () const {
//TK_CHECK_INOUT(m_current < m_map->size()); return m_map->getValue(m_current);
return m_map->get(m_current);
} }
/** /**
* @brief Get Key on the current Element * @brief Get Key on the current Element
* @return the Key on the current Element * @return the Key on the current Element
*/ */
const ETK_MAP_TYPE_KEY& getKey () const { const ETK_MAP_TYPE_KEY& getKey () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getKey(m_current); return m_map->getKey(m_current);
} }
/** /**
@ -212,7 +210,6 @@ namespace etk {
* @return the Key on the current Element * @return the Key on the current Element
*/ */
const ETK_MAP_TYPE_DATA& getValue () const { const ETK_MAP_TYPE_DATA& getValue () const {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getValue(m_current); return m_map->getValue(m_current);
} }
/** /**
@ -220,7 +217,6 @@ namespace etk {
* @return the Key on the current Element * @return the Key on the current Element
*/ */
ETK_MAP_TYPE_DATA& getValue () { ETK_MAP_TYPE_DATA& getValue () {
//TK_CHECK_INOUT(m_current < m_map->size());
return m_map->getValue(m_current); return m_map->getValue(m_current);
} }
@ -232,17 +228,29 @@ namespace etk {
} }
friend class Map; friend class Map;
}; };
static bool defaultSort(etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key1,
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* const & _key2) {
return _key1->first < _key2->first;
}
private: private:
etk::Vector<etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>*> m_data; //!< Data of the Map ==> the Map table is composed of pointer, this permit to have high speed when resize the vector ... etk::Vector<etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>*> m_data; //!< Data of the Map ==> the Map table is composed of pointer, this permit to have high speed when resize the vector ...
bool m_ordered;
public: public:
/** /**
* @brief Constructor of the Map table. * @brief Constructor of the Map table.
* @param[in] _count Number of basic element in the table. * @param[in] _count Number of basic element in the table.
*/ */
Map(int32_t _count = 0) : Map(int32_t _count = 0, bool _ordered=true) :
m_data(_count) { m_data(_count),
m_ordered(_ordered) {
// nothing to do // nothing to do
} }
void setOrdered(bool _ordered) {
m_ordered = _ordered;
if (m_ordered == true) {
m_data.sort(0, m_data.size(), etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>::defaultSort);
}
}
/** /**
* @brief Destructor of the Map table (clear all element in the table) * @brief Destructor of the Map table (clear all element in the table)
*/ */
@ -268,15 +276,16 @@ namespace etk {
* @return Id of the element in the table or -1 of it does not existed * @return Id of the element in the table or -1 of it does not existed
*/ */
int64_t getId(const ETK_MAP_TYPE_KEY& _key) const { int64_t getId(const ETK_MAP_TYPE_KEY& _key) const {
if (m_ordered == true) {
// TODO: search in a dichotomic way.
}
for (size_t iii=0; iii<m_data.size(); iii++) { for (size_t iii=0; iii<m_data.size(); iii++) {
if (m_data[iii] != nullptr) { if (m_data[iii] != nullptr) {
//TK_INFO("Compare key : '" << m_data[iii]->m_key << "' with '" << _key << "'" );
if (m_data[iii]->first == _key) { if (m_data[iii]->first == _key) {
return iii; return iii;
} }
} }
} }
//TK_ERROR(" ==> not fund key '" << _key << "'" );
return -1; return -1;
} }
/** /**
@ -286,12 +295,9 @@ namespace etk {
*/ */
bool exist(const ETK_MAP_TYPE_KEY& _name) const { bool exist(const ETK_MAP_TYPE_KEY& _name) const {
int64_t elementId = getId(_name); int64_t elementId = getId(_name);
//TK_INFO(" Exist ? '" << _name << "' id=" << elementId );
if (elementId<0) { if (elementId<0) {
//TK_INFO(" ==> return false" );
return false; return false;
} }
//TK_INFO(" ==> return true" );
return true; return true;
} }
/** /**
@ -335,10 +341,13 @@ namespace etk {
if (elementId <0) { if (elementId <0) {
etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* tmp = new etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>(etk::move(_key), etk::move(_value)); etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>* tmp = new etk::Pair<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>(etk::move(_key), etk::move(_value));
if (tmp == nullptr) { if (tmp == nullptr) {
//TK_ERROR("allocation error in Map table : '" << _key << "'");
return; return;
} }
m_data.pushBack(tmp); m_data.pushBack(tmp);
// Order data if needed.
if (m_ordered == true) {
m_data.sort(0, m_data.size(), etk::Map<ETK_MAP_TYPE_KEY, ETK_MAP_TYPE_DATA>::defaultSort);
}
return; return;
} }
m_data[elementId]->second = _value; m_data[elementId]->second = _value;
@ -356,7 +365,7 @@ namespace etk {
* @brief Remove an element in the Map table. * @brief Remove an element in the Map table.
* @param[in] _key Name of the element to remove. * @param[in] _key Name of the element to remove.
*/ */
void remove(const ETK_MAP_TYPE_KEY& _key) { void erase(const ETK_MAP_TYPE_KEY& _key) {
int64_t elementId = getId(_key); int64_t elementId = getId(_key);
if (elementId <0) { if (elementId <0) {
//nothing to do ==> not existed //nothing to do ==> not existed
@ -366,6 +375,17 @@ namespace etk {
m_data[elementId] = nullptr; m_data[elementId] = nullptr;
m_data.erase(m_data.begin()+elementId); m_data.erase(m_data.begin()+elementId);
} }
/**
* @brief Remove an element in the Map table.
* @param[in] _it Iterator on the element.
*/
Iterator erase(const Iterator& _it) {
int64_t elementId = _it.m_current;
delete(m_data[elementId]);
m_data[elementId] = nullptr;
m_data.erase(m_data.begin()+elementId);
return position(elementId);
}
/** /**
* @brief Get the number of element in the Map table * @brief Get the number of element in the Map table
* @return number of elements * @return number of elements
@ -373,36 +393,12 @@ namespace etk {
size_t size() const { size_t size() const {
return m_data.size(); return m_data.size();
} }
/**
* @brief get an element with his id.
* @param[in] _pos Position on the element in the Map table.
* @return requested element at this position.
* @note this is a dangerous use of the Map table. Maybe you will use a simple vector.
*/
ETK_MAP_TYPE_DATA& operator[] (size_t _pos) {
return getValue(_pos);
}
/**
* @brief get an element with his id.
* @param[in] _pos Position on the element in the Map table.
* @return requested element at this position.
* @note this is a dangerous use of the Map table. Maybe you will use a simple vector.
*/
const ETK_MAP_TYPE_DATA& operator[] (size_t _pos) const {
return getValue(_pos);
}
/** /**
* @brief Get the name of the element at a specific position. * @brief Get the name of the element at a specific position.
* @param[in] _pos Position of the element in the Map table. * @param[in] _pos Position of the element in the Map table.
* @return name of the element (key). * @return name of the element (key).
*/ */
const ETK_MAP_TYPE_KEY& getKey(size_t _pos) const { const ETK_MAP_TYPE_KEY& getKey(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->m_key; return m_data[_pos]->m_key;
} }
/** /**
@ -424,24 +420,12 @@ namespace etk {
* @return Value available at this position. * @return Value available at this position.
*/ */
const ETK_MAP_TYPE_DATA& getValue(size_t _pos) const { const ETK_MAP_TYPE_DATA& getValue(size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->second; return m_data[_pos]->second;
} }
/** /**
* @copydoc getValue (size_t) * @copydoc getValue (size_t)
*/ */
ETK_MAP_TYPE_DATA& getValue(size_t _pos) { ETK_MAP_TYPE_DATA& getValue(size_t _pos) {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_data.size()){
//TK_CRITICAL("Access to an inexistent data in Map : " << _pos << "/ " << m_data.size());
}
#endif
return m_data[_pos]->second; return m_data[_pos]->second;
} }
@ -482,14 +466,14 @@ namespace etk {
if (elementId <0) { if (elementId <0) {
return end(); return end();
} }
position(elementId); return position(elementId);
} }
const Iterator find(const ETK_MAP_TYPE_KEY& _key) const { const Iterator find(const ETK_MAP_TYPE_KEY& _key) const {
int64_t elementId = getId(_key); int64_t elementId = getId(_key);
if (elementId <0) { if (elementId <0) {
return end(); return end();
} }
position(elementId); return position(elementId);
} }

View File

@ -13,7 +13,7 @@ namespace etk {
class Pair { class Pair {
public: public:
ETK_PAIR_TYPE_1 first; ETK_PAIR_TYPE_1 first;
ETK_PAIR_TYPE_1 second; ETK_PAIR_TYPE_2 second;
Pair(): Pair():
first(), first(),
second() { second() {

View File

@ -12,6 +12,7 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/UString.hpp> #include <etk/UString.hpp>
#include <etk/pair.hpp>
#include <memory> #include <memory>
#define TK_REG_DEBUG TK_HIDDEN #define TK_REG_DEBUG TK_HIDDEN
@ -173,6 +174,9 @@ etk::String autoStr(const etk::String& _data);
etk::String autoStr(char _data); etk::String autoStr(char _data);
etk::String strTick(int32_t _pos); etk::String strTick(int32_t _pos);
class FindProperty;
etk::Stream& operator <<(etk::Stream& _os, const FindProperty& _obj);
/** /**
* @brief Node Elements for every-one * @brief Node Elements for every-one
* @not-in-doc * @not-in-doc
@ -217,7 +221,7 @@ class FindProperty {
void setPositionStop(int64_t _newPos) { void setPositionStop(int64_t _newPos) {
m_positionStop = _newPos; m_positionStop = _newPos;
if (m_positionStop < m_positionStart) { if (m_positionStop < m_positionStart) {
TK_CRITICAL("set voluntary a stop position before end : " << this << " start=" << m_positionStart << " stop=" << m_positionStop); TK_CRITICAL("set voluntary a stop position before end : " << *this << " start=" << m_positionStart << " stop=" << m_positionStop);
} }
} }
uint32_t getMultiplicity() const { uint32_t getMultiplicity() const {
@ -276,8 +280,6 @@ class FindProperty {
} }
}; };
etk::Stream& operator <<(etk::Stream& _os, const FindProperty& _obj);
/** /**
* @brief Node Elements for every-one * @brief Node Elements for every-one
* @not-in-doc * @not-in-doc

View File

@ -363,13 +363,7 @@ namespace etk {
* @param[in] _pos Desired position read * @param[in] _pos Desired position read
* @return Reference on the Element * @return Reference on the Element
*/ */
ETK_VECTOR_TYPE& get(size_t _pos) { ETK_VECTOR_TYPE& get(const size_t _pos) {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_size){
TK_CRITICAL("[CRITICAL] Access to an inexistent data in vector : " << _pos << "/ " << m_size);
}
#endif
return m_data[_pos]; return m_data[_pos];
} }
/** /**
@ -377,21 +371,15 @@ namespace etk {
* @param[in] _pos Position in the vector that might be get [0..Size()] * @param[in] _pos Position in the vector that might be get [0..Size()]
* @return An reference on the copy of selected element * @return An reference on the copy of selected element
*/ */
ETK_VECTOR_TYPE& operator[] (size_t _pos) { ETK_VECTOR_TYPE& operator[] (const size_t _pos) {
return get(_pos); return m_data[_pos];
} }
/** /**
* @brief Get an Element an a special position * @brief Get an Element an a special position
* @param[in] _pos Position in the vector that might be get [0..Size()] * @param[in] _pos Position in the vector that might be get [0..Size()]
* @return An reference on the selected element * @return An reference on the selected element
*/ */
const ETK_VECTOR_TYPE& operator[] (size_t _pos) const { const ETK_VECTOR_TYPE& operator[] (const size_t _pos) const {
// NOTE :Do not change log level, this generate error only in debug mode
#if DEBUG_LEVEL > 2
if(_pos>m_size){
TK_CRITICAL("[CRITICAL] Access to an inexistent data in vector : " << _pos << "/ " << m_size);
}
#endif
return m_data[_pos]; return m_data[_pos];
} }
/** /**

View File

@ -17,7 +17,7 @@ const etk::String& etk::Archive::getName(size_t _id) const {
size_t id = 0; size_t id = 0;
for (auto &it : m_content) { for (auto &it : m_content) {
if (id == _id) { if (id == _id) {
return it.first; return it.getKey();
} }
++id; ++id;
} }
@ -30,7 +30,7 @@ const etk::ArchiveContent& etk::Archive::getContent(size_t _id) const {
size_t id = 0; size_t id = 0;
for (auto &it : m_content) { for (auto &it : m_content) {
if (id == _id) { if (id == _id) {
return it.second; return it.getValue();
} }
++id; ++id;
} }
@ -43,7 +43,7 @@ const etk::ArchiveContent& etk::Archive::getContent(const etk::String& _key) con
if (it == m_content.end()) { if (it == m_content.end()) {
return g_error; return g_error;
} }
return it->second; return it->getValue();
} }
@ -55,9 +55,9 @@ bool etk::Archive::exist(const etk::String& _key) const {
void etk::Archive::display() { void etk::Archive::display() {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
for (auto &it : m_content) { for (auto &it : m_content) {
int32_t size = it.second.getTheoricSize(); int32_t size = it.getValue().getTheoricSize();
int32_t sizeR = it.second.size(); int32_t sizeR = it.getValue().size();
TK_INFO(" element : " << it.first << " size=" << size << " allocated=" << sizeR); TK_INFO(" element : " << it.getKey() << " size=" << size << " allocated=" << sizeR);
} }
} }
@ -118,11 +118,11 @@ void etk::Archive::open(const etk::String& _key) {
TK_ERROR("Try open an unexistant file : '" << _key << "'"); TK_ERROR("Try open an unexistant file : '" << _key << "'");
return; return;
} }
if (it->second.getNumberOfRef()==-1) { if (it->getValue().getNumberOfRef()==-1) {
loadFile(it); loadFile(it);
it->second.increaseRef(); it->getValue().increaseRef();
} }
it->second.increaseRef(); it->getValue().increaseRef();
} }
void etk::Archive::close(const etk::String& _key) { void etk::Archive::close(const etk::String& _key) {
@ -132,10 +132,10 @@ void etk::Archive::close(const etk::String& _key) {
TK_ERROR("Try close an unexistant file : '" << _key << "'"); TK_ERROR("Try close an unexistant file : '" << _key << "'");
return; return;
} }
if (it->second.getNumberOfRef()==0){ if (it->getValue().getNumberOfRef()==0){
TK_ERROR("Try close one more time the file : '" << _key << "'"); TK_ERROR("Try close one more time the file : '" << _key << "'");
} else { } else {
it->second.decreaseRef(); it->getValue().decreaseRef();
} }
} }

View File

@ -167,7 +167,7 @@ namespace etk {
* @brief Request the load in memory of the concerned file. * @brief Request the load in memory of the concerned file.
* @param[in] _it Iterator on the element. * @param[in] _it Iterator on the element.
*/ */
virtual void loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& _it) { }; virtual void loadFile(const etk::Map<etk::String, ArchiveContent>::Iterator& _it) { };
public: public:
/** /**
* @brief Load an Achive with a specific name. * @brief Load an Achive with a specific name.

View File

@ -57,7 +57,7 @@ etk::archive::Zip::~Zip() {
}; };
} }
void etk::archive::Zip::loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& it) { void etk::archive::Zip::loadFile(const etk::Map<etk::String, ArchiveContent>::Iterator& it) {
TK_VERBOSE("Real load file : '" << it->first << "'"); TK_VERBOSE("Real load file : '" << it->first << "'");
unzGoToFirstFile(m_ctx); unzGoToFirstFile(m_ctx);

View File

@ -34,7 +34,7 @@
*/ */
virtual ~Zip(); virtual ~Zip();
protected: protected:
void loadFile(const etk::Map<etk::String, ArchiveContent>::iterator& _it) override; void loadFile(const etk::Map<etk::String, ArchiveContent>::Iterator& _it) override;
}; };
} }
} }

View File

@ -119,14 +119,6 @@ namespace etk {
// forward _Arg as movable // forward _Arg as movable
return ((typename etk::_Remove_reference<ETK_MOVE_TYPE>::m_type&&)_obj); return ((typename etk::_Remove_reference<ETK_MOVE_TYPE>::m_type&&)_obj);
} }
/*
template<class ETK_MOVE_TYPE>
eETK_MOVE_TYPE&& move(ETK_MOVE_TYPE&& _obj) {
// forward _Arg as movable
return ((ETK_MOVE_TYPE&&)_obj);
}
*/
} }

View File

@ -54,6 +54,9 @@ def configure(target, my_module):
# add dependency of the generic C++ library: # add dependency of the generic C++ library:
my_module.add_depend([ my_module.add_depend([
'c', 'c',
'm',
"pthread",
"cxx",
]) ])
if "Android" in target.get_type(): if "Android" in target.get_type():