Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

138 lines
2.5 KiB
C++

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