File: t_list.hpp

package info (click to toggle)
esys-particle 2.3.5%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,132 kB
  • sloc: cpp: 81,480; python: 5,872; makefile: 1,259; sh: 313; perl: 225
file content (338 lines) | stat: -rw-r--r-- 6,116 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2017 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.apache.org/licenses/LICENSE-2.0              //
//                                                         //
/////////////////////////////////////////////////////////////

template <class T>
void Stack<T>::Push(T* V) {
  L.InsertAtStart(V) ;
} 

template <class T>
T* Stack<T>::Pop() {
  L.First() ;
  T* t= L.Get() ;
  L.Clear() ;
  return t ;
}

template <class T>
List<T>::List()
   {
   Start = End = Current = NULL ;
   }

template <class T>
List<T>::List(const List<T> &L)
   {
   Node<T> *Lcur ;
   Start = End = Current = NULL ;
   Lcur = L.Start ;
   while (Lcur)
      {
      Append(Lcur->Val) ;
      Lcur = Lcur->Next ;
      }
   }

template <class T>
List<T>::~List()
   {
   Destroy() ;
   }

/*!
  return the number of element in the list
*/
template <class T>
int List<T>::SizeList()
   {
    int i = 0;
    First() ;
    while (!IsEnd()) {
	i++ ;
	Next() ;
    }
    return i ;
   }

/*!
  Insert an element at the begining of the list
  \param V pointer to element to be inserted
*/
template <class T>
void List<T>::InsertAtStart(T *V)
   {
   if (Start==NULL)
      {
      Start = new Node<T> ;
      Start->Next = NULL ;
      Start->Prev = NULL ;
      Current = Start ;
      End = Start ;
      Current->Val = V ;
      }
   else
      {
      Node<T> *Inter ;
      Inter = new Node<T> ;
      Inter->Prev = NULL ;
      Inter->Next = Start ;
      Inter->Val = V ;
      Start->Prev = Inter ;
      Start = Inter ;
      }
   }

template <class T>
void List<T>::Append(T *V)
   {
   if (Start==NULL)
      {
      Start = new Node<T> ;
      Start->Next = NULL ;
      Start->Prev = NULL ;
      Current = Start ;
      End = Start ;
      Current->Val = V ;
      }
   else
      {
      Node<T> *Inter ;
      Inter = new Node<T> ;
      Inter->Prev = End ;
      Inter->Next = NULL ;
      Inter->Val = V ;
      End->Next = Inter ;
      End = Inter ;
      }
   }

template <class T>
void List<T>::InsertAfter(T *V)
   {
   if ((Start==NULL)||(Current==NULL)||(Current->Next==NULL))
      {
      Append(V) ;
      }
   else
      {
      Node<T> *Inter ;
      Inter = new Node<T> ;
      Inter->Prev = Current ;
      Inter->Next = Current->Next ;
      Inter->Val = V ;
      Current->Next->Prev = Inter ;
      Current->Next = Inter ;
      }
   }

template <class T>
void List<T>::InsertBefore(T *V)
   {
   if ((Start==NULL)||(Current==NULL))
      {
      Append(V) ;
      }
   else if (Start==Current)
      {
      InsertAtStart(V) ;
      }
   else
      {
      Node<T> *Inter ;
      Inter = new Node<T> ;
      Inter->Prev = Current->Prev ;
      Inter->Next = Current ;
      Inter->Val = V ;
      Current->Prev->Next = Inter ;
      Current->Prev = Inter ;
      }
   }

template <class T>
T* List<T>::Get()
   {
#ifdef _DEBUG
     if (!Current) {
       console.Critical() << "Invalid access in List via null pointer\n" ;
     }
     if (!Current->Val) {
       console.Warning() << "List just returned a null pointer\n" ;
     }
#endif
   return Current->Val ;
   }

template <class T>
void List<T>::Put(T *V)
   {
   if (Current) Current->Val = V ;
   }

template <class T>
void List<T>::Clear()
   {
   if (Current)
      {
      if (Current==Start)
	 {
	 Start = Current->Next ;
	 if (Start) Start->Prev = NULL ;
	 else End=NULL ;
	 delete Current ;
	 Current = Start ;
	 }
      else if (Current==End)
	 {
	 End = Current->Prev ;
	 End->Next = NULL ;
	 delete Current ;
	 Current = NULL ;
	 }
      else
	 {
	 Node<T> *Inter ;

	 Inter = Current->Next ;
	 Current->Prev->Next = Current->Next ;
	 Current->Next->Prev = Current->Prev ;
	 delete Current ;
	 Current = Inter ;
	 }
      }
   }

template <class T>
void List<T>::Destroy()
   {
   Current=Start ;
   while (Current) Clear() ;
   }

template <class T>
List<T>& List<T>::operator << (T *V)
  {
  InsertAfter(V) ;
  Next() ;
  return *this ;
  }

template <class T>
List<T>& List<T>::operator >> (T *V)
  {
  if (Current) V = Current->Val ;
  Next() ;
  return *this ;
  }

template <class T>
void List<T>::Next()
  {
  if (Current) Current=Current->Next ;
  }

template <class T>
void List<T>::Prev()
  {
  if (Current && Current->Prev) Current=Current->Prev ;
  }

template <class T>
void List<T>::First()
   {
   Current = Start ;
   }

template <class T>
void List<T>::Last()
   {
   Current = End ;
   }

template <class T>
int List<T>::IsEnd()
   {
   return (Current==NULL) ;
   }

template <class T>
int List<T>::IsStart()
   {
   return (Current==Start) ;
   }

template <class T>
void List<T>::Swap() // echange current avec le suivant
   {
   Node<T> *CS, *CP, *CSS, *C ;

   C = Current ;
   CS = C->Next ;
   CP = C->Prev ;
   CSS = CS->Next ;
   if (CP) CP->Next = CS ;
   CS->Prev = CP ;
   CS->Next = C ;
   C->Prev = CS ;
   C->Next = CSS ;
   if (CSS) CSS->Prev = C ;
   if (!CP) Start = CS ;
   if (!CSS) End = C ;
   }

template <class T>
List<T> List<T>::operator + (const List<T>& L)
   {
   List<T> This=*this;
   This+=L ;
   return This ;
   }

template <class T>
List<T>& List<T>::operator += (const List<T>& L)
   {
   Node<T> *Lcur ;
   Lcur = L.Start ;
   while (Lcur)
      {
      Append(Lcur->Val) ;
      Lcur = Lcur->Next ;
      }
   return *this ;
   }

template <class T>
List<T>& List<T>::operator = (const List<T>& L)
   {
   Node<T> *Lcur ;
   Destroy() ;
   Lcur = L.Start ;
   while (Lcur)
      {
      Append(Lcur->Val) ;
      Lcur = Lcur->Next ;
      }
   return *this ;
   }

#if 0
template <class T>
void ListWS<T>::PushPos() 
{ 
  stack.Push(Current) ;
}
 
template <class T>
void ListWS<T>::PopPos() 
{ 
  Current = stack.Pop() ;
} 
#endif