DIY Auto-Correlator 1.0
Auto-Correlator Card implementation using Teensy 4.x microcontrollers.
simpler_circular_buffer.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3
4template <typename Type, size_t MaxSize>
6{
7
8private:
9
10 Type buffer[MaxSize] = {0};
11 size_t head = 0;
12 size_t tail = 0;
13
14public:
15
17 void reset() __attribute__((always_inline))
18 {
19 head = 0;
20 tail = 0;
21 }
22
24 void push_back(const Type datum) __attribute__((flatten))
25 {
26 //Advance Pointer
27 buffer[tail] = datum;
28 tail = (tail + 1 ) % MaxSize;
29
30 }
31
33 Type operator[] (const size_t index) const __attribute__((always_inline))
34 {
35 return buffer[index % MaxSize];
36 }
37
38};
Definition: simpler_circular_buffer.hpp:6
Type buffer[MaxSize]
Definition: simpler_circular_buffer.hpp:10
size_t tail
Index / Pointer of the first element of the buffer.
Definition: simpler_circular_buffer.hpp:12
Type operator[](const size_t index) const __attribute__((always_inline))
Random access operator can be used to retrive the nth element in the buffer at any state of the buffe...
Definition: simpler_circular_buffer.hpp:33
void reset() __attribute__((always_inline))
Index / Pointer to the last element of the buffer.
Definition: simpler_circular_buffer.hpp:17
size_t head
Fixed Size Buffer.
Definition: simpler_circular_buffer.hpp:11
void push_back(const Type datum) __attribute__((flatten))
Adds a datum to the circular buffer.
Definition: simpler_circular_buffer.hpp:24