Files
ESP8266lib/data/LinearBuffer.h
kazu d028b79325 added data structures
added audio support
added rfid support
added spi support
2017-03-12 13:02:06 +01:00

60 lines
914 B
C++

#ifndef LINEARBUFFER_H
#define LINEARBUFFER_H
template <typename Scalar, int _size> class LinearBuffer {
private:
Scalar _data[_size];
uint16_t head = 0;
public:
void add(const Scalar value) {
if (head >= _size) {return;}
_data[head] = value;
++head;
}
/** get the number of used entries */
uint16_t getNumUsed() const {
return head;
}
/** get the number of used bytes */
uint32_t getBytesUsed() const {
return getNumUsed() * sizeof(Scalar);
}
uint16_t size() const {
return _size;
}
/** set the buffer to empty */
void reset() {
head = 0;
}
const Scalar* data() const {
return _data;
}
/** constant array access */
const Scalar& operator [] (const size_t idx) const {
return _data[idx];
}
/** true if the buffer is currently empty */
bool isEmpty() const {
return head == 0;
}
bool isFull() const {
return head >= size;
}
};
#endif // LINEARBUFFER_H