MeVisLab Toolbox Reference
WEMQueue.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #pragma once
14 
15 #include "MLWEMIncludes.h"
16 
17 ML_START_NAMESPACE
18 
20 
22 template <class T>
24 {
25 public:
26 
31  WEMQueueElement(T* elem);
33  ~WEMQueueElement();
35  inline T* get() { return _elem; }
37  inline const T* get() const { return get(); }
39  inline WEMQueueElement<T>* getNextQueueElement() { return _next; }
41  void setNextQueueElement(WEMQueueElement<T> *next);
42 
43 private:
44 
46  T* _elem;
48  WEMQueueElement<T>* _next;
49 
50 };
51 
53 
57 template <class T>
58 class WEMQueue
59 {
60 public:
61 
63  WEMQueue();
67  WEMQueue(T* elem);
69  ~WEMQueue();
71  void append(T* elem);
73  void prepend(T* elem);
75  void popFront();
77  inline unsigned int getSize() const { return _size; };
79  inline WEMQueueElement<T>* getHead() const { return _head; };
81  inline WEMQueueElement<T>* getTail() const { return _tail;};
82 
83 
84 private:
85 
87  unsigned int _size;
89  WEMQueueElement<T>* _head;
91  WEMQueueElement<T>* _tail;
92 
93 };
94 
97 
98 template <class T>
100 {
101  _elem = NULL;
102  _next = NULL;
103 }
104 
106 
107 template <class T>
109 {
110  _elem = elem;
111  _next = nullptr;
112 }
113 
115 
116 template <class T>
118 {
119  _elem = nullptr;
120  _next = nullptr;
121 }
122 
124 
125 template <class T>
127 {
128  _next = next;
129 }
130 
132 
133 template <class T>
135 {
136  _head = _tail = NULL;
137 
138  _size = 0;
139 }
140 
142 
143 template <class T>
145 {
146  WEMQueueElement<T>* newElement = nullptr;
147  newElement = new WEMQueueElement<T>(elem);
148 
149  _head = newElement;
150  _tail = newElement;
151 
152  _size = 1;
153 }
154 
156 
157 template <class T>
159 {
160  if (_size > 0)
161  {
162  WEMQueueElement<T>* tHead = _head;
163 
164  while (tHead)
165  {
166  _head = tHead->getNextQueueElement();
167  delete tHead;
168  tHead = nullptr;
169  tHead = _head;
170  }
171  }
172 }
173 
175 
176 template <class T>
178 {
179  WEMQueueElement<T>* newElement = nullptr;
180  newElement = new WEMQueueElement<T>(elem);
181 
182  if (_size > 0)
183  {
184  _tail->setNextQueueElement(newElement);
185  _tail = newElement;
186  }
187  else
188  {
189  _head = newElement;
190  _tail = newElement;
191  }
192  _size ++;
193 }
194 
196 
197 template <class T>
199 {
200  WEMQueueElement<T>* newElement = nullptr;
201  newElement = new WEMQueueElement<T>(elem);
202 
203  if (_size > 0)
204  {
205  newElement->setNextQueueElement(_head);
206  _head = newElement;
207  }
208  else
209  {
210  _head = newElement;
211  _tail = newElement;
212  }
213  _size ++;
214 }
215 
217 
218 template <class T>
220 {
221  WEMQueueElement<T>* dHead = _head;
222 
223  _head = dHead->getNextQueueElement();
224  delete dHead;
225  dHead = nullptr;
226  _size --;
227 }
228 
230 
231 ML_END_NAMESPACE
@ T
Definition: SoKeyGrabber.h:71
The WEMQueueElement represents an element of a single linked list.
Definition: WEMQueue.h:24
T * get()
Returns the pointer to this element.
Definition: WEMQueue.h:35
void setNextQueueElement(WEMQueueElement< T > *next)
Sets the next queue element to the given one.
Definition: WEMQueue.h:126
const T * get() const
Returns the pointer to this element.
Definition: WEMQueue.h:37
WEMQueueElement< T > * getNextQueueElement()
Return the next element in the queue.
Definition: WEMQueue.h:39
The WEMQueue is a single linked list with pointers to its head and tail elements.
Definition: WEMQueue.h:59
WEMQueueElement< T > * getTail() const
Returns the tail element of the queue.
Definition: WEMQueue.h:81
unsigned int getSize() const
Returns the number of elements in the queue.
Definition: WEMQueue.h:77
WEMQueueElement< T > * getHead() const
Returns the head element of the queue.
Definition: WEMQueue.h:79