00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 */ 00004 00005 #ifndef __FS_TREE_H_ 00006 #define __FS_TREE_H_ 00007 00008 #include "list.h" 00009 00010 namespace fs 00011 { 00012 00013 template <class T> 00014 class ListTree 00015 { 00016 public: 00017 ListTree <T>* GetRoot () { return root; } 00018 void SetRoot (ListTree <T>* r) { root = r; }; 00019 00020 void SetData (const T& d) { data = d; } 00021 T& GetData () { return data; } 00022 00023 ListTree <T>* AddLeaf (const T& data) 00024 { 00025 ListTree <T> *item = new ListTree <T>; 00026 item->SetData (data); 00027 item->SetRoot (this); 00028 leafs.add (item); 00029 return item; 00030 } 00031 00032 int GetLeafCount () { return leafs.size (); } 00033 ListTree <T>* GetLeaf (int iIndex) { return leafs [iIndex]; } 00034 void DeleteLeaf (int iIndex) { leafs.del (iIndex); } 00035 00036 int GetDepth () 00037 { 00038 return root ? root->GetDepth () + 1 : 0; 00039 } 00040 00041 void Clear () 00042 { 00043 for (int i = 0; i < leafs.size (); i++) 00044 delete leafs [i]; 00045 leafs.clear (); 00046 } 00047 00048 ListTree () {root = NULL;} 00049 ~ListTree () { for (int i = 0; i < leafs.size (); i++) delete leafs [i]; leafs.clear (); } 00050 protected: 00051 ListTree <T> *root; 00052 list <ListTree*> leafs; 00053 T data; 00054 }; 00055 00056 }; 00057 00058 #endif
1.5.6