wip: templated ring buffer

This commit is contained in:
2023-08-07 11:58:53 +04:00
parent 64fa5c9271
commit b02a5d2873
4 changed files with 137 additions and 2 deletions

25
inc/RingBuffer.h Normal file
View File

@@ -0,0 +1,25 @@
#pragma once
#include <cstddef>
template <typename T>
class RingBuffer
{
private:
T* m_items; /* data */
std::size_t m_head;
std::size_t m_tail;
bool m_is_full;
bool m_is_empty;
std::size_t m_size;
void advance_pointer();
void retreat_pointer();
public:
RingBuffer(std::size_t size);
~RingBuffer();
bool IsFull() { return m_is_full; }
bool IsEmpty() { return m_is_empty; }
std::size_t GetSize();
void Reset();
void Write(T* data, size_t count);
bool Read(T* output, size_t count);
void Print();
};