Implement custom barebones circular buffer
This commit is contained in:
parent
48c2cdf97b
commit
d1f9e3d88c
1 changed files with 21 additions and 0 deletions
21
modules/control/Firmware/src/Util/CircularBuffer.h
Normal file
21
modules/control/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
|
Reference in a new issue