#ifndef RINGBUFFER_H
#define RINGBUFFER_H

#include "common/utils/Array.h"

template<typename T, uint N>
class RingBuffer final {
public:

    void write(const T& t) {
        data[writeIndex] = t;
        writeIndex = (writeIndex + 1) % N;
    }

    bool canRead() const {
        return writeIndex != readIndex;
    }

    T read() {
        T& t = data[readIndex];
        readIndex = (readIndex + 1) % N;
        return t;
    }

private:
    Array<T, N> data;
    uint writeIndex = 0;
    uint readIndex = 0;
};

#endif