From e3e868f351754ae64706de874ba2b39a80f734ce Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 29 Jul 2011 17:07:46 +0200 Subject: [PATCH] =?UTF-8?q?debut=20de=20d=C3=A9placement=20du=20vecteur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/tools/EdnTemplate/EdnTemplateTest.cpp | 29 --- Sources/tools/EdnTemplate/EdnTree.h | 186 ------------------ Sources/tools/NameSpaceEdn/Edn.h | 1 + .../EdnVector.h => NameSpaceEdn/Vector.h} | 35 ++-- Sources/tools/NameSpaceEdn/VectorType.h | 1 + 5 files changed, 24 insertions(+), 228 deletions(-) delete mode 100644 Sources/tools/EdnTemplate/EdnTemplateTest.cpp delete mode 100644 Sources/tools/EdnTemplate/EdnTree.h rename Sources/tools/{EdnTemplate/EdnVector.h => NameSpaceEdn/Vector.h} (93%) diff --git a/Sources/tools/EdnTemplate/EdnTemplateTest.cpp b/Sources/tools/EdnTemplate/EdnTemplateTest.cpp deleted file mode 100644 index b91bb93..0000000 --- a/Sources/tools/EdnTemplate/EdnTemplateTest.cpp +++ /dev/null @@ -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 plop; - Edn::VectorType 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]); - -} diff --git a/Sources/tools/EdnTemplate/EdnTree.h b/Sources/tools/EdnTemplate/EdnTree.h deleted file mode 100644 index c03d698..0000000 --- a/Sources/tools/EdnTemplate/EdnTree.h +++ /dev/null @@ -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 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 GetListSubNode( int32_t parentId = ROOT_NODE_ID) - { - std::vector 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 Root(void) - { - return GetListSubNode(ROOT_NODE_ID); - }; - - - private: - int32_t m_LastId; - std::vector< EdnTreeElement > 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 - diff --git a/Sources/tools/NameSpaceEdn/Edn.h b/Sources/tools/NameSpaceEdn/Edn.h index e5882f3..44630c5 100644 --- a/Sources/tools/NameSpaceEdn/Edn.h +++ b/Sources/tools/NameSpaceEdn/Edn.h @@ -26,6 +26,7 @@ #include "tools_debug.h" #include "toolsMemory.h" +#include "Vector.h" #include "VectorType.h" diff --git a/Sources/tools/EdnTemplate/EdnVector.h b/Sources/tools/NameSpaceEdn/Vector.h similarity index 93% rename from Sources/tools/EdnTemplate/EdnVector.h rename to Sources/tools/NameSpaceEdn/Vector.h index 24a5e6c..0673c6c 100644 --- a/Sources/tools/EdnTemplate/EdnVector.h +++ b/Sources/tools/NameSpaceEdn/Vector.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 EdnVector: +namespace Edn +{ + +template class Vector: { public: class Iterator: @@ -70,24 +73,24 @@ template class EdnVector: // Private data : private: int32_t m_current; // curent Id on the vector - EdnVector * m_EdnVector; // Pointer on the curent element of the vector + Edn::Vector * 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 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 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 \ No newline at end of file +#define __class__ NULL + +#endif + diff --git a/Sources/tools/NameSpaceEdn/VectorType.h b/Sources/tools/NameSpaceEdn/VectorType.h index 75f0f8a..c09a760 100644 --- a/Sources/tools/NameSpaceEdn/VectorType.h +++ b/Sources/tools/NameSpaceEdn/VectorType.h @@ -644,3 +644,4 @@ template class VectorType #define __class__ NULL #endif +