00001 // Copyright (C) 2005 Dave Griffiths 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 00017 #include <vector> 00018 #include <map> 00019 #include <iostream> 00020 00021 #ifndef N_TREE 00022 #define N_TREE 00023 00024 using namespace std; 00025 00026 namespace Fluxus 00027 { 00028 00031 class Node 00032 { 00033 public: 00034 Node() : Parent(NULL) {} 00035 virtual ~Node() {} 00036 00037 void RemoveChild(int ID); 00038 00039 Node *Parent; 00040 vector<Node*> Children; 00041 int ID; 00042 }; 00043 00048 class Tree 00049 { 00050 public: 00051 Tree(); 00052 virtual ~Tree(); 00053 00055 virtual int AddNode(int ParentID, Node *); 00056 00058 virtual Node *FindNode(int ID) const; 00059 00061 virtual void RemoveNode(Node *node); 00062 00064 virtual void Clear() { if (m_Root) RemoveNode(m_Root); m_Root=NULL; m_CurrentID=1; } 00065 00067 virtual void Dump(int Depth=0,Node *node=NULL) const; 00068 00070 bool IsDecendedFrom(Node *Parent, Node *Child) const; 00071 00072 protected: 00073 void RemoveNodeWalk(Node *node); 00074 00075 map<int,Node*> m_NodeMap; 00076 Node *m_Root; 00077 int m_CurrentID; 00078 }; 00079 00080 } 00081 00082 #endif