3
*************************************************************************
5
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
8
**************************************************************************
10
This program is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
***************************************************************************
28
#ifndef ArmageTron_tLinkedList_H
29
#define ArmageTron_tLinkedList_H
38
tListItemBase **anchor;
41
typedef int (Comparator)( const tListItemBase* a, const tListItemBase* b );
44
void Insert(tListItemBase *&a);
46
tListItemBase():next(NULL),anchor(NULL) {}
47
tListItemBase(tListItemBase *&a):next(NULL),anchor(NULL){Insert(a);}
48
virtual ~tListItemBase() {Remove();}
50
tListItemBase *Next() {return next;}
53
void Sort( Comparator* comparator );
56
template < typename T, typename comparator >
57
int st_Compare( const tListItemBase* a, const tListItemBase* b )
59
const T* A = static_cast<const T*>( a );
60
const T* B = static_cast<const T*>( b );
62
return comparator::Compare( A, B );
66
template <class T> class tListItem:public tListItemBase{
68
tListItem():tListItemBase()
70
// this class only works under this condition:
71
tASSERT( static_cast< tListItemBase * >( ( T * )(NULL) ) == NULL );
73
tListItem(T *&a):tListItemBase(reinterpret_cast<tListItemBase*&>(a)){};
74
T *Next(){return reinterpret_cast<T*>(next);}
76
template< typename comparator >
79
tListItemBase::Sort( &st_Compare< T, comparator> );
82
void Insert(tListItem *&a)
84
tListItemBase::Insert( reinterpret_cast<tListItemBase*&>(a) );
89
tListItemBase::Insert( reinterpret_cast<tListItemBase*&>(a) );
92
void Insert(tListItemBase *&a)
94
tListItemBase::Insert( a );