From e76f9e8d93aef9d9d418ce8221a1615d53c2bf30 Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Sat, 25 Mar 2023 18:09:47 +0100 Subject: [PATCH] Implement custom barebones circular buffer --- Firmware/src/Util/CircularBuffer.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Firmware/src/Util/CircularBuffer.h diff --git a/Firmware/src/Util/CircularBuffer.h b/Firmware/src/Util/CircularBuffer.h new file mode 100644 index 0000000..c65f85e --- /dev/null +++ b/Firmware/src/Util/CircularBuffer.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include + +namespace util { +template class CircularBuffer { +public: + T &peek() { return buffer[index]; } + + /// @brief Warning: Does not deconstruct entry! If necessary use + /// etl::circular_buffer instead! + T &pop() { + return buffer[index]; + index = (index + 1) % buffer.size(); + } + +private: + etl::array buffer; + size_t index; +}; +} // namespace util