debut de déplacement du vecteur
This commit is contained in:
parent
0fe575e432
commit
e3e868f351
@ -1,29 +0,0 @@
|
||||
|
||||
#include "tools_debug.h"
|
||||
#include "tools_globals.h"
|
||||
|
||||
#include "VectorType.h"
|
||||
|
||||
void TestTemplate(void)
|
||||
{
|
||||
|
||||
EDN_WARNING("Start Template Test ...");
|
||||
Edn::VectorType<int32_t> plop;
|
||||
Edn::VectorType<int8_t> plop2;
|
||||
|
||||
plop.PushBack(15365);
|
||||
plop.PushBack(1);
|
||||
plop.PushBack(2);
|
||||
plop.PushBack(3);
|
||||
plop.PushBack(4);
|
||||
|
||||
EDN_INFO("data is : " << plop[0]);
|
||||
EDN_INFO("data is : " << plop[1]);
|
||||
EDN_INFO("data is : " << plop[2]);
|
||||
EDN_INFO("data is : " << plop[3]);
|
||||
|
||||
plop2.PushBack(65);
|
||||
|
||||
EDN_INFO("data is : " << plop2[0]);
|
||||
|
||||
}
|
@ -1,186 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file EdnTree.h
|
||||
* @brief Editeur De N'ours : Basic tree in a vector For none expensive tree (template)
|
||||
* @author Edouard DUPIN
|
||||
* @date 04/04/2011
|
||||
* @par Project
|
||||
* Edn
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2010 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
* You can not earn money with this Software (if the source extract from Edn
|
||||
* represent less than 50% of original Sources)
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
#ifndef __EDN_TREE_H__
|
||||
#define __EDN_TREE_H__
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "EdnTreeElement"
|
||||
|
||||
template < class T > class EdnTreeElement
|
||||
{
|
||||
public:
|
||||
EdnTreeElement(int32_t parent, int32_t id, T &maNouvelleClass) : elementPtr(NULL), m_parent(parent), m_id(id)
|
||||
{
|
||||
elementPtr = new T(maNouvelleClass);
|
||||
};
|
||||
~EdnTreeElement(void)
|
||||
{
|
||||
delete(elementPtr);
|
||||
};
|
||||
EdnTreeElement(const EdnTreeElement &mustCopy ) : elementPtr(NULL), m_parent(mustCopy.m_parent), m_id(mustCopy.m_id)
|
||||
{
|
||||
elementPtr = new T(*mustCopy.elementPtr);
|
||||
}
|
||||
int32_t GetParrent(void) { return m_parent;};
|
||||
int32_t GetId(void) { return m_id;};
|
||||
T* GetPtr() const
|
||||
{
|
||||
return elementPtr;
|
||||
};
|
||||
|
||||
private:
|
||||
T* elementPtr; // pointer on the curent element
|
||||
int32_t m_parent;
|
||||
int32_t m_id;
|
||||
};
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "EdnTree"
|
||||
|
||||
#define ROOT_NODE_ID (-1)
|
||||
|
||||
template < class T > class EdnTree
|
||||
{
|
||||
public:
|
||||
// constructeur et destructeur
|
||||
EdnTree(void)
|
||||
{
|
||||
m_LastId = 0;
|
||||
};
|
||||
|
||||
~EdnTree(void)
|
||||
{
|
||||
|
||||
};
|
||||
// Common function ...
|
||||
int32_t GetNumberNode(void)
|
||||
{
|
||||
return m_listElement.size();
|
||||
};
|
||||
|
||||
int32_t GetDepth(void)
|
||||
{
|
||||
// TODO : ...
|
||||
return 0;
|
||||
};
|
||||
//!< add an element in the tree
|
||||
int32_t Add(T &maNouvelleClass, int32_t parent=-1)
|
||||
{
|
||||
if (true == CheckPresenceParrent(parent)) {
|
||||
// create the local element
|
||||
EdnTreeElement<T> nouvelElement(parent, m_LastId, maNouvelleClass);
|
||||
// add it in the list
|
||||
m_listElement.push_back(nouvelElement);
|
||||
// increment the ID of the element
|
||||
m_LastId++;
|
||||
// Add is Ok, in theory ...
|
||||
return m_LastId-1;
|
||||
}
|
||||
return -2;
|
||||
};
|
||||
|
||||
bool Remove(int32_t id)
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
bool Clear(void)
|
||||
{
|
||||
return false;
|
||||
};
|
||||
|
||||
T* Get(int32_t id)
|
||||
{
|
||||
// try to find ID
|
||||
int32_t realID = FindElementWithId(id);
|
||||
// when we find it, check it
|
||||
if (0 > realID || realID >= m_LastId) {
|
||||
return NULL;
|
||||
}
|
||||
// Return the element :
|
||||
return m_listElement[realID].GetPtr();
|
||||
};
|
||||
|
||||
std::vector<int32_t> GetListSubNode( int32_t parentId = ROOT_NODE_ID)
|
||||
{
|
||||
std::vector<int32_t> res;
|
||||
int32_t i;
|
||||
for (i=0; i<(int32_t)m_listElement.size(); i++) {
|
||||
if (m_listElement[i].GetParrent() == parentId) {
|
||||
// Add the element ID in the list ...
|
||||
res.push_back(m_listElement[i].GetId());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
std::vector<int32_t> Root(void)
|
||||
{
|
||||
return GetListSubNode(ROOT_NODE_ID);
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
int32_t m_LastId;
|
||||
std::vector< EdnTreeElement<T> > m_listElement; //!< list of element...
|
||||
|
||||
bool CheckPresence(int32_t id)
|
||||
{
|
||||
int32_t i;
|
||||
for (i=0; i<(int32_t)m_listElement.size(); i++) {
|
||||
if (m_listElement[i].GetId() == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
bool CheckPresenceParrent(int32_t parrentId)
|
||||
{
|
||||
if (ROOT_NODE_ID == parrentId) {
|
||||
return true;
|
||||
}
|
||||
return CheckPresence(parrentId);
|
||||
};
|
||||
|
||||
int32_t FindElementWithId(int32_t id)
|
||||
{
|
||||
int32_t i;
|
||||
for (i=0; i<(int32_t)m_listElement.size(); i++) {
|
||||
if (m_listElement[i].GetId() == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return ROOT_NODE_ID;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ NULL
|
||||
|
||||
#endif
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "tools_debug.h"
|
||||
#include "toolsMemory.h"
|
||||
#include "Vector.h"
|
||||
#include "VectorType.h"
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file EdnEdnVector.h
|
||||
* @brief Editeur De N'ours : Basic EdnVector (template)
|
||||
* @file Vector.h
|
||||
* @brief Editeur De N'ours : Basic Edn::Vector (template)
|
||||
* @author Edouard DUPIN
|
||||
* @date 07/04/2011
|
||||
* @par Project
|
||||
@ -26,7 +26,7 @@
|
||||
#define __EDN_EdnVector_H__
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "EdnEdnVector"
|
||||
#define __class__ "Edn::Vector"
|
||||
|
||||
/**
|
||||
* @brief EdnVector classes ...
|
||||
@ -62,7 +62,10 @@
|
||||
* ----------
|
||||
*
|
||||
*/
|
||||
template<class T, int32_t INC=0> class EdnVector:
|
||||
namespace Edn
|
||||
{
|
||||
|
||||
template<class T, int32_t INC=0> class Vector:
|
||||
{
|
||||
public:
|
||||
class Iterator:
|
||||
@ -70,24 +73,24 @@ template<class T, int32_t INC=0> class EdnVector:
|
||||
// Private data :
|
||||
private:
|
||||
int32_t m_current; // curent Id on the vector
|
||||
EdnVector<T> * m_EdnVector; // Pointer on the curent element of the vector
|
||||
Edn::Vector<T> * m_Vector; // Pointer on the curent element of the vector
|
||||
public:
|
||||
/**
|
||||
* @brief Basic itarator constructor with no link with an EdnVector
|
||||
* @brief Basic itarator constructor with no link with an Vector
|
||||
*/
|
||||
Iterator():
|
||||
m_current(-1),
|
||||
m_EdnVector(NULL)
|
||||
m_Vector(NULL)
|
||||
{
|
||||
// nothing to do ...
|
||||
}
|
||||
/**
|
||||
* @brief Recopy constructor on a specific EdnVector.
|
||||
* @brief Recopy constructor on a specific Vector.
|
||||
* @param[in] otherIterator The Iterator that might be copy
|
||||
*/
|
||||
Iterator(const Iterator & otherIterator):
|
||||
m_current(otherIterator.m_current),
|
||||
m_EdnVector(otherIterator.m_EdnVector)
|
||||
m_Vector(otherIterator.m_Vector)
|
||||
{
|
||||
// nothing to do ...
|
||||
}
|
||||
@ -99,7 +102,7 @@ template<class T, int32_t INC=0> class EdnVector:
|
||||
Iterator& operator=(const Iterator & otherIterator)
|
||||
{
|
||||
m_current = otherIterator.m_current;
|
||||
m_EdnVector = otherIterator.m_EdnVector;
|
||||
m_Vector = otherIterator.m_Vector;
|
||||
return *this;
|
||||
}
|
||||
/**
|
||||
@ -108,11 +111,11 @@ template<class T, int32_t INC=0> class EdnVector:
|
||||
~Iterator()
|
||||
{
|
||||
m_current = -1;
|
||||
m_EdnVector = NULL;
|
||||
m_Vector = NULL;
|
||||
}
|
||||
/**
|
||||
* @brief basic boolean cast
|
||||
* @return true if the element is present in the EdnVector size
|
||||
* @return true if the element is present in the Vector size
|
||||
*/
|
||||
operator bool ()
|
||||
{
|
||||
@ -493,5 +496,11 @@ private:
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#undef __class__
|
||||
#define __class__ NULL
|
||||
|
||||
#endif
|
||||
|
@ -644,3 +644,4 @@ template<typename MY_TYPE=int32_t> class VectorType
|
||||
#define __class__ NULL
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user