From 9651f66c4cb68be3816c25df4e2aef488f1a31ea Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Tue, 14 Jun 2022 12:22:12 +0100 Subject: [PATCH] a/util: Add clear() method to HistoryBuffer --- src/xrt/auxiliary/util/u_template_historybuf.hpp | 11 +++++++++++ .../util/u_template_historybuf_impl_helpers.hpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/xrt/auxiliary/util/u_template_historybuf.hpp b/src/xrt/auxiliary/util/u_template_historybuf.hpp index 73ae1bfef..c263b5e2d 100644 --- a/src/xrt/auxiliary/util/u_template_historybuf.hpp +++ b/src/xrt/auxiliary/util/u_template_historybuf.hpp @@ -178,6 +178,9 @@ public: const T & back() const; + void + clear(); + private: // Make sure all valid indices can be represented in a signed integer of the same size static_assert(MaxSize < (std::numeric_limits::max() >> 1), "Cannot use most significant bit"); @@ -187,6 +190,14 @@ private: detail::RingBufferHelper helper_{MaxSize}; }; + +template +void +HistoryBuffer::clear() +{ + helper_.clear(); +} + template inline bool HistoryBuffer::empty() const noexcept diff --git a/src/xrt/auxiliary/util/u_template_historybuf_impl_helpers.hpp b/src/xrt/auxiliary/util/u_template_historybuf_impl_helpers.hpp index 0d12d39f6..1f3ebd631 100644 --- a/src/xrt/auxiliary/util/u_template_historybuf_impl_helpers.hpp +++ b/src/xrt/auxiliary/util/u_template_historybuf_impl_helpers.hpp @@ -113,6 +113,9 @@ public: size_t back_inner_index() const noexcept; + void + clear(); + private: // Would be const, but that would mess up our ability to copy/move containers using this. size_t capacity_; @@ -135,6 +138,13 @@ private: }; +inline void +RingBufferHelper::clear() +{ + this->latest_inner_idx_ = 0; + this->length_ = 0; +} + inline size_t RingBufferHelper::front_impl_() const noexcept {