MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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> class WEMQueueElement
23{
24public:
33 inline T* get()
34 {
35 return _elem;
36 }
38 inline const T* get() const
39 {
40 return get();
41 }
44 {
45 return _next;
46 }
48 void setNextQueueElement(WEMQueueElement<T>* next);
49
50private:
52 T* _elem;
54 WEMQueueElement<T>* _next;
55};
56
58
62template <class T> class WEMQueue
63{
64public:
66 WEMQueue();
70 WEMQueue(T* elem);
72 ~WEMQueue();
74 void append(T* elem);
76 void prepend(T* elem);
78 void popFront();
80 inline unsigned int getSize() const
81 {
82 return _size;
83 };
86 {
87 return _head;
88 };
91 {
92 return _tail;
93 };
94
95
96private:
98 unsigned int _size;
100 WEMQueueElement<T>* _head;
102 WEMQueueElement<T>* _tail;
103};
104
107
109{
110 _elem = NULL;
111 _next = NULL;
112}
113
115
117{
118 _elem = elem;
119 _next = nullptr;
120}
121
123
125{
126 _elem = nullptr;
127 _next = nullptr;
128}
129
131
133{
134 _next = next;
135}
136
138
139template <class T> WEMQueue<T>::WEMQueue()
140{
141 _head = _tail = NULL;
142
143 _size = 0;
144}
145
147
148template <class T> WEMQueue<T>::WEMQueue(T* elem)
149{
152
153 _head = newElement;
154 _tail = newElement;
155
156 _size = 1;
157}
158
160
161template <class T> WEMQueue<T>::~WEMQueue()
162{
163 if (_size > 0) {
164 WEMQueueElement<T>* tHead = _head;
165
166 while (tHead) {
167 _head = tHead->getNextQueueElement();
168 delete tHead;
169 tHead = nullptr;
170 tHead = _head;
171 }
172 }
173}
174
176
177template <class T> void WEMQueue<T>::append(T* elem)
178{
181
182 if (_size > 0) {
183 _tail->setNextQueueElement(newElement);
184 _tail = newElement;
185 }
186 else {
187 _head = newElement;
188 _tail = newElement;
189 }
190 _size++;
191}
192
194
195template <class T> void WEMQueue<T>::prepend(T* elem)
196{
199
200 if (_size > 0) {
201 newElement->setNextQueueElement(_head);
202 _head = newElement;
203 }
204 else {
205 _head = newElement;
206 _tail = newElement;
207 }
208 _size++;
209}
210
212
213template <class T> void WEMQueue<T>::popFront()
214{
215 WEMQueueElement<T>* dHead = _head;
216
217 _head = dHead->getNextQueueElement();
218 delete dHead;
219 dHead = nullptr;
220 _size--;
221}
222
224
@ T
The WEMQueueElement represents an element of a single linked list.
Definition WEMQueue.h:23
const T * get() const
Returns the pointer to this element.
Definition WEMQueue.h:38
T * get()
Returns the pointer to this element.
Definition WEMQueue.h:33
WEMQueueElement< T > * getNextQueueElement()
Return the next element in the queue.
Definition WEMQueue.h:43
The WEMQueue is a single linked list with pointers to its head and tail elements.
Definition WEMQueue.h:63
WEMQueueElement< T > * getTail() const
Returns the tail element of the queue.
Definition WEMQueue.h:90
WEMQueueElement< T > * getHead() const
Returns the head element of the queue.
Definition WEMQueue.h:85
unsigned int getSize() const
Returns the number of elements in the queue.
Definition WEMQueue.h:80
Target mlrange_cast(Source arg)
Generic version of checked ML casts.