15 #include "pandabase.h" 16 #include "config_express.h" 24 template<
class Thing,
int max_size>
35 template<
class Thing,
int max_size>
49 template<
class Thing,
int max_size>
52 int diff = _in - _out;
53 return (diff >= 0) ? diff : max_size + 1 + diff;
64 template<
class Thing,
int max_size>
79 template<
class Thing,
int max_size>
83 return ((_in + 1) % (max_size + 1)) == _out;
94 template<
class Thing,
int max_size>
97 nassertr(!empty(), _array[0]);
109 template<
class Thing,
int max_size>
112 nassertr(!empty(), _array[0]);
123 template<
class Thing,
int max_size>
126 nassertr(!empty(), _array[0]);
127 return _array[(_out + n) % (max_size + 1)];
137 template<
class Thing,
int max_size>
140 nassertr(!empty(), _array[0]);
141 return _array[(_out + n) % (max_size + 1)];
150 template<
class Thing,
int max_size>
159 _array[_out] = Thing();
161 _out = (_out+1)%(max_size+1);
176 template<
class Thing,
int max_size>
179 nassertr(!empty(), _array[0]);
180 return _array[(_in + max_size) % (max_size + 1)];
192 template<
class Thing,
int max_size>
195 nassertr(!empty(), _array[0]);
196 return _array[(_in + max_size) % (max_size + 1)];
205 template<
class Thing,
int max_size>
210 <<
"Circular buffer is full; cannot add requests.\n";
213 _in = (_in+1)%(max_size+1);
222 template<
class Thing,
int max_size>
void push_back(const Thing &t)
Adds an item to the end of the buffer.
bool empty() const
Returns true if the buffer is empty.
const Thing & back() const
Returns a reference to the last item in the queue.
int size() const
Returns the number of items currently in the buffer.
bool full() const
Returns true if the buffer is full; if this is true, push_back() will fail.
void clear()
Removes all items from the queue.
void pop_front()
Removes the first item from the buffer.
This class implements a queue of some type via a circular buffer.
const Thing & operator[](int n) const
Returns the nth element in the buffer.
const Thing & front() const
Returns a reference to the first item in the queue.