166 lines
3.7 KiB
C++
166 lines
3.7 KiB
C++
//this file is adapted from CPA's CPALST.HPP
|
|
|
|
// (c) Ubi Studios 1996
|
|
// See Vincent Greco for any comment or question
|
|
|
|
#ifndef __SNDLST_HPP__
|
|
#define __SNDLST_HPP__
|
|
|
|
#include "afxtempl.h"
|
|
|
|
template<class TYPE>
|
|
class SNDLST2_List : public CList<TYPE*, TYPE*>
|
|
{
|
|
public:
|
|
SNDLST2_List(){}
|
|
~SNDLST2_List(){}
|
|
|
|
|
|
|
|
// TYPE* FindElementFromPos (POSITION& rPosition) const;
|
|
TYPE* FindElementFromIndex(int nIndex) const;//nIndex is int (not tIndex) because of MFC compatibility...
|
|
|
|
|
|
//Position based Iteration
|
|
|
|
TYPE* GetAtElement (POSITION& rPosition) const;
|
|
TYPE* GetHeadElement (POSITION& rPosition) const;
|
|
TYPE* GetTailElement (POSITION& rPosition) const;
|
|
TYPE* GetNextElement (POSITION& rPosition) const;
|
|
TYPE* GetPrevElement (POSITION& rPosition) const;
|
|
BOOL AvailableElement(POSITION& rPosition) const;
|
|
|
|
//Element based Iteration
|
|
|
|
TYPE* GetHeadElement (void) const;
|
|
TYPE* GetTailElement (void) const;
|
|
TYPE* GetNextElement (TYPE* pElement) const;
|
|
TYPE* GetPrevElement (TYPE* pElement) const;
|
|
BOOL AvailableElement(TYPE* pElement) const;
|
|
};
|
|
|
|
//inline functions
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetAtElement(POSITION& rPosition) const
|
|
{
|
|
return rPosition!=NULL ? GetAt(rPosition) : NULL;
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::FindElementFromIndex(int nIndex) const
|
|
{
|
|
POSITION Position=FindIndex(nIndex);
|
|
return GetAtElement(Position);
|
|
}
|
|
|
|
|
|
//Position based Iteration
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetHeadElement(POSITION& rPosition) const
|
|
{
|
|
rPosition = GetHeadPosition();
|
|
return GetAtElement(rPosition);
|
|
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetTailElement(POSITION& rPosition) const
|
|
{
|
|
rPosition = GetTailPosition();
|
|
return GetAtElement(rPosition);
|
|
}
|
|
|
|
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetNextElement(POSITION& rPosition) const
|
|
{
|
|
if(rPosition)
|
|
{
|
|
GetNext(rPosition);
|
|
return GetAtElement(rPosition);
|
|
}
|
|
else
|
|
return GetHeadElement(rPosition);
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetPrevElement(POSITION& rPosition) const
|
|
{
|
|
if(rPosition)
|
|
{
|
|
GetPrev(rPosition);
|
|
return GetAtElement(rPosition);
|
|
}
|
|
else
|
|
return GetTailElement(rPosition);
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline BOOL SNDLST2_List<TYPE>::AvailableElement(POSITION& rPosition) const
|
|
{
|
|
return (rPosition != NULL);
|
|
}
|
|
|
|
|
|
//Element based Iteration
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetHeadElement(void) const
|
|
{
|
|
POSITION Position;
|
|
return GetHeadElement(Position);
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetTailElement(void) const
|
|
{
|
|
POSITION Position;
|
|
return GetTailElement(Position);
|
|
}
|
|
|
|
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetNextElement(TYPE* pElement) const
|
|
{
|
|
POSITION Position=NULL;
|
|
if(!pElement) return GetNextElement(Position);//return head
|
|
Position=Find(pElement);
|
|
return Position?GetNextElement(Position):NULL;//if not found return NULL
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline TYPE* SNDLST2_List<TYPE>::GetPrevElement(TYPE* pElement) const
|
|
{
|
|
POSITION Position=NULL;
|
|
if(!pElement) return GetPrevElement(Position);//return tail
|
|
Position=Find(pElement);
|
|
return Position?GetPrevElement(Position):NULL;//if not found return NULL
|
|
}
|
|
|
|
template<class TYPE>
|
|
inline BOOL SNDLST2_List<TYPE>::AvailableElement(TYPE* pElement) const
|
|
{
|
|
return (pElement != NULL);
|
|
}
|
|
|
|
|
|
#define M_ForAllTheElementsInList(pElement, pListe, Position) \
|
|
for \
|
|
( \
|
|
pElement=(pListe)->GetHeadElement(Position); \
|
|
(pListe)->AvailableElement(Position); \
|
|
pElement=(pListe)->GetNextElement(Position) \
|
|
)
|
|
|
|
|
|
#endif//__CPALST_HPP__
|
|
|
|
|
|
|
|
|
|
|