RingBuffer for Arduino (replacement of std::queue
, std::deque
or std::vector
).
AVR boards (like Uno and Mega) can't use std::queue
, std::deque
or std::vector
.
This library is simple (and limited) replacement of such STLs.
#include <RingBuffer.h>
RingBuffer<uint8_t, 4> buffer;
void setup()
{
buffer.push(1);
buffer.push(2);
buffer.push(3);
buffer.push(4);
for(size_t i = 0; i < buffer.size(); ++i)
Serial.println(buffer[i]);
buffer.pop();
for(auto& b : buffer)
Serial.println(b);
buffer.clear();
}
#include <RingBuffer.h>
struct Data { int number; String str; };
RingBuffer<Data, 3> buffer;
void setup()
{
buffer.push(Data({1, "one"}));
buffer.push(Data({2, "two"}));
Data data = {3, "three"};
buffer.push(data);
for(size_t i = 0; i < buffer.size(); ++i)
{
Serial.print(buffer[i].number);
Serial.print(", ");
Serial.println(buffer[i].str);
}
buffer.pop();
for(auto& b : buffer)
{
Serial.print(b.number);
Serial.print(", ");
Serial.println(b.str);
}
}
size_t capacity() const
size_t size() const
bool empty() const
const T* data() const
T* data()
void push(const T& data)
void push(T&& data)
void push_back(const T& data)
void push_back(T&& data)
void pop()
void pop_back()
const T& front() const
T& front()
const T& back() const
T& back()
const T& operator[] (uint8_t index) const
T& operator[] (uint8_t index)
const T* begin() const
T* begin()
const T* end() const
T* end()
void clear()
T* erase(T* p)
void resize(size_t sz)
void assign(const T* const first, const T* const end)
MIT