diff --git a/general/src/pattern/ringbuffer.hpp b/general/src/pattern/ringbuffer.hpp new file mode 100644 index 0000000..dccd6de --- /dev/null +++ b/general/src/pattern/ringbuffer.hpp @@ -0,0 +1,37 @@ +#ifndef __RINGBUFFER__ +#define __RINGBUFFER__ + +/** + * author : caiyuzheng + * function: a ringbuffer class +*/ +#include +template class RingBuffer{ +public: + T At(uint64_t pos); + RingBuffer(uint64_t size); + ~RingBuffer(); + +protected: + T *mData; + uint64_t mSize; +}; + +template +RingBuffer::RingBuffer(uint64_t size) : + mData(nullptr), + mSize(0) { + mSize = size; + mData = new T[size]; +} +template +RingBuffer::~RingBuffer(){ + delete[] mData; +} + +template +T RingBuffer::At(uint64_t pos){ + return mData[pos]; +} + +#endif