make gcc-2.95 happy
This commit is contained in:
parent
7811f0ab16
commit
68fea83c6f
|
@ -55,6 +55,8 @@ private:
|
|||
List<GameEntry> buckets[MAX_BUCKETS];
|
||||
|
||||
int timeout;
|
||||
|
||||
friend class GameList::GameListIterator;
|
||||
};
|
||||
|
||||
#endif // _GAMELIST_H_
|
||||
|
|
166
list.h
166
list.h
|
@ -35,8 +35,13 @@ template <class T>
|
|||
class ListEntry;
|
||||
|
||||
|
||||
template <class T>
|
||||
class ListIterator;
|
||||
|
||||
|
||||
template <class T>
|
||||
class List {
|
||||
friend class ListIterator<T>;
|
||||
public:
|
||||
List() : head(0), tail(0) {}
|
||||
~List() {}
|
||||
|
@ -91,77 +96,78 @@ protected:
|
|||
List(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:
|
||||
ListEntry<T> *head;
|
||||
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>
|
||||
class ListEntry {
|
||||
friend class List<T>;
|
||||
friend class List<T>::ListIterator<T>;
|
||||
friend class ListIterator<T>;
|
||||
public:
|
||||
ListEntry() {}
|
||||
~ListEntry() {}
|
||||
|
@ -171,8 +177,13 @@ private:
|
|||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class LockedListIterator;
|
||||
|
||||
|
||||
template <class T>
|
||||
class LockedList : private List<T> {
|
||||
friend class LockedListIterator<T>;
|
||||
public:
|
||||
LockedList() {}
|
||||
~LockedList() {}
|
||||
|
@ -210,22 +221,23 @@ public:
|
|||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
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_
|
||||
|
|
Loading…
Reference in New Issue