20namespace xrt::auxiliary::util {
23 template <
typename T,
size_t MaxSize>
class HistoryBufConstIterator;
24 template <
typename T,
size_t MaxSize>
class HistoryBufIterator;
104 size_t inner_index = 0;
106 return &internalBuffer[inner_index];
115 size_t inner_index = 0;
117 return &internalBuffer[inner_index];
144 cend() const noexcept;
148 begin() const noexcept;
152 end() const noexcept;
189 static_assert(MaxSize < (std::numeric_limits<
size_t>::max() >> 1), "Cannot use most significant bit");
191 using container_t = std::array<T, MaxSize>;
192 container_t internalBuffer{};
197template <
typename T,
size_t MaxSize>
199HistoryBuffer<T, MaxSize>::clear()
204template <
typename T,
size_t MaxSize>
208 return helper_.empty();
211template <
typename T,
size_t MaxSize>
215 return helper_.size();
218template <
typename T,
size_t MaxSize>
222 auto inner_index = helper_.push_back_location();
223 internalBuffer[inner_index] = element;
226template <
typename T,
size_t MaxSize>
230 size_t inner_index = 0;
231 if (helper_.age_to_inner_index(age, inner_index)) {
232 return &internalBuffer[inner_index];
236template <
typename T,
size_t MaxSize>
240 size_t inner_index = 0;
241 if (helper_.age_to_inner_index(age, inner_index)) {
242 return &internalBuffer[inner_index];
247template <
typename T,
size_t MaxSize>
251 size_t inner_index = 0;
252 if (helper_.index_to_inner_index(index, inner_index)) {
253 return &internalBuffer[inner_index];
258template <
typename T,
size_t MaxSize>
262 size_t inner_index = 0;
263 if (helper_.index_to_inner_index(index, inner_index)) {
264 return &internalBuffer[inner_index];
269template <
typename T,
size_t MaxSize>
274 throw std::logic_error(
"Cannot get the front of an empty buffer");
276 return internalBuffer[helper_.front_inner_index()];
279template <
typename T,
size_t MaxSize>
284 throw std::logic_error(
"Cannot get the front of an empty buffer");
286 return internalBuffer[helper_.front_inner_index()];
289template <
typename T,
size_t MaxSize>
294 throw std::logic_error(
"Cannot get the back of an empty buffer");
296 return internalBuffer[helper_.back_inner_index()];
299template <
typename T,
size_t MaxSize>
304 throw std::logic_error(
"Cannot get the back of an empty buffer");
306 return internalBuffer[helper_.back_inner_index()];
Stores some number of values in a ring buffer, overwriting the earliest-pushed-remaining element if o...
Definition: u_template_historybuf.hpp:38
void pop_front() noexcept
Logically remove the oldest element from the buffer.
Definition: u_template_historybuf.hpp:80
const T * get_at_clamped_age(size_t age) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: u_template_historybuf.hpp:113
bool empty() const noexcept
Is the buffer empty?
Definition: u_template_historybuf.hpp:206
bool pop_back() noexcept
Logically remove the newest element from the buffer.
Definition: u_template_historybuf.hpp:67
T * get_at_index(size_t index) noexcept
Use a value at a given index, where 0 is the least-recent value still stored, index 1 follows it,...
Definition: u_template_historybuf.hpp:249
const_iterator end() const noexcept
Get a "past the end" (past the newest) const iterator.
Definition: u_template_historybuf_const_iterator.inl:251
const_iterator cbegin() const noexcept
Get a const iterator for the oldest element.
Definition: u_template_historybuf_const_iterator.inl:227
T & back()
Gets a reference to the back (newest) element in the buffer.
Definition: u_template_historybuf.hpp:291
const T * get_at_index(size_t index) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: u_template_historybuf.hpp:260
size_t size() const noexcept
How many elements are in the buffer?
Definition: u_template_historybuf.hpp:213
const T * get_at_age(size_t age) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: u_template_historybuf.hpp:238
const_iterator cend() const noexcept
Get a "past the end" (past the newest) const iterator.
Definition: u_template_historybuf_const_iterator.inl:237
const_iterator begin() const noexcept
Get a const iterator for the oldest element.
Definition: u_template_historybuf_const_iterator.inl:244
void push_back(const T &element)
Put something at the back, overwriting whatever was at the front if necessary.
Definition: u_template_historybuf.hpp:220
T * get_at_clamped_age(size_t age) noexcept
Like get_at_age() but values larger than the oldest age are clamped.
Definition: u_template_historybuf.hpp:102
T & front()
Gets a reference to the front (oldest) element in the buffer.
Definition: u_template_historybuf.hpp:271
T * get_at_age(size_t age) noexcept
Use a value at a given age, where age 0 is the most recent value, age 1 precedes it,...
Definition: u_template_historybuf.hpp:228
Class template for const_iterator for HistoryBuffer.
Definition: u_template_historybuf_const_iterator.inl:29
Class template for iterator for HistoryBuffer.
Definition: u_template_historybuf_iterator.inl:29
All the bookkeeping for adapting a fixed-size array to a ring buffer.
Definition: u_template_historybuf_impl_helpers.hpp:46
bool pop_back() noexcept
Record the logical removal of the back element, if any.
Definition: u_template_historybuf_impl_helpers.hpp:217
void pop_front() noexcept
Record the logical removal of the front element, if any.
Definition: u_template_historybuf_impl_helpers.hpp:210
bool clamped_age_to_inner_index(size_t age, size_t &out_inner_idx) const noexcept
Get the inner index for a given age, clamping it if out of bounds.
Definition: u_template_historybuf_impl_helpers.hpp:175
A template class to serve as the base of iterator and const_iterator types for things with "random ac...
const_iterator details for ring buffer
All the "element-type-independent" code (helper objects, base classes) for a ringbuffer implementatio...
iterator details for ring buffer