~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/tools/tLinkedList.h

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
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.
14
 
 
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.
19
 
 
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.
23
 
  
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#ifndef ArmageTron_tLinkedList_H
29
 
#define ArmageTron_tLinkedList_H
30
 
 
31
 
#include "tError.h"
32
 
 
33
 
#include <stdlib.h>
34
 
 
35
 
class tListItemBase{
36
 
protected:
37
 
    tListItemBase  *next;
38
 
    tListItemBase **anchor;
39
 
 
40
 
public:
41
 
    typedef int (Comparator)( const tListItemBase* a, const tListItemBase* b );
42
 
 
43
 
    void Remove();
44
 
    void Insert(tListItemBase *&a);
45
 
 
46
 
    tListItemBase():next(NULL),anchor(NULL)                 {}
47
 
    tListItemBase(tListItemBase *&a):next(NULL),anchor(NULL){Insert(a);}
48
 
    virtual ~tListItemBase()                                {Remove();}
49
 
 
50
 
    tListItemBase *Next()                             {return next;}
51
 
 
52
 
    int Len();
53
 
    void Sort( Comparator* comparator );
54
 
};
55
 
 
56
 
template < typename T, typename comparator >
57
 
int st_Compare( const tListItemBase* a, const tListItemBase* b )
58
 
{
59
 
    const T* A = static_cast<const T*>( a );
60
 
    const T* B = static_cast<const T*>( b );
61
 
 
62
 
    return comparator::Compare( A, B );
63
 
}
64
 
 
65
 
 
66
 
template <class T> class tListItem:public tListItemBase{
67
 
public:
68
 
    tListItem():tListItemBase()
69
 
    { 
70
 
        // this class only works under this condition:
71
 
        tASSERT( static_cast< tListItemBase * >( ( T * )(NULL)  ) == NULL );
72
 
    };
73
 
    tListItem(T *&a):tListItemBase(reinterpret_cast<tListItemBase*&>(a)){};
74
 
    T *Next(){return reinterpret_cast<T*>(next);}
75
 
 
76
 
    template< typename comparator >
77
 
    void Sort( )
78
 
    {
79
 
        tListItemBase::Sort( &st_Compare< T, comparator> );
80
 
    }
81
 
 
82
 
    void Insert(tListItem *&a)
83
 
    {
84
 
        tListItemBase::Insert( reinterpret_cast<tListItemBase*&>(a) );
85
 
    }
86
 
 
87
 
    void Insert(T *&a)
88
 
    {
89
 
        tListItemBase::Insert( reinterpret_cast<tListItemBase*&>(a) );
90
 
    }
91
 
 
92
 
    void Insert(tListItemBase *&a)
93
 
    {
94
 
        tListItemBase::Insert( a );
95
 
    }
96
 
};
97
 
 
98
 
#endif