OpenBarnyard
 
Loading...
Searching...
No Matches
TDList.h
Go to the documentation of this file.
1#pragma once
2#include "T2Iterator.h"
3
5
7{
8public:
9 class TNode
10 {
11 public:
13 template <class T> friend class TDList;
15
20
21 public:
22 template <typename T>
23 T* As() { return TSTATICCAST( T, this ); }
24
25 protected:
26 TNode();
28 ~TNode();
29
30 TNode* Next() const { return m_pNext; }
31 TNode* Prev() const { return m_pPrev; }
32
33 public:
34 void Remove();
35 void InsertAfter( TNode* a_pNode );
36 void InsertBefore( TNode* a_pNode );
37
38 TBOOL IsLinked() const { return this != m_pNext; }
39
40 private:
41 void Reset();
42
43 protected:
46 };
47
48public:
49 void InsertSegmentAtHead( TNode* a_pNode1, TNode* a_pNode2 );
50 void InsertSegmentAtTail( TNode* a_pNode1, TNode* a_pNode2 );
51
52 void InsertHead( TNode* a_pNode ) { a_pNode->InsertAfter( &m_oRoot ); }
53 void InsertTail( TNode* a_pNode ) { a_pNode->InsertBefore( &m_oRoot ); }
55 {
56 if ( !IsEmpty() ) m_oRoot.Next()->Remove();
57 }
59 {
60 if ( !IsEmpty() ) m_oRoot.Prev()->Remove();
61 }
62 TBOOL IsEmpty() { return m_oRoot.Next() == &m_oRoot; }
63 TNode* Head() { return m_oRoot.Next(); }
64 TNode* Tail() { return m_oRoot.Prev(); }
65 TNode* Begin() { return m_oRoot.Next(); }
66 TNode* End() { return &m_oRoot; }
67
68 void RemoveAll();
69
70public:
71 static void InsertSegmentAfter( TNode* a_pNode1, TNode* a_pNode2, TNode* a_pNode3 );
72 static void InsertSegmentBefore( TNode* a_pNode1, TNode* a_pNode2, TNode* a_pNode3 );
73
74protected:
77
78private:
79 TNode m_oRoot;
80};
81
83{
84public:
85 class TNode
86 {
87 public:
89 template <class T> friend class TPriList;
91
96
97 public:
98 template <typename T>
99 T* As() { return TSTATICCAST( T, this ); }
100
101 protected:
102 TNode();
104 ~TNode();
105
106 TNode* Next() const { return m_pNext; }
107 TNode* Prev() const { return m_pPrev; }
108
109 public:
110 void Remove();
111 void InsertAfter( TNode* a_pNode );
112 void InsertBefore( TNode* a_pNode );
113
114 TBOOL IsLinked() const { return this != m_pNext; }
115
116 void SetPriority( TINT priority ) { m_iPriority = priority; }
117 TINT GetPriority() const { return m_iPriority; }
118
119 TNode& operator=( const TNode& a_pNode );
120
121 private:
122 void Reset();
123
124 public:
128 };
129
130public:
131 TBOOL IsEmpty() { return m_pNext == End(); }
132 TNode* Head() { return m_pNext; }
133 TNode* Tail() { return m_pPrev; }
134 TNode* Begin() { return m_pNext; }
135 TNode* End() { return (TNode*)this; }
136
137 void Insert( TNode* a_pNode, TINT iPriority );
138 void Insert( TNode* a_pNode );
139
140 void RemoveAll();
141
142protected:
145
146private:
147 TNode* m_pNext;
148 TNode* m_pPrev;
149};
150
151template <class T>
153{
154public:
156
158
159 Iterator GetNext( Iterator a_itNode ) { return a_itNode.Next(); }
160 Iterator GetPrev( Iterator a_itNode ) { return a_itNode.Prev(); }
164};
165
166template <class T>
167class TDList : public TGenericDList
168{
169public:
171
173
174 Iterator GetNext( Iterator a_itNode ) { return a_itNode.Next(); }
175 Iterator GetPrev( Iterator a_itNode ) { return a_itNode.Prev(); }
176 T* Head() { return TGenericDList::Head()->As<T>(); }
177 T* Tail() { return TGenericDList::Tail()->As<T>(); }
178 Iterator Begin() { return TGenericDList::Begin()->As<T>(); }
179 Iterator End() { return TGenericDList::End()->As<T>(); }
181 TBOOL IsLinked() { return m_oRoot.IsLinked(); }
184};
185
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define T2_DEFINE_ITERATOR(TYPE, NODE_TYPE)
Definition T2Iterator.h:19
#define T2_DEFINE_ITERATOR_FRIEND()
Definition T2Iterator.h:16
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
void InsertSegmentAtHead(TNode *a_pNode1, TNode *a_pNode2)
Definition TDList.cpp:84
void InsertSegmentAtTail(TNode *a_pNode1, TNode *a_pNode2)
Definition TDList.cpp:92
void RemoveAll()
Definition TDList.cpp:100
void RemoveTail()
Definition TDList.h:58
void InsertHead(TNode *a_pNode)
Definition TDList.h:52
TNode * Begin()
Definition TDList.h:65
static void InsertSegmentAfter(TNode *a_pNode1, TNode *a_pNode2, TNode *a_pNode3)
Definition TDList.cpp:59
static void InsertSegmentBefore(TNode *a_pNode1, TNode *a_pNode2, TNode *a_pNode3)
Definition TDList.cpp:67
void InsertTail(TNode *a_pNode)
Definition TDList.h:53
TNode * Tail()
Definition TDList.h:64
TNode * Head()
Definition TDList.h:63
TNode * End()
Definition TDList.h:66
TBOOL IsEmpty()
Definition TDList.h:62
void RemoveHead()
Definition TDList.h:54
void InsertBefore(TNode *a_pNode)
Definition TDList.cpp:36
TNode * Prev() const
Definition TDList.h:31
TBOOL IsLinked() const
Definition TDList.h:38
void InsertAfter(TNode *a_pNode)
Definition TDList.cpp:26
TNode * Next() const
Definition TDList.h:30
friend class TDList
Definition TDList.h:13
friend TGenericDList
Definition TDList.h:12
void Insert(TNode *a_pNode, TINT iPriority)
Definition TPriList.cpp:66
TBOOL IsEmpty()
Definition TDList.h:131
TNode * Begin()
Definition TDList.h:134
TNode * Tail()
Definition TDList.h:133
TNode * End()
Definition TDList.h:135
TNode * Head()
Definition TDList.h:132
friend class TPriList
Definition TDList.h:89
TNode * Prev() const
Definition TDList.h:107
TINT GetPriority() const
Definition TDList.h:117
TNode & operator=(const TNode &a_pNode)
Definition TPriList.cpp:98
void InsertBefore(TNode *a_pNode)
Definition TPriList.cpp:23
void InsertAfter(TNode *a_pNode)
Definition TPriList.cpp:12
TNode * Next() const
Definition TDList.h:106
void SetPriority(TINT priority)
Definition TDList.h:116
TBOOL IsLinked() const
Definition TDList.h:114
Iterator GetPrev(Iterator a_itNode)
Definition TDList.h:160
TBOOL IsLinked()
Definition TDList.h:163
Iterator GetNext(Iterator a_itNode)
Definition TDList.h:159
TPriList()
Definition TDList.h:157
Toshi::T2Iterator< T, TNode > Iterator
Definition TDList.h:155
Iterator Begin()
Definition TDList.h:161
Iterator End()
Definition TDList.h:162
TDList()
Definition TDList.h:172
Toshi::T2Iterator< T, TNode > Iterator
Definition TDList.h:170
TBOOL IsLinked()
Definition TDList.h:181
Iterator GetPrev(Iterator a_itNode)
Definition TDList.h:175
T * Head()
Definition TDList.h:176
Iterator Begin()
Definition TDList.h:178
T * Tail()
Definition TDList.h:177
Iterator GetNext(Iterator a_itNode)
Definition TDList.h:174
void RemoveHead()
Definition TDList.h:182
Iterator End()
Definition TDList.h:179
TBOOL IsEmpty()
Definition TDList.h:180
void RemoveTail()
Definition TDList.h:183