//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : Forest.h // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: 类的声明 // = Maintainers: // //-----------------------------------------------------------------------------+ #ifndef _FOREST_H_ #define _FOREST_H_ #ifndef _PDLIST_H_ #include "PDList.h" #endif #ifndef _TREE_H_ #include "Tree.h" #endif template class Table; template class Tree; template class Forest : public PDList< Tree > { public: Forest(); Forest(const Forest& forest); virtual ~Forest(); virtual Tree* FetchCur(); //深拷贝 Forest& operator=(const Forest&forest); //一般仅被Tree内部调用 void SetParent(Tree*pTree); Tree* GetCurTree(); long GetTreeNum() const; long GetLeafNum(); void GetLeafNodes(Table*>& leafs); long FindTreeNode(const T&t, Table* >&trees); }; template Forest::Forest() { } template Forest::Forest(const Forest& forest) { *this=forest; } template Forest::~Forest() { } template long Forest::GetTreeNum()const { return this->GetLength(); } template Tree* Forest::GetCurTree() { return this->GetCurData(); } template Tree* Forest::FetchCur() { Tree*p = PDList>::FetchCur(); if(p!=NULL) { p->Parent()=NULL; } return p; } template void Forest::GetLeafNodes(Table*>&leafs) { for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext()) { GetCurTree()->GetLeafNodes(leafs); } } template long Forest::GetLeafNum() { long res=0; for(this->MoveToFirst();!this->IsOut();this->MoveToNext()) { res += GetCurTree()->GetLeafNum(); } return res; } template long Forest::FindTreeNode(const T&t,Table* >&trees) { for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext()) { GetCurTree()->FindTreeNode(t,trees); } return trees.GetLength(); } template void Forest::SetParent(Tree*pTree) { for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext()) { GetCurTree()->Parent() = pTree; } } template Forest& Forest::operator =(const Forest&forest) { this->Clear(); for(Tree*const*pCur = forest.GetFirst(); pCur!=NULL; pCur = forest.GetNext(pCur)) { AddTail(new Tree(**pCur)); } return *this; } #endif