3template <
typename T, plUInt32 C>
6 m_pElements = GetStaticArray();
11template <
typename T, plUInt32 C>
14 m_pElements = GetStaticArray();
21template <
typename T, plUInt32 C>
27template <
typename T, plUInt32 C>
32 for (plUInt32 i = 0; i < rhs.
GetCount(); ++i)
36template <
typename T, plUInt32 C>
42 for (plUInt32 i = 0; i < m_uiCount; ++i)
44 if ((*
this)[i] != rhs[i])
51template <
typename T, plUInt32 C>
54 PL_ASSERT_DEV(CanAppend(),
"The ring-buffer is full, no elements can be appended before removing one.");
56 const plUInt32 uiLastElement = (m_uiFirstElement + m_uiCount) % C;
62template <
typename T, plUInt32 C>
65 PL_ASSERT_DEV(CanAppend(),
"The ring-buffer is full, no elements can be appended before removing one.");
67 const plUInt32 uiLastElement = (m_uiFirstElement + m_uiCount) % C;
73template <
typename T, plUInt32 C>
76 PL_ASSERT_DEV(!IsEmpty(),
"The ring-buffer is empty, cannot peek at the last element.");
78 const plUInt32 uiLastElement = (m_uiFirstElement + m_uiCount - 1) % C;
79 return m_pElements[uiLastElement];
82template <
typename T, plUInt32 C>
85 PL_ASSERT_DEV(!IsEmpty(),
"The ring-buffer is empty, cannot peek at the last element.");
87 const plUInt32 uiLastElement = (m_uiFirstElement + m_uiCount - 1) % C;
88 return m_pElements[uiLastElement];
91template <
typename T, plUInt32 C>
94 PL_ASSERT_DEV(m_uiCount >= uiElements,
"The ring-buffer contains {0} elements, cannot remove {1} elements from it.", m_uiCount, uiElements);
96 while (uiElements > 0)
100 m_uiFirstElement %= C;
107template <
typename T, plUInt32 C>
110 PL_ASSERT_DEV(!IsEmpty(),
"The ring-buffer is empty, cannot peek at the first element.");
112 return m_pElements[m_uiFirstElement];
115template <
typename T, plUInt32 C>
118 PL_ASSERT_DEV(!IsEmpty(),
"The ring-buffer is empty, cannot peek at the first element.");
120 return m_pElements[m_uiFirstElement];
123template <
typename T, plUInt32 C>
126 PL_ASSERT_DEBUG(uiIndex < m_uiCount,
"The ring-buffer only has {0} elements, cannot access element {1}.", m_uiCount, uiIndex);
128 return m_pElements[(m_uiFirstElement + uiIndex) % C];
131template <
typename T, plUInt32 C>
134 PL_ASSERT_DEBUG(uiIndex < m_uiCount,
"The ring-buffer only has {0} elements, cannot access element {1}.", m_uiCount, uiIndex);
136 return m_pElements[(m_uiFirstElement + uiIndex) % C];
139template <
typename T, plUInt32 C>
145template <
typename T, plUInt32 C>
148 return m_uiCount == 0;
151template <
typename T, plUInt32 C>
154 return (m_uiCount + uiElements) <= C;
157template <
typename T, plUInt32 C>
164template <
typename T, plUInt32 C>
167 return reinterpret_cast<T*
>(m_Data);
static void CopyConstruct(Destination *pDestination, const Source ©, size_t uiCount=1)
Constructs uiCount objects of type T in a raw buffer at pDestination, by creating uiCount copies of c...
static void MoveConstruct(T *pDestination, T &&source)
Constructs an object of type T in a raw buffer at pDestination, by using move construction from sourc...
static void Destruct(T *pDestination, size_t uiCount=1)
Destructs uiCount objects of type T at pDestination.
A ring-buffer container that will use a static array of a given capacity to cycle through elements.
Definition StaticRingBuffer.h:10
void Clear()
Destructs all elements in the ring-buffer.
Definition StaticRingBuffer_inl.h:158
plUInt32 GetCount() const
Returns the number of elements that are currently in the ring-buffer.
Definition StaticRingBuffer_inl.h:140
void PushBack(const T &element)
Appends an element at the end of the ring-buffer. Asserts that CanAppend() is true.
Definition StaticRingBuffer_inl.h:52
const T & PeekFront() const
Accesses the oldest element in the ring-buffer.
Definition StaticRingBuffer_inl.h:108
bool CanAppend(plUInt32 uiElements=1)
Returns true, if the ring-buffer can store at least uiElements additional elements.
Definition StaticRingBuffer_inl.h:152
void PopFront(plUInt32 uiElements=1)
Removes the oldest element from the ring-buffer.
Definition StaticRingBuffer_inl.h:92
void operator=(const plStaticRingBuffer< T, Capacity > &rhs)
Copies the content from rhs into this ring-buffer.
Definition StaticRingBuffer_inl.h:28
T & PeekBack()
Accesses the latest element in the ring-buffer.
Definition StaticRingBuffer_inl.h:74
const T & operator[](plUInt32 uiIndex) const
Accesses the n-th element in the ring-buffer.
Definition StaticRingBuffer_inl.h:124
bool IsEmpty() const
Returns true if the ring-buffer currently contains no elements.
Definition StaticRingBuffer_inl.h:146
bool operator==(const plStaticRingBuffer< T, Capacity > &rhs) const
Compares two ring-buffers for equality.
Definition StaticRingBuffer_inl.h:37
plStaticRingBuffer()
Constructs an empty ring-buffer.
Definition StaticRingBuffer_inl.h:4
~plStaticRingBuffer()
Destructs all remaining elements.
Definition StaticRingBuffer_inl.h:22