11 #ifndef __UT_RingBuffer__
12 #define __UT_RingBuffer__
39 { insertImpl(
id, data); }
41 { insertImpl(
id, std::move(
data)); }
55 T data = std::move(myData(myFirst));
76 int size()
const {
return myLastId - myFirstId + 1; }
86 return myData(idIndex(
id));
93 const T &
front()
const {
return myData(myFirst); }
95 const T &
back()
const {
return myData(myLast); }
96 int backId()
const {
return myLastId; }
101 void growIfNeeded(
int number)
103 if (
entries() + number > myData.entries())
107 void growData(
int number);
108 int idIndex(
int id)
const
109 {
return (
id - myFirstId + myFirst) % myData.entries(); }
111 template <
typename S>
112 void insertImpl(
int id,
S &&
data);
113 template <
typename S>
114 int pushImpl(
S &&
data);
129 template <
typename T>
130 template <
typename S>
136 if (myLast >= myData.entries())
139 myData(myLast) = std::forward<S>(
data);
143 template <
typename T>
149 if (myFirst >= myData.entries())
154 template <
typename T>
161 myLast = myData.entries()-1;
SYS_NO_DISCARD_RESULT T popFirst()
T operator[](int id) const
void pop()
Pop a single element from the start of the buffer.
void insert(int id, T &&data)
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
#define SYS_NO_DISCARD_RESULT
void insert(int id, const T &data)
void popBack()
Pop a single element from the back of the buffer.
void clear()
Resets the buffer to an empty buffer with a 0 index.
const T & operator()(int id) const