convert tabs to spaces

This commit is contained in:
Jeff Hill
2000-10-11 19:44:34 +00:00
parent a746ac770d
commit ae0f01b2ff
5 changed files with 542 additions and 545 deletions

View File

@@ -1,7 +1,7 @@
/*
* $Id$
*
* type safe doubly linked list templates
* type safe doubly linked list templates
*
* Author Jeffrey O. Hill
* johill@lanl.gov
@@ -59,14 +59,11 @@ class tsDLNode {
friend class tsDLFwdIter<T>; // deprecated
friend class tsDLBwdIter<T>; // deprecated
public:
tsDLNode();
void operator = (const tsDLNode<T> &) const;
tsDLNode();
void operator = (const tsDLNode<T> &) const;
private:
T *pNext;
T *pPrev;
//protected:
// T *getNext(void) const;
// T *getPrev(void) const;
T *pNext;
T *pPrev;
};
//
@@ -83,60 +80,60 @@ class tsDLList {
friend class tsDLBwdIter<T>;
public:
tsDLList (); // create empty list
tsDLList (); // create empty list
unsigned count () const; // number of items on list
unsigned count () const; // number of items on list
void add (T &item); // add item to end of list
void add (T &item); // add item to end of list
// all Ts in addList added to end of list
// (addList left empty)
void add (tsDLList<T> &addList);
void add (tsDLList<T> &addList);
void push (T &item); // add item to beginning of list
void push (T &item); // add item to beginning of list
// remove item from list
void remove (T &item);
// remove item from list
void remove (T &item);
T * get (); // removes first item on list
T * pop (); // same as get ()
T * get (); // removes first item on list
T * pop (); // same as get ()
// insert item in the list immediately after itemBefore
void insertAfter (T &item, T &itemBefore);
// insert item in the list immediately after itemBefore
void insertAfter (T &item, T &itemBefore);
// insert item in the list immediately before itemAfter)
void insertBefore (T &item, T &itemAfter);
//
// returns -1 if the item isnt on the list and the node
// insert item in the list immediately before itemAfter)
void insertBefore (T &item, T &itemAfter);
//
// returns -1 if the item isnt on the list and the node
// number (beginning with zero if it is)
//
int find (T &item) const;
//
int find (T &item) const;
T *first (void) const; // ptr to first item on list
T *last (void) const; // ptr to last item on list
T *first (void) const; // ptr to first item on list
T *last (void) const; // ptr to last item on list
private:
T *pFirst;
T *pLast;
unsigned itemCount;
T *pFirst;
T *pLast;
unsigned itemCount;
//
// create empty list
//
// create empty list
// (throw away any knowledge of current list)
//
void clear ();
//
void clear ();
//
// copying one list item into another and
// ending up with to list headers pointing
// at the same list is always a questionable
// thing to do.
//
// therefore, this is intentionally private
//
// copying one list item into another and
// ending up with to list headers pointing
// at the same list is always a questionable
// thing to do.
//
// therefore, this is intentionally private
// and _not_ implemented.
//
tsDLList (const tsDLList &);
//
tsDLList (const tsDLList &);
};
//
@@ -147,27 +144,27 @@ private:
template <class T>
class tsDLIterConstBD {
public:
tsDLIterConstBD (const T *pInitialEntry);
tsDLIterConstBD (const T *pInitialEntry);
tsDLIterConstBD<T> operator = (const T *pNewEntry);
tsDLIterConstBD<T> operator = (const T *pNewEntry);
tsDLIterConstBD<T> itemAfter ();
tsDLIterConstBD<T> itemBefore ();
bool operator == (const tsDLIterConstBD<T> &rhs) const;
bool operator != (const tsDLIterConstBD<T> &rhs) const;
bool operator == (const tsDLIterConstBD<T> &rhs) const;
bool operator != (const tsDLIterConstBD<T> &rhs) const;
const T & operator * () const;
const T * operator -> () const;
const T & operator * () const;
const T * operator -> () const;
tsDLIterConstBD<T> operator ++ (); // prefix ++
tsDLIterConstBD<T> operator ++ (int); // postfix ++
tsDLIterConstBD<T> operator -- (); // prefix --
tsDLIterConstBD<T> operator -- (int); // postfix --
tsDLIterConstBD<T> operator ++ (int); // postfix ++
tsDLIterConstBD<T> operator -- (); // prefix --
tsDLIterConstBD<T> operator -- (int); // postfix --
# if defined(_MSC_VER) && _MSC_VER < 1200
tsDLIterConstBD (const class tsDLIterConstBD<T> &copyIn);
# endif
# if defined(_MSC_VER) && _MSC_VER < 1200
tsDLIterConstBD (const class tsDLIterConstBD<T> &copyIn);
# endif
bool valid () const;
@@ -178,8 +175,8 @@ public:
protected:
union {
const T *pConstEntry;
T *pEntry;
const T *pConstEntry;
T *pEntry;
};
};
@@ -191,30 +188,30 @@ protected:
template <class T>
class tsDLIterBD : private tsDLIterConstBD<T> {
public:
tsDLIterBD (T *pInitialEntry);
tsDLIterBD (T *pInitialEntry);
tsDLIterBD<T> operator = (T *pNewEntry);
tsDLIterBD<T> operator = (T *pNewEntry);
tsDLIterBD<T> itemAfter ();
tsDLIterBD<T> itemBefore ();
tsDLIterBD<T> itemAfter ();
tsDLIterBD<T> itemBefore ();
bool operator == (const tsDLIterBD<T> &rhs) const;
bool operator != (const tsDLIterBD<T> &rhs) const;
bool operator == (const tsDLIterBD<T> &rhs) const;
bool operator != (const tsDLIterBD<T> &rhs) const;
T & operator * () const;
T * operator -> () const;
T & operator * () const;
T * operator -> () const;
tsDLIterBD<T> operator ++ (); // prefix ++
tsDLIterBD<T> operator ++ (); // prefix ++
tsDLIterBD<T> operator ++ (int); // postfix ++
tsDLIterBD<T> operator ++ (int); // postfix ++
tsDLIterBD<T> operator -- (); // prefix --
tsDLIterBD<T> operator -- (); // prefix --
tsDLIterBD<T> operator -- (int); // postfix --
tsDLIterBD<T> operator -- (int); // postfix --
# if defined(_MSC_VER) && _MSC_VER < 1200
tsDLIterBD (const class tsDLIterBD<T> &copyIn);
# endif
# if defined(_MSC_VER) && _MSC_VER < 1200
tsDLIterBD (const class tsDLIterBD<T> &copyIn);
# endif
bool valid () const;
@@ -265,7 +262,7 @@ inline void tsDLNode<T>::operator = (const tsDLNode<T> &) const {}
template <class T>
inline tsDLList<T>::tsDLList ()
{
this->clear ();
this->clear ();
}
//
@@ -276,7 +273,7 @@ inline tsDLList<T>::tsDLList ()
template <class T>
inline unsigned tsDLList<T>::count () const
{
return this->itemCount;
return this->itemCount;
}
//
@@ -303,9 +300,9 @@ inline T *tsDLList<T>::last (void) const
template <class T>
inline void tsDLList<T>::clear ()
{
this->pFirst = 0;
this->pLast = 0;
this->itemCount = 0u;
this->pFirst = 0;
this->pLast = 0;
this->itemCount = 0u;
}
//
@@ -314,25 +311,25 @@ inline void tsDLList<T>::clear ()
template <class T>
inline void tsDLList<T>::remove (T &item)
{
tsDLNode<T> &theNode = item;
tsDLNode<T> &theNode = item;
if (this->pLast == &item) {
this->pLast = theNode.pPrev;
}
else {
tsDLNode<T> &nextNode = *theNode.pNext;
nextNode.pPrev = theNode.pPrev;
}
if (this->pLast == &item) {
this->pLast = theNode.pPrev;
}
else {
tsDLNode<T> &nextNode = *theNode.pNext;
nextNode.pPrev = theNode.pPrev;
}
if (this->pFirst == &item) {
this->pFirst = theNode.pNext;
}
else {
tsDLNode<T> &prevNode = *theNode.pPrev;
prevNode.pNext = theNode.pNext;
}
this->itemCount--;
if (this->pFirst == &item) {
this->pFirst = theNode.pNext;
}
else {
tsDLNode<T> &prevNode = *theNode.pPrev;
prevNode.pNext = theNode.pNext;
}
this->itemCount--;
}
//
@@ -341,13 +338,13 @@ inline void tsDLList<T>::remove (T &item)
template <class T>
inline T * tsDLList<T>::get()
{
T *pItem = this->pFirst;
T *pItem = this->pFirst;
if (pItem) {
this->remove (*pItem);
}
return pItem;
if (pItem) {
this->remove (*pItem);
}
return pItem;
}
//
@@ -357,7 +354,7 @@ inline T * tsDLList<T>::get()
template <class T>
inline T * tsDLList<T>::pop()
{
return this->get();
return this->get();
}
//
@@ -369,37 +366,37 @@ inline T * tsDLList<T>::pop()
template <class T>
inline void tsDLList<T>::add (tsDLList<T> &addList)
{
//
// NOOP if addList is empty
//
if ( addList.itemCount == 0u ) {
return;
}
//
// NOOP if addList is empty
//
if ( addList.itemCount == 0u ) {
return;
}
if ( this->itemCount == 0u ) {
//
// this is empty so just init from
// addList
//
*this = addList;
}
else {
tsDLNode<T> *pLastNode = this->pLast;
tsDLNode<T> *pAddListFirstNode = addList.pFirst;
if ( this->itemCount == 0u ) {
//
// this is empty so just init from
// addList
//
*this = addList;
}
else {
tsDLNode<T> *pLastNode = this->pLast;
tsDLNode<T> *pAddListFirstNode = addList.pFirst;
//
// add addList to the end of this
//
pLastNode->pNext = addList.pFirst;
pAddListFirstNode->pPrev = addList.pLast;
this->pLast = addList.pLast;
this->itemCount += addList.itemCount;
}
//
// add addList to the end of this
//
pLastNode->pNext = addList.pFirst;
pAddListFirstNode->pPrev = addList.pLast;
this->pLast = addList.pLast;
this->itemCount += addList.itemCount;
}
//
// leave addList empty
//
addList.clear();
//
// leave addList empty
//
addList.clear();
}
//
@@ -412,20 +409,20 @@ inline void tsDLList<T>::add (T &item)
{
tsDLNode<T> &theNode = item;
theNode.pNext = 0;
theNode.pPrev = this->pLast;
theNode.pNext = 0;
theNode.pPrev = this->pLast;
if (this->itemCount) {
tsDLNode<T> &lastNode = *this->pLast;
lastNode.pNext = &item;
}
else {
this->pFirst = &item;
}
if (this->itemCount) {
tsDLNode<T> &lastNode = *this->pLast;
lastNode.pNext = &item;
}
else {
this->pFirst = &item;
}
this->pLast = &item;
this->pLast = &item;
this->itemCount++;
this->itemCount++;
}
//
@@ -436,22 +433,22 @@ inline void tsDLList<T>::add (T &item)
template <class T>
inline void tsDLList<T>::insertAfter (T &item, T &itemBefore)
{
tsDLNode<T> &nodeItem = item;
tsDLNode<T> &nodeBefore = itemBefore;
tsDLNode<T> &nodeItem = item;
tsDLNode<T> &nodeBefore = itemBefore;
nodeItem.pPrev = &itemBefore;
nodeItem.pNext = nodeBefore.pNext;
nodeBefore.pNext = &item;
nodeItem.pPrev = &itemBefore;
nodeItem.pNext = nodeBefore.pNext;
nodeBefore.pNext = &item;
if (nodeItem.pNext) {
tsDLNode<T> *pNextNode = nodeItem.pNext;
pNextNode->pPrev = &item;
}
else {
this->pLast = &item;
}
if (nodeItem.pNext) {
tsDLNode<T> *pNextNode = nodeItem.pNext;
pNextNode->pPrev = &item;
}
else {
this->pLast = &item;
}
this->itemCount++;
this->itemCount++;
}
//
@@ -462,22 +459,22 @@ inline void tsDLList<T>::insertAfter (T &item, T &itemBefore)
template <class T>
inline void tsDLList<T>::insertBefore (T &item, T &itemAfter)
{
tsDLNode<T> &node = item;
tsDLNode<T> &nodeAfter = itemAfter;
tsDLNode<T> &node = item;
tsDLNode<T> &nodeAfter = itemAfter;
node.pNext = &itemAfter;
node.pPrev = nodeAfter.pPrev;
nodeAfter.pPrev = &item;
node.pNext = &itemAfter;
node.pPrev = nodeAfter.pPrev;
nodeAfter.pPrev = &item;
if (node.pPrev) {
tsDLNode<T> &prevNode = *node.pPrev;
prevNode.pNext = &item;
}
else {
this->pFirst = &item;
}
if (node.pPrev) {
tsDLNode<T> &prevNode = *node.pPrev;
prevNode.pNext = &item;
}
else {
this->pFirst = &item;
}
this->itemCount++;
this->itemCount++;
}
//
@@ -488,21 +485,21 @@ inline void tsDLList<T>::insertBefore (T &item, T &itemAfter)
template <class T>
inline void tsDLList<T>::push (T &item)
{
tsDLNode<T> &theNode = item;
theNode.pPrev = 0;
theNode.pNext = this->pFirst;
tsDLNode<T> &theNode = item;
theNode.pPrev = 0;
theNode.pNext = this->pFirst;
if (this->itemCount) {
tsDLNode<T> *pFirstNode = this->pFirst;
pFirstNode->pPrev = &item;
}
else {
this->pLast = &item;
}
if (this->itemCount) {
tsDLNode<T> *pFirstNode = this->pFirst;
pFirstNode->pPrev = &item;
}
else {
this->pLast = &item;
}
this->pFirst = &item;
this->pFirst = &item;
this->itemCount++;
this->itemCount++;
}
//
@@ -514,17 +511,17 @@ inline void tsDLList<T>::push (T &item)
template <class T>
int tsDLList<T>::find (T &item) const
{
tsDLFwdIter<T> iter (*this);
tsDLNode<T> *pItem;
int itemNo=0;
tsDLFwdIter<T> iter (*this);
tsDLNode<T> *pItem;
int itemNo=0;
while ( ( pItem = iter.next () ) ) {
if ( pItem == &item ) {
return itemNo;
}
itemNo++;
}
return -1;
while ( ( pItem = iter.next () ) ) {
if ( pItem == &item ) {
return itemNo;
}
itemNo++;
}
return -1;
}
//////////////////////////////////////////
@@ -532,7 +529,7 @@ int tsDLList<T>::find (T &item) const
//////////////////////////////////////////
template <class T>
inline tsDLIterConstBD<T>::tsDLIterConstBD (const T * pInitialEntry) :
pConstEntry (pInitialEntry) {}
pConstEntry (pInitialEntry) {}
//
// This is apparently required by some compiler, but
@@ -540,56 +537,56 @@ inline tsDLIterConstBD<T>::tsDLIterConstBD (const T * pInitialEntry) :
// should not be required by any compiler. I am assuming
// that this "some compiler" is a past version of MS
// Visual C.
//
# if defined(_MSC_VER) && _MSC_VER < 1200
template <class T>
inline tsDLIterConstBD<T>::tsDLIterConstBD (const class tsDLIterBD<T> &copyIn) :
pConstEntry (copyIn.pEntry) {}
# endif
//
# if defined(_MSC_VER) && _MSC_VER < 1200
template <class T>
inline tsDLIterConstBD<T>::tsDLIterConstBD (const class tsDLIterBD<T> &copyIn) :
pConstEntry (copyIn.pEntry) {}
# endif
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator = (const T *pNewEntry)
{
this->pConstEntry = pNewEntry;
return *this;
this->pConstEntry = pNewEntry;
return *this;
}
template <class T>
inline bool tsDLIterConstBD<T>::operator == (const tsDLIterConstBD<T> &rhs) const
{
return this->pConstEntry == rhs.pConstEntry;
return this->pConstEntry == rhs.pConstEntry;
}
template <class T>
inline bool tsDLIterConstBD<T>::operator != (const tsDLIterConstBD<T> &rhs) const
{
return this->pConstEntry != rhs.pConstEntry;
return this->pConstEntry != rhs.pConstEntry;
}
template <class T>
inline const T & tsDLIterConstBD<T>::operator * () const
{
return *this->pConstEntry;
return *this->pConstEntry;
}
template <class T>
inline const T * tsDLIterConstBD<T>::operator -> () const
{
return this->pConstEntry;
return this->pConstEntry;
}
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::itemAfter ()
{
const tsDLNode<T> &node = *this->pConstEntry;
return tsDLIterConstBD<T> (node.pNext);
const tsDLNode<T> &node = *this->pConstEntry;
return tsDLIterConstBD<T> (node.pNext);
}
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::itemBefore ()
{
const tsDLNode<T> &node = *this->pConstEntry;
return tsDLIterConstBD<T> (node.pPrev);
const tsDLNode<T> &node = *this->pConstEntry;
return tsDLIterConstBD<T> (node.pPrev);
}
//
@@ -598,8 +595,8 @@ inline tsDLIterConstBD<T> tsDLIterConstBD<T>::itemBefore ()
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator ++ ()
{
const tsDLNode<T> &node = *this->pConstEntry;
this->pConstEntry = node.pNext;
const tsDLNode<T> &node = *this->pConstEntry;
this->pConstEntry = node.pNext;
return *this;
}
@@ -609,10 +606,10 @@ inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator ++ ()
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator ++ (int)
{
tsDLIterConstBD<T> tmp = *this;
const tsDLNode<T> &node = *this->pConstEntry;
this->pConstEntry = node.pNext;
return tmp;
tsDLIterConstBD<T> tmp = *this;
const tsDLNode<T> &node = *this->pConstEntry;
this->pConstEntry = node.pNext;
return tmp;
}
//
@@ -621,8 +618,8 @@ inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator ++ (int)
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator -- ()
{
const tsDLNode<T> &entryNode = *this->pConstEntry;
this->pConstEntry = entryNode.pPrev;
const tsDLNode<T> &entryNode = *this->pConstEntry;
this->pConstEntry = entryNode.pPrev;
return *this;
}
@@ -632,10 +629,10 @@ inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator -- ()
template <class T>
inline tsDLIterConstBD<T> tsDLIterConstBD<T>::operator -- (int)
{
tsDLIterConstBD<T> tmp = *this;
const tsDLNode<T> &entryNode = *this->pConstEntry;
this->pConstEntry = entryNode.pPrev;
return tmp;
tsDLIterConstBD<T> tmp = *this;
const tsDLNode<T> &entryNode = *this->pConstEntry;
this->pConstEntry = entryNode.pPrev;
return tmp;
}
template <class T>
@@ -659,7 +656,7 @@ inline const tsDLIterConstBD<T> tsDLIterConstBD<T>::eol ()
template <class T>
inline tsDLIterBD<T>::tsDLIterBD (T * pInitialEntry) :
tsDLIterConstBD<T> (pInitialEntry) {}
tsDLIterConstBD<T> (pInitialEntry) {}
//
// This is apparently required by some compiler, but
@@ -667,12 +664,12 @@ inline tsDLIterBD<T>::tsDLIterBD (T * pInitialEntry) :
// should not be required by any compiler. I am assuming
// that this "some compiler" is a past version of MS
// Visual C.
//
# if defined(_MSC_VER) && _MSC_VER < 1200
template <class T>
inline tsDLIterBD<T>::tsDLIterBD (const class tsDLIterBD<T> &copyIn) :
tsDLIterConstBD (copyIn) {}
# endif
//
# if defined(_MSC_VER) && _MSC_VER < 1200
template <class T>
inline tsDLIterBD<T>::tsDLIterBD (const class tsDLIterBD<T> &copyIn) :
tsDLIterConstBD (copyIn) {}
# endif
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::operator = (T *pNewEntry)
@@ -684,7 +681,7 @@ inline tsDLIterBD<T> tsDLIterBD<T>::operator = (T *pNewEntry)
template <class T>
inline bool tsDLIterBD<T>::operator == (const tsDLIterBD<T> &rhs) const
{
return this->pEntry == rhs.pEntry;
return this->pEntry == rhs.pEntry;
}
template <class T>
@@ -696,27 +693,27 @@ inline bool tsDLIterBD<T>::operator != (const tsDLIterBD<T> &rhs) const
template <class T>
inline T & tsDLIterBD<T>::operator * () const
{
return *this->pEntry;
return *this->pEntry;
}
template <class T>
inline T * tsDLIterBD<T>::operator -> () const
{
return this->pEntry;
return this->pEntry;
}
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::itemAfter ()
{
tsDLNode<T> &node = *this->pEntry;
return tsDLIterBD<T> (node.pNext);
tsDLNode<T> &node = *this->pEntry;
return tsDLIterBD<T> (node.pNext);
}
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::itemBefore ()
{
tsDLNode<T> &node = *this->pEntry;
return tsDLIterBD<T> (node.pPrev);
tsDLNode<T> &node = *this->pEntry;
return tsDLIterBD<T> (node.pPrev);
}
template <class T>
@@ -734,31 +731,31 @@ inline const tsDLIterBD<T> tsDLIterBD<T>::eol ()
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::operator ++ () // prefix ++
{
this->tsDLIterConstBD<T>::operator ++ ();
return *this;
this->tsDLIterConstBD<T>::operator ++ ();
return *this;
}
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::operator ++ (int) // postfix ++
{
tsDLIterBD<T> tmp = *this;
this->tsDLIterConstBD<T>::operator ++ (1);
return tmp;
tsDLIterBD<T> tmp = *this;
this->tsDLIterConstBD<T>::operator ++ (1);
return tmp;
}
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::operator -- () // prefix --
{
this->tsDLIterConstBD<T>::operator -- ();
return *this;
this->tsDLIterConstBD<T>::operator -- ();
return *this;
}
template <class T>
inline tsDLIterBD<T> tsDLIterBD<T>::operator -- (int) // postfix --
{
tsDLIterBD<T> tmp = *this;
this->tsDLIterConstBD<T>::operator -- (1);
return tmp;
tsDLIterBD<T> tmp = *this;
this->tsDLIterConstBD<T>::operator -- (1);
return tmp;
}
#include "tsDLListDeprecated.h"

View File

@@ -7,28 +7,28 @@
// 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
// 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 () ();
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 *pCurrent;
tsDLList<T> *pList;
T * current (); // certain compilers require this
};
@@ -38,37 +38,37 @@ protected:
//
// 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)
// 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
// 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();
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 ();
//
// 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 ();
};
@@ -78,37 +78,37 @@ protected:
//
// 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)
// 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
// 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 ();
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 ();
};
@@ -125,21 +125,21 @@ protected:
template <class T>
void tsDLFwdIter<T>::remove ()
{
T *pCur = this->pCurrent;
T *pCur = this->pCurrent;
if (pCur) {
tsDLNode<T> *pCurNode = pCur;
if (pCur) {
tsDLNode<T> *pCurNode = pCur;
//
// Move this->pCurrent to the previous item
//
this->pCurrent = pCurNode->pPrev;
//
// Move this->pCurrent to the previous item
//
this->pCurrent = pCurNode->pPrev;
//
// delete current item
//
this->pList->remove(*pCur);
}
//
// delete current item
//
this->pList->remove(*pCur);
}
}
//
@@ -148,8 +148,8 @@ void tsDLFwdIter<T>::remove ()
template <class T>
inline T * tsDLFwdIter<T>::next ()
{
tsDLIter<T> &iterBase = *this;
return iterBase.next();
tsDLIter<T> &iterBase = *this;
return iterBase.next();
}
//
@@ -158,7 +158,7 @@ inline T * tsDLFwdIter<T>::next ()
template <class T>
inline T * tsDLFwdIter<T>::operator () ()
{
return this->next();
return this->next();
}
//////////////////////////////////////////
@@ -167,39 +167,39 @@ inline T * tsDLFwdIter<T>::operator () ()
template <class T>
inline tsDLIter<T>::tsDLIter (tsDLList<T> & listIn) :
pCurrent(0), pList(&listIn) {}
pCurrent(0), pList(&listIn) {}
template <class T>
inline void tsDLIter<T>::reset ()
{
this->pCurrent = 0;
this->pCurrent = 0;
}
template <class T>
inline void tsDLIter<T>::reset (tsDLList<T> &listIn)
{
this->reset();
this->pList = &listIn;
this->reset();
this->pList = &listIn;
}
template <class T>
inline void tsDLIter<T>::operator = (tsDLList<T> &listIn)
{
this->reset(listIn);
this->reset(listIn);
}
template <class T>
inline T * tsDLIter<T>::first()
{
this->pCurrent = this->pList->pFirst;
return this->pCurrent;
this->pCurrent = this->pList->pFirst;
return this->pCurrent;
}
template <class T>
inline T * tsDLIter<T>::last()
{
this->pCurrent = this->pList->pLast;
return this->pCurrent;
this->pCurrent = this->pList->pLast;
return this->pCurrent;
}
//
@@ -208,16 +208,16 @@ inline T * tsDLIter<T>::last()
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;
T *pCur = this->pCurrent;
if (pCur==0) {
pCur = this->pList->pFirst;
}
else {
tsDLNode<T> *pCurNode = pCur;
pCur = pCurNode->pNext;
}
this->pCurrent = pCur;
return pCur;
}
//
@@ -226,16 +226,16 @@ inline T * tsDLIter<T>::next ()
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;
T *pCur = this->pCurrent;
if (pCur==0) {
pCur = this->pList->pLast;
}
else {
tsDLNode<T> *pCurNode = pCur;
pCur = pCurNode->pPrev;
}
this->pCurrent = pCur;
return pCur;
}
//
@@ -244,7 +244,7 @@ inline T * tsDLIter<T>::prev ()
template <class T>
inline T * tsDLIter<T>::operator () ()
{
return this->next();
return this->next();
}
//
@@ -253,7 +253,7 @@ inline T * tsDLIter<T>::operator () ()
template <class T>
inline T * tsDLIter<T>::current()
{
return this->pCurrent;
return this->pCurrent;
}
///////////////////////////////////////////
@@ -262,30 +262,30 @@ inline T * tsDLIter<T>::current()
template <class T>
inline tsDLBwdIter<T>::tsDLBwdIter(tsDLList<T> &listIn) :
tsDLIter<T>(listIn) {}
tsDLIter<T>(listIn) {}
template <class T>
inline void tsDLBwdIter<T>::reset ()
{
this->tsDLIter<T>::reset();
this->tsDLIter<T>::reset();
}
template <class T>
inline void tsDLBwdIter<T>::reset (tsDLList<T> &listIn)
{
this->tsDLIter<T>::reset(listIn);
this->tsDLIter<T>::reset(listIn);
}
template <class T>
inline void tsDLBwdIter<T>::operator = (tsDLList<T> &listIn)
{
this->tsDLIter<T>::reset(listIn);
this->tsDLIter<T>::reset(listIn);
}
template <class T>
inline T * tsDLBwdIter<T>::last()
{
return this->tsDLIter<T>::last();
return this->tsDLIter<T>::last();
}
//
@@ -302,29 +302,29 @@ inline T * tsDLBwdIter<T>::last()
template <class T>
void tsDLBwdIter<T>::remove ()
{
T *pCur = this->pCurrent;
T *pCur = this->pCurrent;
if (pCur) {
tsDLNode<T> *pCurNode = pCur;
if (pCur) {
tsDLNode<T> *pCurNode = pCur;
//
// strip const (we didnt declare the
// list const in the constructor)
//
tsDLList<T> * pMutableList =
(tsDLList<T> *) this->pList;
//
// 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;
//
// Move this->pCurrent to the item after the
// item being deleted
//
this->pCurrent = pCurNode->pNext;
//
// delete current item
//
pMutableList->remove(*pCur);
}
//
// delete current item
//
pMutableList->remove(*pCur);
}
}
//////////////////////////////////////////
@@ -333,35 +333,35 @@ void tsDLBwdIter<T>::remove ()
template <class T>
inline tsDLFwdIter<T>::tsDLFwdIter (tsDLList<T> &listIn) :
tsDLIter<T>(listIn) {}
tsDLIter<T>(listIn) {}
template <class T>
inline void tsDLFwdIter<T>::reset ()
{
this->tsDLIter<T>::reset();
this->tsDLIter<T>::reset();
}
template <class T>
inline void tsDLFwdIter<T>::reset (tsDLList<T> &listIn)
{
this->tsDLIter<T>::reset(listIn);
this->tsDLIter<T>::reset(listIn);
}
template <class T>
inline void tsDLFwdIter<T>::operator = (tsDLList<T> &listIn)
{
this->tsDLIter<T>::reset(listIn);
this->tsDLIter<T>::reset(listIn);
}
template <class T>
inline T * tsDLFwdIter<T>::first()
{
tsDLIter<T> &iterBase = *this;
return iterBase.first();
tsDLIter<T> &iterBase = *this;
return iterBase.first();
}
template <class T>
inline T * tsDLFwdIter<T>::current()
{
return this->tsDLIter<T>::current ();
return this->tsDLIter<T>::current ();
}

View File

@@ -7,11 +7,11 @@
template <class T>
inline const T & tsMax (const T &a, const T &b)
{
return (a>b) ? a : b;
return (a>b) ? a : b;
}
template <class T>
inline const T & tsMin (const T &a, const T &b)
{
return (a<b) ? a : b;
return (a<b) ? a : b;
}

View File

@@ -59,15 +59,15 @@ friend class tsSLIter<T>;
friend class tsSLIterRm<T>;
public:
tsSLNode ();
tsSLNode ();
void operator = (const tsSLNode<T> &) const;
void operator = (const tsSLNode<T> &) const;
private:
void removeNextItem (); // removes the item after this node
void removeNextItem (); // removes the item after this node
T *pNext;
T *pNext;
};
@@ -80,15 +80,15 @@ class tsSLList : public tsSLNode<T> {
public:
tsSLList (); // creates an empty list
void insert (T &item, tsSLNode<T> &itemBefore); // insert after item before
void insert (T &item, tsSLNode<T> &itemBefore); // insert after item before
void add (T &item); // add to the beginning of the list
void add (T &item); // add to the beginning of the list
T * get (); // remove from the beginning of the list
T * get (); // remove from the beginning of the list
T * pop (); // same as get
T * pop (); // same as get
void push (T &item); // same as add
void push (T &item); // same as add
private:
tsSLList (const tsSLList &); // intentionally _not_ implemented
};
@@ -99,15 +99,15 @@ private:
template <class T>
class tsSLIter {
public:
tsSLIter (const tsSLList<T> &listIn);
tsSLIter (const tsSLList<T> &listIn);
T * next (); // move iterator forward
T * next (); // move iterator forward
T * operator () (); // same as next ()
T * operator () (); // same as next ()
private:
T *pCurrent;
const tsSLList<T> *pList; // ptr allows cpy op
T *pCurrent;
const tsSLList<T> *pList; // ptr allows cpy op
};
//
@@ -118,23 +118,23 @@ template <class T>
class tsSLIterRm {
public:
//
// exceptions
//
class noCurrentItemInIterator {};
//
// exceptions
//
class noCurrentItemInIterator {};
tsSLIterRm (tsSLList<T> &listIn);
tsSLIterRm (tsSLList<T> &listIn);
T * next (); // move iterator forward
T * next (); // move iterator forward
T * operator () (); // same as next ()
T * operator () (); // same as next ()
void remove (); // remove current node
void remove (); // remove current node
private:
T *pPrevious;
T *pCurrent;
tsSLList<T> *pList; // ptr allows cpy op
T *pPrevious;
T *pCurrent;
tsSLList<T> *pList; // ptr allows cpy op
};
//////////////////////////////////////////
@@ -166,11 +166,11 @@ inline void tsSLNode<T>::operator = (const tsSLNode<T> &) const {}
template <class T>
inline void tsSLNode<T>::removeNextItem ()
{
T *pItem = this->pNext;
if (pItem) {
tsSLNode<T> *pNode = pItem;
this->pNext = pNode->pNext;
}
T *pItem = this->pNext;
if (pItem) {
tsSLNode<T> *pNode = pItem;
this->pNext = pNode->pNext;
}
}
//////////////////////////////////////////
@@ -196,9 +196,9 @@ inline tsSLList<T>::tsSLList ()
template <class T>
inline void tsSLList<T>::insert (T &item, tsSLNode<T> &itemBefore)
{
tsSLNode<T> &node = item;
node.pNext = itemBefore.pNext;
itemBefore.pNext = &item;
tsSLNode<T> &node = item;
node.pNext = itemBefore.pNext;
itemBefore.pNext = &item;
}
//
@@ -207,7 +207,7 @@ inline void tsSLList<T>::insert (T &item, tsSLNode<T> &itemBefore)
template <class T>
inline void tsSLList<T>::add (T &item)
{
this->insert (item, *this);
this->insert (item, *this);
}
//
@@ -216,10 +216,10 @@ inline void tsSLList<T>::add (T &item)
template <class T>
inline T * tsSLList<T>::get()
{
tsSLNode<T> *pThisNode = this;
T *pItem = pThisNode->pNext;
pThisNode->removeNextItem();
return pItem;
tsSLNode<T> *pThisNode = this;
T *pItem = pThisNode->pNext;
pThisNode->removeNextItem();
return pItem;
}
//
@@ -228,7 +228,7 @@ inline T * tsSLList<T>::get()
template <class T>
inline T * tsSLList<T>::pop()
{
return this->get();
return this->get();
}
//
@@ -237,7 +237,7 @@ inline T * tsSLList<T>::pop()
template <class T>
inline void tsSLList<T>::push(T &item)
{
this->add(item);
this->add(item);
}
//////////////////////////////////////////
@@ -265,19 +265,19 @@ inline tsSLIter<T>::tsSLIter (const tsSLList<T> &listIn) :
template <class T>
inline T * tsSLIter<T>::next ()
{
if (this->pCurrent!=0) {
tsSLNode<T> *pCurNode = this->pCurrent;
this->pCurrent = pCurNode->pNext;
}
else {
const tsSLNode<T> &first = *this->pList;
//
// assume that we are starting (or restarting) at the
// beginning of the list
//
this->pCurrent = first.pNext;
}
return this->pCurrent;
if (this->pCurrent!=0) {
tsSLNode<T> *pCurNode = this->pCurrent;
this->pCurrent = pCurNode->pNext;
}
else {
const tsSLNode<T> &first = *this->pList;
//
// assume that we are starting (or restarting) at the
// beginning of the list
//
this->pCurrent = first.pNext;
}
return this->pCurrent;
}
//
@@ -286,7 +286,7 @@ inline T * tsSLIter<T>::next ()
template <class T>
inline T * tsSLIter<T>::operator () ()
{
return this->next();
return this->next();
}
//////////////////////////////////////////
@@ -329,21 +329,21 @@ inline tsSLIterRm<T>::tsSLIterRm (tsSLList<T> &listIn) :
template <class T>
inline T * tsSLIterRm<T>::next ()
{
if (this->pCurrent!=0) {
tsSLNode<T> *pCurNode = this->pCurrent;
this->pPrevious = this->pCurrent;
this->pCurrent = pCurNode->pNext;
}
else {
const tsSLNode<T> &first = *this->pList;
//
// assume that we are starting (or restarting) at the
// beginning of the list
//
this->pCurrent = first.pNext;
this->pPrevious = 0;
}
return this->pCurrent;
if (this->pCurrent!=0) {
tsSLNode<T> *pCurNode = this->pCurrent;
this->pPrevious = this->pCurrent;
this->pCurrent = pCurNode->pNext;
}
else {
const tsSLNode<T> &first = *this->pList;
//
// assume that we are starting (or restarting) at the
// beginning of the list
//
this->pCurrent = first.pNext;
this->pPrevious = 0;
}
return this->pCurrent;
}
//
@@ -352,7 +352,7 @@ inline T * tsSLIterRm<T>::next ()
template <class T>
inline T * tsSLIterRm<T>::operator () ()
{
return this->next();
return this->next();
}
//
@@ -372,30 +372,30 @@ inline T * tsSLIterRm<T>::operator () ()
template <class T>
void tsSLIterRm<T>::remove ()
{
if (this->pCurrent==0) {
if (this->pCurrent==0) {
throwWithLocation ( noCurrentItemInIterator () );
}
}
tsSLNode<T> *pPrevNode;
tsSLNode<T> *pCurNode = this->pCurrent;
tsSLNode<T> *pPrevNode;
tsSLNode<T> *pCurNode = this->pCurrent;
if (this->pPrevious==0) {
pPrevNode = this->pList;
//
// fail if it is an attempt to
// delete twice without moving the iterator
//
if (pPrevNode->pNext != this->pCurrent) {
if (this->pPrevious==0) {
pPrevNode = this->pList;
//
// fail if it is an attempt to
// delete twice without moving the iterator
//
if (pPrevNode->pNext != this->pCurrent) {
throwWithLocation ( noCurrentItemInIterator ());
}
}
else {
pPrevNode = this->pPrevious;
}
}
}
else {
pPrevNode = this->pPrevious;
}
pPrevNode->pNext = pCurNode->pNext;
this->pCurrent = this->pPrevious;
this->pPrevious = 0;
pPrevNode->pNext = pCurNode->pNext;
this->pCurrent = this->pPrevious;
this->pPrevious = 0;
}
#endif // tsSLListh

View File

@@ -56,32 +56,32 @@ class epicsShareClass fdRegId
{
public:
fdRegId (const SOCKET fdIn, const fdRegType typeIn) :
fd(fdIn), type(typeIn) {}
fdRegId (const SOCKET fdIn, const fdRegType typeIn) :
fd(fdIn), type(typeIn) {}
SOCKET getFD () const
{
return this->fd;
}
SOCKET getFD () const
{
return this->fd;
}
fdRegType getType () const
{
return this->type;
}
fdRegType getType () const
{
return this->type;
}
bool operator == (const fdRegId &idIn) const
{
return this->fd == idIn.fd && this->type==idIn.type;
}
bool operator == (const fdRegId &idIn) const
{
return this->fd == idIn.fd && this->type==idIn.type;
}
resTableIndex hash (unsigned nBitsId) const;
resTableIndex hash (unsigned nBitsId) const;
static const unsigned minIndexBitWidth ();
static const unsigned maxIndexBitWidth ();
virtual void show (unsigned level) const;
virtual void show (unsigned level) const;
private:
const SOCKET fd;
const SOCKET fd;
const fdRegType type;
};
@@ -100,34 +100,34 @@ public:
//
class fdInterestSubscriptionAlreadyExits {};
epicsShareFunc fdManager (osiTimerQueue &timerQueue = osiDefaultTimerQueue);
epicsShareFunc ~fdManager ();
epicsShareFunc void process (double delay); // delay parameter is in seconds
epicsShareFunc fdManager (osiTimerQueue &timerQueue = osiDefaultTimerQueue);
epicsShareFunc ~fdManager ();
epicsShareFunc void process (double delay); // delay parameter is in seconds
//
// returns NULL if the fd is unknown
//
//
// returns NULL if the fd is unknown
//
epicsShareFunc fdReg *lookUpFD (const SOCKET fd, const fdRegType type);
osiTimerQueue & timerQueueRef () const;
private:
tsDLList<fdReg> regList;
tsDLList<fdReg> activeList;
resTable<fdReg, fdRegId> fdTbl;
fd_set fdSets[fdrNEnums];
tsDLList<fdReg> regList;
tsDLList<fdReg> activeList;
resTable<fdReg, fdRegId> fdTbl;
fd_set fdSets[fdrNEnums];
osiTimerQueue &timerQueue;
SOCKET maxFD;
unsigned processInProg;
//
// Set to fdreg when in call back
// and nill otherwise
//
fdReg *pCBReg;
SOCKET maxFD;
unsigned processInProg;
//
// Set to fdreg when in call back
// and nill otherwise
//
fdReg *pCBReg;
epicsShareFunc void installReg (fdReg &reg);
epicsShareFunc void removeReg (fdReg &reg);
epicsShareFunc void installReg (fdReg &reg);
epicsShareFunc void removeReg (fdReg &reg);
};
//
@@ -146,37 +146,37 @@ class fdReg : public fdRegId, public tsDLNode<fdReg>, public tsSLNode<fdReg> {
public:
epicsShareFunc fdReg (const SOCKET fdIn, const fdRegType type,
const bool onceOnly=false, fdManager &manager = fileDescriptorManager);
epicsShareFunc virtual ~fdReg ();
const bool onceOnly=false, fdManager &manager = fileDescriptorManager);
epicsShareFunc virtual ~fdReg ();
epicsShareFunc virtual void show (unsigned level) const;
//
// Called by the file descriptor manager:
// 1) If the fdManager is deleted and there are still
// fdReg objects attached
// 2) Immediately after calling "callBack()" if
// the constructor specified "onceOnly"
//
// fdReg::destroy() does a "delete this"
//
epicsShareFunc virtual void destroy ();
epicsShareFunc virtual void show (unsigned level) const;
//
// Called by the file descriptor manager:
// 1) If the fdManager is deleted and there are still
// fdReg objects attached
// 2) Immediately after calling "callBack()" if
// the constructor specified "onceOnly"
//
// fdReg::destroy() does a "delete this"
//
epicsShareFunc virtual void destroy ();
private:
enum state {active, pending, limbo};
//
// called when there is activity on the fd
// NOTES
// 1) the fdManager will call this only once during the
// lifetime of a fdReg object if the constructor
// specified "onceOnly"
//
epicsShareFunc virtual void callBack ()=0;
//
// called when there is activity on the fd
// NOTES
// 1) the fdManager will call this only once during the
// lifetime of a fdReg object if the constructor
// specified "onceOnly"
//
epicsShareFunc virtual void callBack ()=0;
unsigned char state; // state enums go here
unsigned char onceOnly;
fdManager &manager;
unsigned char state; // state enums go here
unsigned char onceOnly;
fdManager &manager;
};
//
@@ -189,16 +189,16 @@ inline resTableIndex fdRegId::hash (unsigned) const
hashid = intId<SOCKET, hashTableIndexBits, sizeof(SOCKET)*CHAR_BIT>
::hashEngine(this->fd);
//
// also evenly distribute based on the type of fdRegType
//
hashid ^= this->type;
//
// also evenly distribute based on the type of fdRegType
//
hashid ^= this->type;
//
// the result here is always masked to the
// proper size after it is returned to the resource class
//
return hashid;
//
// the result here is always masked to the
// proper size after it is returned to the resource class
//
return hashid;
}
//