47 void Add(
const TYPE& elm);
81template<
class TYPE>
void
84 #if NEBULA_BOUNDSCHECKS
92 this->elements =
new TYPE[c];
98template<
class TYPE>
void
105 if (0 != this->elements)
107 delete[] this->elements;
115template<
class TYPE>
void
118 #if NEBULA_BOUNDSCHECKS
122 this->size = rhs.
size;
126 for (i = 0; i < rhs.
Size(); i++)
173 this->size = rhs.size;
174 this->capacity = rhs.capacity;
175 this->headIndex = rhs.headIndex;
176 this->baseIndex = rhs.baseIndex;
177 this->elements = rhs.elements;
183 rhs.elements =
nullptr;
198template<
class TYPE>
void
209template<
class TYPE>
void
212 this->size = rhs.size;
213 this->capacity = rhs.capacity;
214 this->headIndex = rhs.headIndex;
215 this->baseIndex = rhs.baseIndex;
216 this->elements = rhs.elements;
222 rhs.elements =
nullptr;
228template<
class TYPE> TYPE&
231 #if NEBULA_BOUNDSCHECKS
232 n_assert(this->elements && (index < this->size));
234 IndexT absIndex = index + this->baseIndex;
235 if (absIndex >= this->capacity)
238 absIndex -= this->capacity;
240 return this->elements[absIndex];
246template<
class TYPE> TYPE&
255template<
class TYPE> TYPE&
258 #if NEBULA_BOUNDSCHECKS
261 return (*
this)[this->size - 1];
267template<
class TYPE>
bool
270 return (0 == this->size);
276template<
class TYPE>
void
287template<
class TYPE>
void
291 this->Allocate(newCapacity);
297template<
class TYPE>
SizeT
300 return this->capacity;
306template<
class TYPE>
SizeT
315template<
class TYPE>
void
318 #if NEBULA_BOUNDSCHECKS
323 this->elements[this->headIndex++] = elm;
326 if (this->headIndex >= this->capacity)
332 if (this->size == this->capacity)
335 if (this->baseIndex >= this->capacity)
356 for (i = 0; i < this->size; i++)
358 result.
Append((*
this)[i]);
371 return this->elements;
382 return this->elements;
Nebula's dynamic array class.
Definition array.h:60
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1334
A ring buffer stores up to a maximum number of elements in a circular fashion.
Definition ringbuffer.h:21
~RingBuffer()
destructor
Definition ringbuffer.h:190
void SetCapacity(SizeT newCapacity)
set capacity (clear previous content)
Definition ringbuffer.h:288
IndexT baseIndex
Definition ringbuffer.h:73
TYPE & Back() const
return reference to last element
Definition ringbuffer.h:256
RingBuffer(const RingBuffer< TYPE > &rhs)
copy constructor
Definition ringbuffer.h:160
TYPE * GetBuffer()
get real linear underlying buffer
Definition ringbuffer.h:368
void Add(const TYPE &elm)
add an element to the ring buffer
Definition ringbuffer.h:316
SizeT capacity
Definition ringbuffer.h:71
RingBuffer()
default constructor
Definition ringbuffer.h:136
void Reset()
reset ring buffer, just reset the head/base indices without calling destructors
Definition ringbuffer.h:277
RingBuffer(SizeT capacity)
constructor with size
Definition ringbuffer.h:150
void operator=(RingBuffer< TYPE > &&rhs)
mover operator
Definition ringbuffer.h:210
void Copy(const RingBuffer< TYPE > &src)
copy content
Definition ringbuffer.h:116
RingBuffer(RingBuffer< TYPE > &&rhs)
move constructor
Definition ringbuffer.h:171
TYPE & operator[](IndexT index) const
index operator
Definition ringbuffer.h:229
Array< TYPE > AsArray() const
return all values as array
Definition ringbuffer.h:352
TYPE & Front() const
return reference to first element
Definition ringbuffer.h:247
bool IsEmpty() const
return true if ring buffer is empty
Definition ringbuffer.h:268
SizeT size
Definition ringbuffer.h:72
void operator=(const RingBuffer< TYPE > &rhs)
assignment operator
Definition ringbuffer.h:199
void Delete()
delete content
Definition ringbuffer.h:99
TYPE * elements
Definition ringbuffer.h:75
IndexT headIndex
Definition ringbuffer.h:74
void Allocate(SizeT capacity)
allocate element buffer
Definition ringbuffer.h:82
SizeT Size() const
get number of elements in ring buffer
Definition ringbuffer.h:307
const TYPE * GetBuffer() const
get real linear underlying buffer
Definition ringbuffer.h:379
SizeT Capacity() const
get capacity
Definition ringbuffer.h:298
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48