21 template<
class Thing,
int max_size>
30 template<
class Thing,
int max_size>
40 template<
class Thing,
int max_size>
43 int diff = _in - _out;
44 return (diff >= 0) ? diff : max_size + 1 + diff;
52 template<
class Thing,
int max_size>
64 template<
class Thing,
int max_size>
68 return ((_in + 1) % (max_size + 1)) == _out;
76 template<
class Thing,
int max_size>
79 nassertr(!empty(), _array[0]);
88 template<
class Thing,
int max_size>
91 nassertr(!empty(), _array[0]);
100 template<
class Thing,
int max_size>
103 nassertr(!empty(), _array[0]);
104 return _array[(_out + n) % (max_size + 1)];
112 template<
class Thing,
int max_size>
115 nassertr(!empty(), _array[0]);
116 return _array[(_out + n) % (max_size + 1)];
123 template<
class Thing,
int max_size>
132 _array[_out] = Thing();
134 _out = (_out+1)%(max_size+1);
145 template<
class Thing,
int max_size>
148 nassertr(!empty(), _array[0]);
149 return _array[(_in + max_size) % (max_size + 1)];
157 template<
class Thing,
int max_size>
160 nassertr(!empty(), _array[0]);
161 return _array[(_in + max_size) % (max_size + 1)];
167 template<
class Thing,
int max_size>
172 <<
"Circular buffer is full; cannot add requests.\n";
175 _in = (_in+1)%(max_size+1);
182 template<
class Thing,
int max_size>
void push_back(const Thing &t)
Adds an item to the end of the buffer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool empty() const
Returns true if the buffer is empty.
const Thing & back() const
Returns a reference to the last item in the queue.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.