Implement custom barebones circular buffer
This commit is contained in:
parent
3ff75471f6
commit
e76f9e8d93
1 changed files with 21 additions and 0 deletions
21
Firmware/src/Util/CircularBuffer.h
Normal file
21
Firmware/src/Util/CircularBuffer.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <etl/array.h>
|
||||
|
||||
namespace util {
|
||||
template <typename T, size_t size> 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<T, size> buffer;
|
||||
size_t index;
|
||||
};
|
||||
} // namespace util
|
Loading…
Reference in a new issue