Monado OpenXR Runtime
xrt::auxiliary::util::HistoryBuffer< T, MaxSize > Class Template Reference

Stores some number of values in a ring buffer, overwriting the earliest-pushed-remaining element if out of room. More...

#include <util/u_template_historybuf.hpp>

Public Types

using iterator = detail::HistoryBufIterator< T, MaxSize >
 
using const_iterator = detail::HistoryBufConstIterator< T, MaxSize >
 

Public Member Functions

bool empty () const noexcept
 Is the buffer empty? More...
 
size_t size () const noexcept
 How many elements are in the buffer? More...
 
void push_back (const T &element)
 Put something at the back, overwriting whatever was at the front if necessary. More...
 
bool pop_back () noexcept
 Logically remove the newest element from the buffer. More...
 
void pop_front () noexcept
 Logically remove the oldest element from the buffer. More...
 
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, etc. More...
 
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 only in what argument(s) it accepts. More...
 
T * get_at_clamped_age (size_t age) noexcept
 Like get_at_age() but values larger than the oldest age are clamped. More...
 
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 only in what argument(s) it accepts. More...
 
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, etc. More...
 
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 only in what argument(s) it accepts. More...
 
const_iterator cbegin () const noexcept
 Get a const iterator for the oldest element. More...
 
const_iterator cend () const noexcept
 Get a "past the end" (past the newest) const iterator. More...
 
const_iterator begin () const noexcept
 Get a const iterator for the oldest element. More...
 
const_iterator end () const noexcept
 Get a "past the end" (past the newest) const iterator. More...
 
iterator begin () noexcept
 Get an iterator for the oldest element. More...
 
iterator end () noexcept
 Get a "past the end" (past the newest) iterator. More...
 
T & front ()
 Gets a reference to the front (oldest) element in the buffer. More...
 
const T & front () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
T & back ()
 Gets a reference to the back (newest) element in the buffer. More...
 
const T & back () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void clear ()
 

Detailed Description

template<typename T, size_t MaxSize>
class xrt::auxiliary::util::HistoryBuffer< T, MaxSize >

Stores some number of values in a ring buffer, overwriting the earliest-pushed-remaining element if out of room.

Note this should only store value types, since there's no way to destroy elements other than overwriting them, and all elements are default-initialized upon construction of the container.

Note
Unlike m_relation_history which is based on this, this data structure is not inherently safe for concurrent/threaded use: there are no locks built-in.

Member Function Documentation

◆ back() [1/2]

template<typename T , size_t MaxSize>
T & xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::back
inline

Gets a reference to the back (newest) element in the buffer.

Exceptions
std::logic_errorif buffer is empty

◆ back() [2/2]

template<typename T , size_t MaxSize>
const T & xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::back
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ begin() [1/2]

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::const_iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::begin
inlinenoexcept

Get a const iterator for the oldest element.

◆ begin() [2/2]

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::begin
inlinenoexcept

Get an iterator for the oldest element.

◆ cbegin()

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::const_iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::cbegin
inlinenoexcept

Get a const iterator for the oldest element.

◆ cend()

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::const_iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::cend
inlinenoexcept

Get a "past the end" (past the newest) const iterator.

◆ empty()

template<typename T , size_t MaxSize>
bool xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::empty
inlinenoexcept

Is the buffer empty?

◆ end() [1/2]

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::const_iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::end
inlinenoexcept

Get a "past the end" (past the newest) const iterator.

◆ end() [2/2]

template<typename T , size_t MaxSize>
HistoryBuffer< T, MaxSize >::iterator xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::end
inlinenoexcept

Get a "past the end" (past the newest) iterator.

◆ front() [1/2]

template<typename T , size_t MaxSize>
T & xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::front
inline

Gets a reference to the front (oldest) element in the buffer.

Exceptions
std::logic_errorif buffer is empty

◆ front() [2/2]

template<typename T , size_t MaxSize>
const T & xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::front
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_at_age() [1/2]

template<typename T , size_t MaxSize>
const T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_age ( size_t  age) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_at_age() [2/2]

template<typename T , size_t MaxSize>
T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_age ( size_t  age)
inlinenoexcept

Use a value at a given age, where age 0 is the most recent value, age 1 precedes it, etc.

(reverse chronological order)

Out of bounds accesses will return nullptr.

◆ get_at_clamped_age() [1/2]

template<typename T , size_t MaxSize>
const T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_clamped_age ( size_t  age) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

References xrt::auxiliary::util::detail::RingBufferHelper::clamped_age_to_inner_index().

◆ get_at_clamped_age() [2/2]

template<typename T , size_t MaxSize>
T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_clamped_age ( size_t  age)
inlinenoexcept

Like get_at_age() but values larger than the oldest age are clamped.

References xrt::auxiliary::util::detail::RingBufferHelper::clamped_age_to_inner_index().

◆ get_at_index() [1/2]

template<typename T , size_t MaxSize>
const T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_index ( size_t  index) const
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ get_at_index() [2/2]

template<typename T , size_t MaxSize>
T * xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::get_at_index ( size_t  index)
inlinenoexcept

Use a value at a given index, where 0 is the least-recent value still stored, index 1 follows it, etc.

(chronological order)

Out of bounds accesses will return nullptr.

◆ pop_back()

template<typename T , size_t MaxSize>
bool xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::pop_back ( )
inlinenoexcept

Logically remove the newest element from the buffer.

This is permitted to invalidate iterators. They won't be poisoned, but they will return something you don't expect.

Returns
true if there was something to pop.

References xrt::auxiliary::util::detail::RingBufferHelper::pop_back().

◆ pop_front()

template<typename T , size_t MaxSize>
void xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::pop_front ( )
inlinenoexcept

Logically remove the oldest element from the buffer.

The value still remains in the backing container until overwritten, but it isn't accessible anymore.

This invalidates iterators. They won't be poisoned, but they will return something you don't expect.

References xrt::auxiliary::util::detail::RingBufferHelper::pop_front().

◆ push_back()

template<typename T , size_t MaxSize>
void xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::push_back ( const T &  element)
inline

Put something at the back, overwriting whatever was at the front if necessary.

This is permitted to invalidate iterators. They won't be poisoned, but they will return something you don't expect.

◆ size()

template<typename T , size_t MaxSize>
size_t xrt::auxiliary::util::HistoryBuffer< T, MaxSize >::size
inlinenoexcept

How many elements are in the buffer?


The documentation for this class was generated from the following files: