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