make gcc-2.95 happy

This commit is contained in:
Olaf Rempel 2006-04-17 13:35:50 +02:00
parent 7811f0ab16
commit 68fea83c6f
2 changed files with 91 additions and 77 deletions

View File

@ -55,6 +55,8 @@ private:
List<GameEntry> buckets[MAX_BUCKETS]; List<GameEntry> buckets[MAX_BUCKETS];
int timeout; int timeout;
friend class GameList::GameListIterator;
}; };
#endif // _GAMELIST_H_ #endif // _GAMELIST_H_

166
list.h
View File

@ -35,8 +35,13 @@ template <class T>
class ListEntry; class ListEntry;
template <class T>
class ListIterator;
template <class T> template <class T>
class List { class List {
friend class ListIterator<T>;
public: public:
List() : head(0), tail(0) {} List() : head(0), tail(0) {}
~List() {} ~List() {}
@ -91,77 +96,78 @@ protected:
List(const List& l); List(const List& l);
List& operator=(const List& l); List& operator=(const List& l);
template <class TT>
class ListIterator : public Iterator<TT> {
public:
ListIterator(List<TT>* list)
: list(list)
{
reset();
}
virtual ~ListIterator() {}
virtual bool hasNext()
{
return (pos == NULL) ? (list->head != NULL) : (pos->next != NULL);
}
virtual TT* next()
{
prev = pos;
pos = (pos == NULL) ? list->head : pos->next;
return (TT*)pos;
}
virtual void remove()
{
// remove pre-head -> bail out
if (pos == NULL)
return;
// remove first
if (pos == list->head)
list->head = pos->next;
// remove middle
if (prev)
prev->next = pos->next;
// remove last
if (pos == list->tail)
list->tail = (prev == NULL) ? NULL : prev;
pos = prev;
}
virtual void reset()
{
pos = NULL;
prev = NULL;
}
protected:
ListIterator(const ListIterator& li);
ListIterator& operator=(const ListIterator& li);
List<TT>* list;
private:
ListEntry<TT>* pos;
ListEntry<TT>* prev;
};
private: private:
ListEntry<T> *head; ListEntry<T> *head;
ListEntry<T> *tail; ListEntry<T> *tail;
}; };
template <class T>
class ListIterator : public Iterator<T> {
public:
ListIterator(List<T>* list)
: list(list)
{
reset();
}
virtual ~ListIterator() {}
virtual bool hasNext()
{
return (pos == NULL) ? (list->head != NULL) : (pos->next != NULL);
}
virtual T* next()
{
prev = pos;
pos = (pos == NULL) ? list->head : pos->next;
return (T*)pos;
}
virtual void remove()
{
// remove pre-head -> bail out
if (pos == NULL)
return;
// remove first
if (pos == list->head)
list->head = pos->next;
// remove middle
if (prev)
prev->next = pos->next;
// remove last
if (pos == list->tail)
list->tail = (prev == NULL) ? NULL : prev;
pos = prev;
}
virtual void reset()
{
pos = NULL;
prev = NULL;
}
protected:
ListIterator(const ListIterator& li);
ListIterator& operator=(const ListIterator& li);
List<T>* list;
private:
ListEntry<T>* pos;
ListEntry<T>* prev;
};
template <class T> template <class T>
class ListEntry { class ListEntry {
friend class List<T>; friend class List<T>;
friend class List<T>::ListIterator<T>; friend class ListIterator<T>;
public: public:
ListEntry() {} ListEntry() {}
~ListEntry() {} ~ListEntry() {}
@ -171,8 +177,13 @@ private:
}; };
template <class T>
class LockedListIterator;
template <class T> template <class T>
class LockedList : private List<T> { class LockedList : private List<T> {
friend class LockedListIterator<T>;
public: public:
LockedList() {} LockedList() {}
~LockedList() {} ~LockedList() {}
@ -210,22 +221,23 @@ public:
} }
private: private:
template <class TT>
class LockedListIterator : public List<TT>::ListIterator<TT> {
public:
LockedListIterator(LockedList<TT>* list)
: List<TT>::ListIterator<TT>(list)
{
list->mutex.lock();
}
virtual ~LockedListIterator()
{
((LockedList<TT>*)list)->mutex.unlock();
}
};
Mutex mutex; Mutex mutex;
}; };
template <class T>
class LockedListIterator : public ListIterator<T> {
public:
LockedListIterator(LockedList<T>* list)
: ListIterator<T>(list)
{
list->mutex.lock();
}
virtual ~LockedListIterator()
{
((LockedList<T>*)list)->mutex.unlock();
}
};
#endif //_LIST_H_ #endif //_LIST_H_