98 size_t size()
const {
return m_length; }
108 const T&
front()
const {
return (*
this)[0]; }
116 T&
back() {
return m_data[(m_front + m_length - 1) % m_data.size()]; }
125 return m_data[(m_front + m_length - 1) % m_data.size()];
134 if (m_data.size() == 0) {
138 m_front = ModuloDec(m_front);
140 m_data[m_front] =
value;
142 if (m_length < m_data.size()) {
153 if (m_data.size() == 0) {
157 m_data[(m_front + m_length) % m_data.size()] =
value;
159 if (m_length < m_data.size()) {
163 m_front = ModuloInc(m_front);
173 template <
class... Args>
175 if (m_data.size() == 0) {
179 m_front = ModuloDec(m_front);
181 m_data[m_front] = T{args...};
183 if (m_length < m_data.size()) {
194 template <
class... Args>
196 if (m_data.size() == 0) {
200 m_data[(m_front + m_length) % m_data.size()] = T{args...};
202 if (m_length < m_data.size()) {
206 m_front = ModuloInc(m_front);
217 T& temp = m_data[m_front];
218 m_front = ModuloInc(m_front);
231 return m_data[(m_front + m_length) % m_data.size()];
251 return m_data[(m_front +
index) % m_data.size()];
258 return m_data[(m_front +
index) % m_data.size()];
262 std::vector<T> m_data;
275 size_t ModuloInc(
size_t index) {
return (index + 1) % m_data.size(); }
282 size_t ModuloDec(
size_t index) {
284 return m_data.size() - 1;
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
Definition: circular_buffer.h:54
std::ptrdiff_t difference_type
Definition: circular_buffer.h:58
const_iterator & operator++()
Definition: circular_buffer.h:65
const_reference operator*() const
Definition: circular_buffer.h:75
T value_type
Definition: circular_buffer.h:57
bool operator==(const const_iterator &) const =default
std::forward_iterator_tag iterator_category
Definition: circular_buffer.h:56
const T & const_reference
Definition: circular_buffer.h:60
const_iterator(const circular_buffer *buffer, size_t index)
Definition: circular_buffer.h:62
T * pointer
Definition: circular_buffer.h:59
const_iterator operator++(int)
Definition: circular_buffer.h:69
Definition: circular_buffer.h:26
iterator & operator++()
Definition: circular_buffer.h:37
bool operator==(const iterator &) const =default
reference operator*()
Definition: circular_buffer.h:47
std::ptrdiff_t difference_type
Definition: circular_buffer.h:30
iterator operator++(int)
Definition: circular_buffer.h:41
T & reference
Definition: circular_buffer.h:32
T * pointer
Definition: circular_buffer.h:31
iterator(circular_buffer *buffer, size_t index)
Definition: circular_buffer.h:34
std::forward_iterator_tag iterator_category
Definition: circular_buffer.h:28
T value_type
Definition: circular_buffer.h:29
This is a simple circular buffer so we don't need to "bucket brigade" copy old values.
Definition: circular_buffer.h:17
size_t size() const
Returns number of elements in buffer.
Definition: circular_buffer.h:98
void emplace_back(Args &&... args)
Push a new value onto the back of the buffer that is constructed with the provided constructor argume...
Definition: circular_buffer.h:195
iterator end()
Definition: circular_buffer.h:83
iterator begin()
Definition: circular_buffer.h:82
T pop_back()
Pop value at back of buffer.
Definition: circular_buffer.h:229
circular_buffer & operator=(const circular_buffer &)=default
void emplace_front(Args &&... args)
Push a new value onto the front of the buffer that is constructed with the provided constructor argum...
Definition: circular_buffer.h:174
circular_buffer & operator=(circular_buffer &&)=default
T & operator[](size_t index)
Definition: circular_buffer.h:250
void push_front(T value)
Push a new value onto the front of the buffer.
Definition: circular_buffer.h:133
circular_buffer(size_t size)
Definition: circular_buffer.h:19
const_iterator cbegin() const
Definition: circular_buffer.h:90
void resize(size_t size)
Resizes internal buffer to given size.
Definition: circular_buffer.inc:15
circular_buffer(const circular_buffer &)=default
circular_buffer(circular_buffer &&)=default
void reset()
Empties internal buffer.
Definition: circular_buffer.h:242
void push_back(T value)
Push a new value onto the back of the buffer.
Definition: circular_buffer.h:152
T pop_front()
Pop value at front of buffer.
Definition: circular_buffer.h:216
const T & operator[](size_t index) const
Definition: circular_buffer.h:257
const T & back() const
Returns value at back of buffer.
Definition: circular_buffer.h:124
const_iterator end() const
Definition: circular_buffer.h:86
const_iterator begin() const
Definition: circular_buffer.h:85
T & front()
Returns value at front of buffer.
Definition: circular_buffer.h:103
const_iterator cend() const
Definition: circular_buffer.h:91
const T & front() const
Returns value at front of buffer.
Definition: circular_buffer.h:108
T & back()
Returns value at back of buffer.
Definition: circular_buffer.h:116
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18