137 lines
2.5 KiB
C++
137 lines
2.5 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// 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 T> class TTable;
|
|
template<class T> class TTree;
|
|
template<class T> class TForest : public TPDList< TTree<T> >
|
|
{
|
|
public:
|
|
TForest();
|
|
TForest(const TForest<T>& forest);
|
|
virtual ~TForest();
|
|
virtual TTree<T>* FetchCur();
|
|
|
|
//深拷贝
|
|
TForest<T>& operator=(const TForest<T>&forest);
|
|
//一般仅被TTree<T>内部调用
|
|
void SetParent(TTree<T>*pTree);
|
|
|
|
TTree<T>* GetCurTree();
|
|
|
|
long GetTreeNum() const;
|
|
long GetLeafNum();
|
|
void GetLeafNodes(TTable<TTree<T>*>& leafs);
|
|
long FindTreeNode(const T&t, TTable<TTree<T>* >&trees);
|
|
};
|
|
|
|
|
|
template<class T>
|
|
TForest<T>::TForest()
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
TForest<T>::TForest(const TForest<T>& forest)
|
|
{
|
|
*this=forest;
|
|
}
|
|
|
|
template<class T>
|
|
TForest<T>::~TForest()
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
long TForest<T>::GetTreeNum()const
|
|
{
|
|
return this->GetLength();
|
|
}
|
|
|
|
template<class T>
|
|
TTree<T>* TForest<T>::GetCurTree()
|
|
{
|
|
return this->GetCurData();
|
|
}
|
|
|
|
template<class T>
|
|
TTree<T>* TForest<T>::FetchCur()
|
|
{
|
|
TTree<T>*p = TPDList<TTree<T>>::FetchCur();
|
|
if(p!=NULL)
|
|
{
|
|
p->Parent()=NULL;
|
|
}
|
|
return p;
|
|
}
|
|
|
|
template<class T>
|
|
void TForest<T>::GetLeafNodes(TTable<TTree<T>*>&leafs)
|
|
{
|
|
for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext())
|
|
{
|
|
GetCurTree()->GetLeafNodes(leafs);
|
|
}
|
|
}
|
|
|
|
template<class T>
|
|
long TForest<T>::GetLeafNum()
|
|
{
|
|
long res=0;
|
|
for(this->MoveToFirst();!this->IsOut();this->MoveToNext())
|
|
{
|
|
res += GetCurTree()->GetLeafNum();
|
|
}
|
|
return res;
|
|
}
|
|
|
|
template<class T>
|
|
long TForest<T>::FindTreeNode(const T&t,TTable<TTree<T>* >&trees)
|
|
{
|
|
for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext())
|
|
{
|
|
GetCurTree()->FindTreeNode(t,trees);
|
|
}
|
|
return trees.GetLength();
|
|
}
|
|
|
|
template<class T>
|
|
void TForest<T>::SetParent(TTree<T>*pTree)
|
|
{
|
|
for(this->MoveToFirst(); !this->IsOut(); this->MoveToNext())
|
|
{
|
|
GetCurTree()->Parent() = pTree;
|
|
}
|
|
}
|
|
|
|
template<class T>
|
|
TForest<T>& TForest<T>::operator =(const TForest<T>&forest)
|
|
{
|
|
this->Clear();
|
|
for(TTree<T>*const*pCur = forest.GetFirst(); pCur!=NULL; pCur = forest.GetNext(pCur))
|
|
{
|
|
this->AddTail(new TTree<T>(**pCur));
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
#endif |