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
18
20
22template <class T>
24{
25public:
26
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
43private:
44
46 T* _elem;
48 WEMQueueElement<T>* _next;
49
50};
51
53
57template <class T>
59{
60public:
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
84private:
85
87 unsigned int _size;
89 WEMQueueElement<T>* _head;
91 WEMQueueElement<T>* _tail;
92
93};
94
97
98template <class T>
100{
101 _elem = NULL;
102 _next = NULL;
103}
104
106
107template <class T>
109{
110 _elem = elem;
111 _next = nullptr;
112}
113
115
116template <class T>
118{
119 _elem = nullptr;
120 _next = nullptr;
121}
122
124
125template <class T>
127{
128 _next = next;
129}
130
132
133template <class T>
135{
136 _head = _tail = NULL;
137
138 _size = 0;
139}
140
142
143template <class T>
145{
148
149 _head = newElement;
150 _tail = newElement;
151
152 _size = 1;
153}
154
156
157template <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
176template <class T>
178{
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
197template <class T>
199{
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
218template <class T>
220{
221 WEMQueueElement<T>* dHead = _head;
222
223 _head = dHead->getNextQueueElement();
224 delete dHead;
225 dHead = nullptr;
226 _size --;
227}
228
230
@ T
The WEMQueueElement represents an element of a single linked list.
Definition WEMQueue.h:24
const T * get() const
Returns the pointer to this element.
Definition WEMQueue.h:37
T * get()
Returns the pointer to this element.
Definition WEMQueue.h:35
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
WEMQueueElement< T > * getHead() const
Returns the head element of the queue.
Definition WEMQueue.h:79
unsigned int getSize() const
Returns the number of elements in the queue.
Definition WEMQueue.h:77
Target mlrange_cast(Source arg)
Generic version of checked ML casts.