* Put implementation in class declaration of template class ListNode<T> for increased locality and readability

* Enable compilation of RTTI (RunTime Type-Information) compilation (not using any of it, .., yet)

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2231 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2007-07-27 21:11:57 +00:00
parent 0e4c52b890
commit 8010de593a
2 changed files with 151 additions and 204 deletions

View File

@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Intermediate_Dir ".\Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "NDEBUG"
@ -67,7 +67,7 @@ LINK32=link.exe
# PROP Intermediate_Dir ".\Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR /YX /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x809 /d "_DEBUG"

View File

@ -26,208 +26,155 @@
#define __INCLUDED_LISTTEMP__
template<class T>
class ListNode {
protected:
ListNode<T> *PrevNode;
ListNode<T> *NextNode;
T *Data;
public:
ListNode();
~ListNode();
T* GetData(void) { return Data; }
void AppendNode(ListNode<T>* RootNode);
void InsertAfterNode(ListNode<T>* Node);
void InsertBeforeNode(ListNode<T>* Node);
ListNode<T>* GetNextNode(void);
ListNode<T>* GetPrevNode(void);
ListNode<T>* GetFirstNode(void);
ListNode<T>* GetLastNode(void);
ListNode<T>* GetNthNode(int NodeNum);
ListNode<T>* RemoveNode(ListNode<T>* RootNode);
void DeleteList(void);
int CountNodes(void);
class ListNode
{
public:
ListNode() :
PrevNode(NULL),
NextNode(NULL),
Data(new T)
{
}
~ListNode()
{
// DebugPrint("DeleteNode\n");
delete Data;
}
T* GetData()
{
return Data;
}
void AppendNode(ListNode<T>* RootNode)
{
ListNode<T>* TmpNode = RootNode->GetLastNode(); // Find the end of the list.
TmpNode->NextNode = this; // Append the new node to the list.
PrevNode = TmpNode;
NextNode = NULL;
}
void InsertAfterNode(ListNode<T>* Node)
{
PrevNode = Node;
NextNode = Node->NextNode;
Node->NextNode = this;
if(NextNode != NULL)
NextNode->PrevNode = this;
}
void InsertBeforeNode(ListNode<T>* Node)
{
PrevNode = Node->PrevNode;
Node->PrevNode = this;
NextNode = Node;
if(PrevNode != NULL)
PrevNode->NextNode = this;
}
ListNode<T>* GetNextNode()
{
return NextNode;
}
ListNode<T>* GetPrevNode()
{
return PrevNode;
}
ListNode<T>* GetFirstNode()
{
ListNode* TmpNode = this; // Get address of this node.
while(TmpNode->PrevNode != NULL) // Find the start of the list.
{
TmpNode = TmpNode->PrevNode;
}
return TmpNode;
}
ListNode<T>* GetLastNode()
{
ListNode<T>* TmpNode = this; // Get address of this node.
while(TmpNode->NextNode != NULL) // Find the end of the list.
{
TmpNode = TmpNode->NextNode;
}
return TmpNode;
}
ListNode<T>* GetNthNode(size_t NodeNum)
{
ListNode<T>* TmpNode = GetFirstNode(); // Find the start of the list.
while (TmpNode != NULL)
{
if(NodeNum == 0)
return TmpNode;
TmpNode = TmpNode->NextNode;
--NodeNum;
}
return NULL;
}
ListNode<T>* RemoveNode(ListNode<T>* RootNode)
{
// DebugPrint("* Removing node @ %p\n",this);
if(this == RootNode)
{
RootNode = RootNode->GetNextNode();
// DebugPrint("* Root changed %p\n",RootNode);
}
if(PrevNode != NULL)
PrevNode->NextNode = NextNode;
if(NextNode != NULL)
NextNode->PrevNode = PrevNode;
return RootNode;
}
void DeleteList()
{
ListNode<T>* TmpNode = GetFirstNode(); // Find the start of the list.
ListNode<T>* TmpNode2;
while(TmpNode != NULL) // Delete all items in the list.
{
TmpNode2 = TmpNode;
TmpNode = TmpNode->NextNode;
delete TmpNode2;
}
}
size_t CountNodes()
{
ListNode<T>* TmpNode = GetFirstNode(); // Find the start of the list.
size_t count = 0;
// Walk to the end of the list and count all encountered nodes
while(TmpNode != NULL)
{
TmpNode = TmpNode->NextNode;
++count;
}
return count;
}
protected:
ListNode<T>* PrevNode;
ListNode<T>* NextNode;
T* Data;
};
template<class T>
ListNode<T>::ListNode()
{
PrevNode=NULL;
NextNode=NULL;
Data=new T;
}
template<class T>
ListNode<T>::~ListNode()
{
// DebugPrint("DeleteNode\n");
delete Data;
}
template<class T>
void ListNode<T>::DeleteList(void)
{
ListNode<T>* TmpNode;
TmpNode=this; // Get address of this node.
while(TmpNode->PrevNode!=NULL) { // Find the start of the list.
TmpNode=TmpNode->PrevNode;
}
ListNode<T>* TmpNode2;
while(TmpNode!=NULL) { // Delete all items in the list.
TmpNode2=TmpNode;
TmpNode=TmpNode->NextNode;
delete TmpNode2;
}
}
template<class T>
ListNode<T>* ListNode<T>::RemoveNode(ListNode<T>* RootNode)
{
// DebugPrint("* Removing node @ %p\n",this);
if(this==RootNode) {
RootNode=RootNode->GetNextNode();
// DebugPrint("* Root changed %p\n",RootNode);
}
if(PrevNode!=NULL) {
PrevNode->NextNode=NextNode;
}
if(NextNode!=NULL) {
NextNode->PrevNode=PrevNode;
}
return RootNode;
}
template<class T>
void ListNode<T>::AppendNode(ListNode<T>* RootNode)
{
ListNode<T>* TmpNode;
TmpNode=RootNode;
while(TmpNode->NextNode!=NULL) { // Find the end of the list.
TmpNode=TmpNode->NextNode;
}
TmpNode->NextNode=this; // Append the new node to the list.
PrevNode=TmpNode;
NextNode=NULL;
}
template<class T>
void ListNode<T>::InsertAfterNode(ListNode<T>* Node)
{
PrevNode=Node;
NextNode=Node->NextNode;
Node->NextNode=this;
if(NextNode!=NULL) {
NextNode->PrevNode=this;
}
}
template<class T>
void ListNode<T>::InsertBeforeNode(ListNode<T>* Node)
{
PrevNode=Node->PrevNode;
Node->PrevNode=this;
NextNode=Node;
if(PrevNode!=NULL) {
PrevNode->NextNode=this;
}
}
template<class T>
ListNode<T>* ListNode<T>::GetNextNode(void)
{
return(NextNode);
}
template<class T>
ListNode<T>* ListNode<T>::GetPrevNode(void)
{
return(PrevNode);
}
template<class T>
ListNode<T>* ListNode<T>::GetFirstNode(void)
{
ListNode *TmpNode;
TmpNode=this; // Get address of this node.
while(TmpNode->PrevNode!=NULL) { // Find the start of the list.
TmpNode=TmpNode->PrevNode;
}
return(TmpNode);
}
template<class T>
ListNode<T>* ListNode<T>::GetLastNode(void)
{
ListNode<T>* TmpNode;
TmpNode=this; // Get address of this node.
while(TmpNode->NextNode!=NULL) { // Find the end of the list.
TmpNode=TmpNode->NextNode;
}
return(TmpNode);
}
template<class T>
ListNode<T>* ListNode<T>::GetNthNode(int NodeNum)
{
ListNode<T>* TmpNode;
TmpNode=this; // Get address of this node.
while(TmpNode->PrevNode!=NULL) { // Find the start of the list.
TmpNode=TmpNode->PrevNode;
}
while(TmpNode!=NULL) {
if(NodeNum==0) {
return(TmpNode);
}
TmpNode=TmpNode->NextNode;
NodeNum--;
}
return(NULL);
}
template<class T>
int ListNode<T>::CountNodes(void)
{
int count;
ListNode<T>* TmpNode;
TmpNode=this; // Get address of this node.
while(TmpNode->PrevNode!=NULL) { // Find the start of the list.
TmpNode=TmpNode->PrevNode;
}
count=0;
while(TmpNode!=NULL) { // Find the end of the list.
TmpNode=TmpNode->NextNode;
count++;
}
return(count);
}
#endif