Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dllist.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : ww3d *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/dllist.h $*
26 * *
27 * Original Author:: Jani Penttinen *
28 * *
29 * $Author:: Jani_p $*
30 * *
31 * $Modtime:: 3/21/01 6:18p $*
32 * *
33 * $Revision:: 11 $*
34 * *
35 *---------------------------------------------------------------------------------------------*
36 * Functions: *
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
38
39#if defined(_MSC_VER)
40#pragma once
41#endif
42
43#ifndef DLLIST_H
44#define DLLIST_H
45
46
47template <class T> class DLNodeClass;
48
49template <class T>
51{
52 friend DLNodeClass<T>;
53 DLNodeClass<T>* head;
54 DLNodeClass<T>* tail;
55
56public:
57 DLListClass() : head(0), tail(0) {}
58 virtual ~DLListClass() { }
59
64
65 T* Head() { return static_cast<T*>(head); }
66 T* Tail() { return static_cast<T*>(tail); }
67 const T* Const_Head() const { return static_cast<const T*>(head); }
68 const T* Const_Tail() const { return static_cast<const T*>(tail); }
69};
70
71// Destroy-list will call delete for all nodes when the list is destructed. Note that the class doesn't work
72// with undeclared pointer types (destructor has to be known).
73template <class T>
75{
76public:
78 {
79 while (T* t=Head()) {
80 delete t;
81 }
82 }
83};
84
85template <class T>
86class DLNodeClass : public W3DMPO
87{
88 // nope, this is an ABC
89 //W3DMPO_GLUE(DLNodeClass)
90
91 friend DLListClass<T>;
92 DLNodeClass<T>* succ;
93 DLNodeClass<T>* pred;
94 DLListClass<T>* list;
95public:
96 DLNodeClass() : succ(0), pred(0), list(0) {}
98
100 {
101 list=n->list;
102 succ=n;
103 pred=n->pred;
104 if (n->pred) n->pred->succ=this;
105 n->pred=this;
106
107 if (list->head==n) {
108 list->head=this;
109 }
110 }
111
113 {
114 list=n->list;
115 pred=n;
116 succ=n->succ;
117 if (n->succ) n->succ->pred=this;
118 n->succ=this;
119
120 if (list->tail==n) {
121 list->tail=this;
122 }
123 }
124
125 void Remove()
126 {
127 if (!list) return;
128 if (list->Head()==this) {
129 DLListClass<T>* tmp_list=list;
130 list=0;
131 tmp_list->Remove_Head();
132 return;
133 }
134 if (list->Tail()==this) {
135 DLListClass<T>* tmp_list=list;
136 list=0;
137 tmp_list->Remove_Tail();
138 return;
139 }
140 if (succ) succ->pred=pred;
141 if (pred) pred->succ=succ;
142 list=0;
143 }
144
145
146 T* Succ() { return static_cast<T*>(succ); }
147 T* Pred() { return static_cast<T*>(pred); }
148 const T* Const_Succ() const { return static_cast<const T*>(succ); }
149 const T* Const_Pred() const { return static_cast<const T*>(pred); }
150
151 DLListClass<T>* List() { return list; }
152};
153
154
155template <class T>
157{
158 n->list=this;
159 if (head) {
160 n->Insert_Before(head);
161 head=n;
162 }
163 else {
164 tail=n;
165 head=n;
166 n->succ=0;
167 n->pred=0;
168 }
169}
170
171template <class T>
173{
174 n->list=this;
175 if (tail) {
176 n->Insert_After(tail);
177 tail=n;
178 }
179 else {
180 tail=n;
181 head=n;
182 n->succ=0;
183 n->pred=0;
184 }
185}
186
187template <class T>
189{
190 if (!head) return;
191 DLNodeClass<T>* n=head;
192 head=head->Succ();
193 if (!head) tail=head;
194 else head->pred=0;
195 n->Remove();
196}
197
198template <class T>
200{
201 if (!tail) return;
202 DLNodeClass<T>* n=tail;
203 tail=tail->Pred();
204 if (!tail) head=tail;
205 else tail->succ=0;
206 n->Remove();
207}
208
209#endif //DLLIST_H
virtual ~DLDestroyListClass()
Definition dllist.h:77
void Add_Tail(DLNodeClass< T > *node)
Definition dllist.h:172
DLListClass()
Definition dllist.h:57
T * Tail()
Definition dllist.h:66
void Remove_Tail()
Definition dllist.h:199
void Add_Head(DLNodeClass< T > *node)
Definition dllist.h:156
void Remove_Head()
Definition dllist.h:188
virtual ~DLListClass()
Definition dllist.h:58
T * Head()
Definition dllist.h:65
const T * Const_Head() const
Definition dllist.h:67
const T * Const_Tail() const
Definition dllist.h:68
void Remove()
Definition dllist.h:125
const T * Const_Succ() const
Definition dllist.h:148
const T * Const_Pred() const
Definition dllist.h:149
T * Pred()
Definition dllist.h:147
T * Succ()
Definition dllist.h:146
void Insert_After(DLNodeClass< T > *n)
Definition dllist.h:112
DLListClass< T > * List()
Definition dllist.h:151
DLNodeClass()
Definition dllist.h:96
void Insert_Before(DLNodeClass< T > *n)
Definition dllist.h:99
~DLNodeClass()
Definition dllist.h:97