deprecated old iterators
This commit is contained in:
@@ -34,11 +34,11 @@
|
||||
#define tsDLListH_include
|
||||
|
||||
template <class T> class tsDLList;
|
||||
template <class T> class tsDLIter;
|
||||
template <class T> class tsDLFwdIter;
|
||||
template <class T> class tsDLBwdIter;
|
||||
template <class T> class tsDLIterConstBD;
|
||||
template <class T> class tsDLIterBD;
|
||||
template <class T> class tsDLIter; // deprecated
|
||||
template <class T> class tsDLFwdIter; // deprecated
|
||||
template <class T> class tsDLBwdIter; // deprecated
|
||||
|
||||
//
|
||||
// class tsDLNode<T>
|
||||
@@ -53,11 +53,11 @@ template <class T> class tsDLIterBD;
|
||||
template <class T>
|
||||
class tsDLNode {
|
||||
friend class tsDLList<T>;
|
||||
friend class tsDLIter<T>;
|
||||
friend class tsDLFwdIter<T>;
|
||||
friend class tsDLBwdIter<T>;
|
||||
friend class tsDLIterConstBD<T>;
|
||||
friend class tsDLIterBD<T>;
|
||||
friend class tsDLIterConstBD<T>;
|
||||
friend class tsDLIter<T>; // deprecated
|
||||
friend class tsDLFwdIter<T>; // deprecated
|
||||
friend class tsDLBwdIter<T>; // deprecated
|
||||
public:
|
||||
tsDLNode();
|
||||
void operator = (const tsDLNode<T> &) const;
|
||||
@@ -159,7 +159,6 @@ public:
|
||||
|
||||
const T & operator * () const;
|
||||
const T * operator -> () const;
|
||||
//operator const T * () const;
|
||||
|
||||
tsDLIterConstBD<T> operator ++ (); // prefix ++
|
||||
tsDLIterConstBD<T> operator ++ (int); // postfix ++
|
||||
@@ -204,33 +203,14 @@ public:
|
||||
|
||||
T & operator * () const;
|
||||
T * operator -> () const;
|
||||
//operator T* () const;
|
||||
|
||||
tsDLIterBD<T> operator ++ () // prefix ++
|
||||
{
|
||||
this->tsDLIterConstBD<T>::operator ++ ();
|
||||
return *this;
|
||||
}
|
||||
tsDLIterBD<T> operator ++ (); // prefix ++
|
||||
|
||||
tsDLIterBD<T> operator ++ (int) // postfix ++
|
||||
{
|
||||
tsDLIterBD<T> tmp = *this;
|
||||
this->tsDLIterConstBD<T>::operator ++ (1);
|
||||
return tmp;
|
||||
}
|
||||
tsDLIterBD<T> operator ++ (int); // postfix ++
|
||||
|
||||
tsDLIterBD<T> operator -- () // prefix --
|
||||
{
|
||||
this->tsDLIterConstBD<T>::operator -- ();
|
||||
return *this;
|
||||
}
|
||||
tsDLIterBD<T> operator -- (); // prefix --
|
||||
|
||||
tsDLIterBD<T> operator -- (int) // postfix --
|
||||
{
|
||||
tsDLIterBD<T> tmp = *this;
|
||||
this->tsDLIterConstBD<T>::operator -- (1);
|
||||
return tmp;
|
||||
}
|
||||
tsDLIterBD<T> operator -- (int); // postfix --
|
||||
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1200
|
||||
tsDLIterBD (const class tsDLIterBD<T> ©In);
|
||||
@@ -244,121 +224,6 @@ public:
|
||||
static const tsDLIterBD<T> eol ();
|
||||
};
|
||||
|
||||
//
|
||||
// tsDLIter<T>
|
||||
//
|
||||
// doubly linked list iterator
|
||||
//
|
||||
// Notes:
|
||||
// 1)
|
||||
// This iterator does not allow for removal
|
||||
// of an item in order to avoid problems
|
||||
// resulting when we remove an item (and
|
||||
// then dont know whether to make pCurrent
|
||||
// point at the item before or after the
|
||||
// item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLIter {
|
||||
public:
|
||||
tsDLIter (tsDLList<T> & listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * next ();
|
||||
T * prev ();
|
||||
T * first();
|
||||
T * last();
|
||||
T * operator () ();
|
||||
|
||||
protected:
|
||||
T *pCurrent;
|
||||
tsDLList<T> *pList;
|
||||
|
||||
T * current (); // certain compilers require this
|
||||
};
|
||||
|
||||
//
|
||||
// class tsDLFwdIter<T>
|
||||
//
|
||||
// Notes:
|
||||
// 1) No direct access to pCurrent is provided since
|
||||
// this might allow for confusion when an item
|
||||
// is removed (and pCurrent ends up pointing at
|
||||
// an item that has been seen before)
|
||||
//
|
||||
// 2) This iterator only moves forward in order to
|
||||
// avoid problems resulting when we remove an
|
||||
// item (and then dont know whether to make
|
||||
// pCurrent point at the item before or after
|
||||
// the item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLFwdIter: private tsDLIter<T> {
|
||||
public:
|
||||
tsDLFwdIter (tsDLList<T> &listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * operator () ();
|
||||
T * next ();
|
||||
T * first();
|
||||
|
||||
//
|
||||
// remove ()
|
||||
// (and move current to be the item
|
||||
// pointed to by pPrev - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
void remove ();
|
||||
protected:
|
||||
T *current ();
|
||||
};
|
||||
|
||||
//
|
||||
// tsDLBwdIter<T>
|
||||
//
|
||||
// Notes:
|
||||
// 1) No direct access to pCurrent is provided since
|
||||
// this might allow for confusion when an item
|
||||
// is removed (and pCurrent ends up pointing at
|
||||
// an item that has been seen before)
|
||||
//
|
||||
// 2) This iterator only moves backward in order to
|
||||
// avoid problems resulting when we remove an
|
||||
// item (and then dont know whether to make
|
||||
// pCurrent point at the item before or after
|
||||
// the item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLBwdIter : private tsDLIter<T> {
|
||||
public:
|
||||
tsDLBwdIter (tsDLList<T> &listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * operator () () { return this->tsDLIter<T>::prev(); }
|
||||
T * prev ();
|
||||
T * last();
|
||||
//
|
||||
// remove ()
|
||||
// remove current item
|
||||
// (and move current to be the item
|
||||
// pointed to by pNext - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
void remove ();
|
||||
protected:
|
||||
T * current ();
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// tsDLNode<T> member functions
|
||||
///////////////////////////////////
|
||||
@@ -447,7 +312,7 @@ inline void tsDLList<T>::clear ()
|
||||
// tsDLList<T>::remove ()
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::remove (T &item)
|
||||
inline void tsDLList<T>::remove (T &item)
|
||||
{
|
||||
tsDLNode<T> &theNode = item;
|
||||
|
||||
@@ -502,16 +367,16 @@ inline T * tsDLList<T>::pop()
|
||||
// (and removes all items from addList)
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::add (tsDLList<T> &addList)
|
||||
inline void tsDLList<T>::add (tsDLList<T> &addList)
|
||||
{
|
||||
//
|
||||
// NOOP if addList is empty
|
||||
//
|
||||
if (addList.itemCount==0u) {
|
||||
if ( addList.itemCount == 0u ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->itemCount==0u) {
|
||||
if ( this->itemCount == 0u ) {
|
||||
//
|
||||
// this is empty so just init from
|
||||
// addList
|
||||
@@ -543,7 +408,7 @@ void tsDLList<T>::add (tsDLList<T> &addList)
|
||||
// add an item to the end of the list
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::add (T &item)
|
||||
inline void tsDLList<T>::add (T &item)
|
||||
{
|
||||
tsDLNode<T> &theNode = item;
|
||||
|
||||
@@ -569,7 +434,7 @@ void tsDLList<T>::add (T &item)
|
||||
// place item in the list immediately after itemBefore
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::insertAfter (T &item, T &itemBefore)
|
||||
inline void tsDLList<T>::insertAfter (T &item, T &itemBefore)
|
||||
{
|
||||
tsDLNode<T> &nodeItem = item;
|
||||
tsDLNode<T> &nodeBefore = itemBefore;
|
||||
@@ -595,7 +460,7 @@ void tsDLList<T>::insertAfter (T &item, T &itemBefore)
|
||||
// place item in the list immediately before itemAfter
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::insertBefore (T &item, T &itemAfter)
|
||||
inline void tsDLList<T>::insertBefore (T &item, T &itemAfter)
|
||||
{
|
||||
tsDLNode<T> &node = item;
|
||||
tsDLNode<T> &nodeAfter = itemAfter;
|
||||
@@ -621,7 +486,7 @@ void tsDLList<T>::insertBefore (T &item, T &itemAfter)
|
||||
// add an item at the beginning of the list
|
||||
//
|
||||
template <class T>
|
||||
void tsDLList<T>::push (T &item)
|
||||
inline void tsDLList<T>::push (T &item)
|
||||
{
|
||||
tsDLNode<T> &theNode = item;
|
||||
theNode.pPrev = 0;
|
||||
@@ -678,7 +543,7 @@ inline tsDLIterConstBD<T>::tsDLIterConstBD (const T * pInitialEntry) :
|
||||
//
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1200
|
||||
template <class T>
|
||||
tsDLIterConstBD<T>::tsDLIterConstBD (const class tsDLIterBD<T> ©In) :
|
||||
inline tsDLIterConstBD<T>::tsDLIterConstBD (const class tsDLIterBD<T> ©In) :
|
||||
pConstEntry (copyIn.pEntry) {}
|
||||
# endif
|
||||
|
||||
@@ -713,13 +578,6 @@ inline const T * tsDLIterConstBD<T>::operator -> () const
|
||||
return this->pConstEntry;
|
||||
}
|
||||
|
||||
//template <class T>
|
||||
//inline tsDLIterConstBD<T>::operator const T * () const
|
||||
//{
|
||||
//return this->pConstEntry;
|
||||
//return 0;
|
||||
//}
|
||||
|
||||
template <class T>
|
||||
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::itemAfter ()
|
||||
{
|
||||
@@ -812,7 +670,7 @@ inline tsDLIterBD<T>::tsDLIterBD (T * pInitialEntry) :
|
||||
//
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1200
|
||||
template <class T>
|
||||
tsDLIterBD<T>::tsDLIterBD (const class tsDLIterBD<T> ©In) :
|
||||
inline tsDLIterBD<T>::tsDLIterBD (const class tsDLIterBD<T> ©In) :
|
||||
tsDLIterConstBD (copyIn) {}
|
||||
# endif
|
||||
|
||||
@@ -847,12 +705,6 @@ inline T * tsDLIterBD<T>::operator -> () const
|
||||
return this->pEntry;
|
||||
}
|
||||
|
||||
//template <class T>
|
||||
//inline tsDLIterBD<T>::operator T * () const
|
||||
//{
|
||||
// return this->pEntry;
|
||||
//}
|
||||
|
||||
template <class T>
|
||||
inline tsDLIterBD<T> tsDLIterBD<T>::itemAfter ()
|
||||
{
|
||||
@@ -873,267 +725,43 @@ inline bool tsDLIterBD<T>::valid () const
|
||||
return this->pEntry ? true : false;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIterBD<T>::eol
|
||||
//
|
||||
template <class T>
|
||||
inline const tsDLIterBD<T> tsDLIterBD<T>::eol ()
|
||||
{
|
||||
return tsDLIterBD<T>(0);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// tsDLIter<T> member functions
|
||||
//////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLIter<T>::tsDLIter (tsDLList<T> & listIn) :
|
||||
pCurrent(0), pList(&listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::reset ()
|
||||
{
|
||||
this->pCurrent = 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::reset (tsDLList<T> &listIn)
|
||||
{
|
||||
this->reset();
|
||||
this->pList = &listIn;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::operator = (tsDLList<T> &listIn)
|
||||
{
|
||||
this->reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::first()
|
||||
{
|
||||
this->pCurrent = this->pList->pFirst;
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::last()
|
||||
{
|
||||
this->pCurrent = this->pList->pLast;
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::next ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::next ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
if (pCur==0) {
|
||||
pCur = this->pList->pFirst;
|
||||
}
|
||||
else {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
pCur = pCurNode->pNext;
|
||||
}
|
||||
this->pCurrent = pCur;
|
||||
return pCur;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::prev ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::prev ()
|
||||
inline tsDLIterBD<T> tsDLIterBD<T>::operator ++ () // prefix ++
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
if (pCur==0) {
|
||||
pCur = this->pList->pLast;
|
||||
}
|
||||
else {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
pCur = pCurNode->pPrev;
|
||||
}
|
||||
this->pCurrent = pCur;
|
||||
return pCur;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::operator () ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::operator () ()
|
||||
{
|
||||
return this->next();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::current()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::current()
|
||||
{
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// tsDLBwdIter<T> member functions
|
||||
///////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLBwdIter<T>::tsDLBwdIter(tsDLList<T> &listIn) :
|
||||
tsDLIter<T>(listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::reset ()
|
||||
{
|
||||
this->tsDLIter<T>::reset();
|
||||
this->tsDLIterConstBD<T>::operator ++ ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::reset (tsDLList<T> &listIn)
|
||||
inline tsDLIterBD<T> tsDLIterBD<T>::operator ++ (int) // postfix ++
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
tsDLIterBD<T> tmp = *this;
|
||||
this->tsDLIterConstBD<T>::operator ++ (1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::operator = (tsDLList<T> &listIn)
|
||||
inline tsDLIterBD<T> tsDLIterBD<T>::operator -- () // prefix --
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
this->tsDLIterConstBD<T>::operator -- ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLBwdIter<T>::last()
|
||||
inline tsDLIterBD<T> tsDLIterBD<T>::operator -- (int) // postfix --
|
||||
{
|
||||
return this->tsDLIter<T>::last();
|
||||
tsDLIterBD<T> tmp = *this;
|
||||
this->tsDLIterConstBD<T>::operator -- (1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLBwdIter<T>::remove ()
|
||||
//
|
||||
// remove current item
|
||||
// (and move current to be the item
|
||||
// pointed to by pNext - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
template <class T>
|
||||
void tsDLBwdIter<T>::remove ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
|
||||
if (pCur) {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
|
||||
//
|
||||
// strip const (we didnt declare the
|
||||
// list const in the constructor)
|
||||
//
|
||||
tsDLList<T> * pMutableList =
|
||||
(tsDLList<T> *) this->pList;
|
||||
|
||||
//
|
||||
// Move this->pCurrent to the item after the
|
||||
// item being deleted
|
||||
//
|
||||
this->pCurrent = pCurNode->pNext;
|
||||
|
||||
//
|
||||
// delete current item
|
||||
//
|
||||
pMutableList->remove(*pCur);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// tsDLFwdIter<T> member functions
|
||||
//////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLFwdIter<T>::tsDLFwdIter (tsDLList<T> &listIn) :
|
||||
tsDLIter<T>(listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::reset ()
|
||||
{
|
||||
this->tsDLIter<T>::reset();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::reset (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::operator = (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::first()
|
||||
{
|
||||
tsDLIter<T> &iterBase = *this;
|
||||
return iterBase.first();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::current()
|
||||
{
|
||||
return this->tsDLIter<T>::current ();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::remove ()
|
||||
// (and move current to be the item
|
||||
// pointed to by pPrev - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
template <class T>
|
||||
void tsDLFwdIter<T>::remove ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
|
||||
if (pCur) {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
|
||||
//
|
||||
// Move this->pCurrent to the previous item
|
||||
//
|
||||
this->pCurrent = pCurNode->pPrev;
|
||||
|
||||
//
|
||||
// delete current item
|
||||
//
|
||||
this->pList->remove(*pCur);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::next ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::next ()
|
||||
{
|
||||
tsDLIter<T> &iterBase = *this;
|
||||
return iterBase.next();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::operator () ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::operator () ()
|
||||
{
|
||||
return this->next();
|
||||
}
|
||||
#include <tsDLListDeprecated.h>
|
||||
|
||||
#endif // tsDLListH_include
|
||||
|
||||
|
||||
367
src/libCom/cxxTemplates/tsDLListDeprecated.h
Normal file
367
src/libCom/cxxTemplates/tsDLListDeprecated.h
Normal file
@@ -0,0 +1,367 @@
|
||||
|
||||
//
|
||||
// tsDLIter<T>
|
||||
//
|
||||
// doubly linked list iterator
|
||||
//
|
||||
// Notes:
|
||||
// 1)
|
||||
// This iterator does not allow for removal
|
||||
// of an item in order to avoid problems
|
||||
// resulting when we remove an item (and
|
||||
// then dont know whether to make pCurrent
|
||||
// point at the item before or after the
|
||||
// item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLIter {
|
||||
public:
|
||||
tsDLIter (tsDLList<T> & listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * next ();
|
||||
T * prev ();
|
||||
T * first();
|
||||
T * last();
|
||||
T * operator () ();
|
||||
|
||||
protected:
|
||||
T *pCurrent;
|
||||
tsDLList<T> *pList;
|
||||
|
||||
T * current (); // certain compilers require this
|
||||
};
|
||||
|
||||
//
|
||||
// class tsDLFwdIter<T>
|
||||
//
|
||||
// Notes:
|
||||
// 1) No direct access to pCurrent is provided since
|
||||
// this might allow for confusion when an item
|
||||
// is removed (and pCurrent ends up pointing at
|
||||
// an item that has been seen before)
|
||||
//
|
||||
// 2) This iterator only moves forward in order to
|
||||
// avoid problems resulting when we remove an
|
||||
// item (and then dont know whether to make
|
||||
// pCurrent point at the item before or after
|
||||
// the item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLFwdIter: private tsDLIter<T> {
|
||||
public:
|
||||
tsDLFwdIter (tsDLList<T> &listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * operator () ();
|
||||
T * next ();
|
||||
T * first();
|
||||
|
||||
//
|
||||
// remove ()
|
||||
// (and move current to be the item
|
||||
// pointed to by pPrev - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
void remove ();
|
||||
protected:
|
||||
T *current ();
|
||||
};
|
||||
|
||||
//
|
||||
// tsDLBwdIter<T>
|
||||
//
|
||||
// Notes:
|
||||
// 1) No direct access to pCurrent is provided since
|
||||
// this might allow for confusion when an item
|
||||
// is removed (and pCurrent ends up pointing at
|
||||
// an item that has been seen before)
|
||||
//
|
||||
// 2) This iterator only moves backward in order to
|
||||
// avoid problems resulting when we remove an
|
||||
// item (and then dont know whether to make
|
||||
// pCurrent point at the item before or after
|
||||
// the item removed
|
||||
//
|
||||
template <class T>
|
||||
class tsDLBwdIter : private tsDLIter<T> {
|
||||
public:
|
||||
tsDLBwdIter (tsDLList<T> &listIn);
|
||||
void reset ();
|
||||
void reset (tsDLList<T> &listIn);
|
||||
void operator = (tsDLList<T> &listIn);
|
||||
T * operator () () { return this->tsDLIter<T>::prev(); }
|
||||
T * prev ();
|
||||
T * last();
|
||||
//
|
||||
// remove ()
|
||||
// remove current item
|
||||
// (and move current to be the item
|
||||
// pointed to by pNext - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
void remove ();
|
||||
protected:
|
||||
T * current ();
|
||||
};
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::remove ()
|
||||
// (and move current to be the item
|
||||
// pointed to by pPrev - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
template <class T>
|
||||
void tsDLFwdIter<T>::remove ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
|
||||
if (pCur) {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
|
||||
//
|
||||
// Move this->pCurrent to the previous item
|
||||
//
|
||||
this->pCurrent = pCurNode->pPrev;
|
||||
|
||||
//
|
||||
// delete current item
|
||||
//
|
||||
this->pList->remove(*pCur);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::next ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::next ()
|
||||
{
|
||||
tsDLIter<T> &iterBase = *this;
|
||||
return iterBase.next();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLFwdIter<T>::operator () ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::operator () ()
|
||||
{
|
||||
return this->next();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// tsDLIter<T> member functions
|
||||
//////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLIter<T>::tsDLIter (tsDLList<T> & listIn) :
|
||||
pCurrent(0), pList(&listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::reset ()
|
||||
{
|
||||
this->pCurrent = 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::reset (tsDLList<T> &listIn)
|
||||
{
|
||||
this->reset();
|
||||
this->pList = &listIn;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLIter<T>::operator = (tsDLList<T> &listIn)
|
||||
{
|
||||
this->reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::first()
|
||||
{
|
||||
this->pCurrent = this->pList->pFirst;
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::last()
|
||||
{
|
||||
this->pCurrent = this->pList->pLast;
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::next ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::next ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
if (pCur==0) {
|
||||
pCur = this->pList->pFirst;
|
||||
}
|
||||
else {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
pCur = pCurNode->pNext;
|
||||
}
|
||||
this->pCurrent = pCur;
|
||||
return pCur;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::prev ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::prev ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
if (pCur==0) {
|
||||
pCur = this->pList->pLast;
|
||||
}
|
||||
else {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
pCur = pCurNode->pPrev;
|
||||
}
|
||||
this->pCurrent = pCur;
|
||||
return pCur;
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::operator () ()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::operator () ()
|
||||
{
|
||||
return this->next();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLIter<T>::current()
|
||||
//
|
||||
template <class T>
|
||||
inline T * tsDLIter<T>::current()
|
||||
{
|
||||
return this->pCurrent;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// tsDLBwdIter<T> member functions
|
||||
///////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLBwdIter<T>::tsDLBwdIter(tsDLList<T> &listIn) :
|
||||
tsDLIter<T>(listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::reset ()
|
||||
{
|
||||
this->tsDLIter<T>::reset();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::reset (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLBwdIter<T>::operator = (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLBwdIter<T>::last()
|
||||
{
|
||||
return this->tsDLIter<T>::last();
|
||||
}
|
||||
|
||||
//
|
||||
// tsDLBwdIter<T>::remove ()
|
||||
//
|
||||
// remove current item
|
||||
// (and move current to be the item
|
||||
// pointed to by pNext - the item seen
|
||||
// by the iterator before the current one -
|
||||
// this guarantee that the list will be
|
||||
// accessed sequentially even if an item
|
||||
// is removed)
|
||||
//
|
||||
template <class T>
|
||||
void tsDLBwdIter<T>::remove ()
|
||||
{
|
||||
T *pCur = this->pCurrent;
|
||||
|
||||
if (pCur) {
|
||||
tsDLNode<T> *pCurNode = pCur;
|
||||
|
||||
//
|
||||
// strip const (we didnt declare the
|
||||
// list const in the constructor)
|
||||
//
|
||||
tsDLList<T> * pMutableList =
|
||||
(tsDLList<T> *) this->pList;
|
||||
|
||||
//
|
||||
// Move this->pCurrent to the item after the
|
||||
// item being deleted
|
||||
//
|
||||
this->pCurrent = pCurNode->pNext;
|
||||
|
||||
//
|
||||
// delete current item
|
||||
//
|
||||
pMutableList->remove(*pCur);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// tsDLFwdIter<T> member functions
|
||||
//////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
inline tsDLFwdIter<T>::tsDLFwdIter (tsDLList<T> &listIn) :
|
||||
tsDLIter<T>(listIn) {}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::reset ()
|
||||
{
|
||||
this->tsDLIter<T>::reset();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::reset (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void tsDLFwdIter<T>::operator = (tsDLList<T> &listIn)
|
||||
{
|
||||
this->tsDLIter<T>::reset(listIn);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::first()
|
||||
{
|
||||
tsDLIter<T> &iterBase = *this;
|
||||
return iterBase.first();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T * tsDLFwdIter<T>::current()
|
||||
{
|
||||
return this->tsDLIter<T>::current ();
|
||||
}
|
||||
Reference in New Issue
Block a user