Nebula
Loading...
Searching...
No Matches
arrayqueue.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/types.h"
15#include "util/array.h"
16
17//------------------------------------------------------------------------------
18namespace Util
19{
20template<class TYPE> class ArrayQueue
21{
22public:
24 ArrayQueue();
26 ArrayQueue(const ArrayQueue<TYPE>& rhs);
31
33 void operator=(const ArrayQueue<TYPE>& rhs);
35 void operator=(ArrayQueue<TYPE>&& rhs);
37 TYPE& operator[](IndexT index) const;
39 bool operator==(const ArrayQueue<TYPE>& rhs) const;
41 bool operator!=(const ArrayQueue<TYPE>& rhs) const;
43 void Reserve(SizeT num);
45 SizeT Size() const;
47 bool IsEmpty() const;
49 void Clear();
51 bool Contains(const TYPE& e) const;
53 void EraseIndex(const IndexT i);
54
56 void Enqueue(const TYPE& e);
58 TYPE Dequeue();
60 TYPE& Peek() const;
61
62protected:
64};
65
66//------------------------------------------------------------------------------
69template<class TYPE>
71{
72 // empty
73}
74
75//------------------------------------------------------------------------------
78template<class TYPE>
80{
81 this->queueArray = rhs.queueArray;
82}
83
84//------------------------------------------------------------------------------
87template<class TYPE>
89 queueArray(std::move(rhs.queueArray))
90{
91 // empty
92}
93
94//------------------------------------------------------------------------------
97template<class TYPE>
99{
100 this->queueArray = rhs;
101}
102
103//------------------------------------------------------------------------------
106template<class TYPE>
107void
109{
110 this->queueArray = rhs.queueArray;
111}
112
113//------------------------------------------------------------------------------
116template<class TYPE>
117void
119{
120 this->queueArray = std::move(rhs.queueArray);
121}
122
123//------------------------------------------------------------------------------
126template<class TYPE>
127TYPE&
129{
130 return this->queueArray[index];
131}
132
133//------------------------------------------------------------------------------
136template<class TYPE>
137bool
139{
140 return this->queueArray == rhs.queueArray;
141}
142
143//------------------------------------------------------------------------------
146template<class TYPE>
147bool
149{
150 return this->queueArray != rhs.queueArray;
151}
152
153//------------------------------------------------------------------------------
156template<class TYPE>
157bool
158ArrayQueue<TYPE>::Contains(const TYPE& e) const
159{
160 return (InvalidIndex != this->queueArray.FindIndex(e));
161}
162
163//------------------------------------------------------------------------------
166template<class TYPE>
167void
169{
170 this->queueArray.EraseIndex(i);
171}
172
173//------------------------------------------------------------------------------
176template<class TYPE>
177void
179{
180 this->queueArray.Clear();
181}
182
183//------------------------------------------------------------------------------
186template<class TYPE>
187void
189{
190 this->queueArray.Reserve(num);
191}
192
193//------------------------------------------------------------------------------
196template<class TYPE>
197SizeT
199{
200 return this->queueArray.Size();
201}
202
203//------------------------------------------------------------------------------
206template<class TYPE>
207bool
209{
210 return this->queueArray.IsEmpty();
211}
212
213//------------------------------------------------------------------------------
216template<class TYPE>
217void
219{
220 this->queueArray.Append(e);
221}
222
223//------------------------------------------------------------------------------
226template<class TYPE>
227TYPE
229{
230 TYPE e = this->queueArray.Front();
231 this->queueArray.EraseIndex(0);
232 return e;
233}
234
235//------------------------------------------------------------------------------
238template<class TYPE>
239TYPE&
241{
242 return this->queueArray.Front();
243}
244
245} // namespace Util
246//------------------------------------------------------------------------------
Nebula's dynamic array class.
Definition array.h:60
Definition arrayqueue.h:21
void Reserve(SizeT num)
increase capacity to fit N more elements into the queue
Definition arrayqueue.h:188
bool IsEmpty() const
return true if queue is empty
Definition arrayqueue.h:208
void EraseIndex(const IndexT i)
erase element at index
bool operator!=(const ArrayQueue< TYPE > &rhs) const
inequality operator
Definition arrayqueue.h:148
ArrayQueue()
constructor
Definition arrayqueue.h:70
void Clear()
remove all elements from the queue
Definition arrayqueue.h:178
void Enqueue(const TYPE &e)
add element to the back of the queue
Definition arrayqueue.h:218
TYPE & Peek() const
access to element at front of queue without removing it
Definition arrayqueue.h:240
SizeT Size() const
returns number of elements in the queue
Definition arrayqueue.h:198
ArrayQueue(const Array< TYPE > &rhs)
conversion constructor for array
Array< TYPE > queueArray
Definition arrayqueue.h:63
TYPE Dequeue()
remove the element from the front of the queue
Definition arrayqueue.h:228
TYPE & operator[](IndexT index) const
access element by index, 0 is the frontmost element (next to be dequeued)
Definition arrayqueue.h:128
bool Contains(const TYPE &e) const
return true if queue contains element
Definition arrayqueue.h:158
void operator=(const ArrayQueue< TYPE > &rhs)
assignment operator
Definition arrayqueue.h:108
bool operator==(const ArrayQueue< TYPE > &rhs) const
equality operator
Definition arrayqueue.h:138
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
Definition half.h:491
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48