添加ringbuffer的模板类

master
zcy 2020-08-26 17:15:19 +08:00
parent 2cf452ef79
commit eed3fe05bd
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#ifndef __RINGBUFFER__
#define __RINGBUFFER__
/**
* author : caiyuzheng
* function: a ringbuffer class
*/
#include<stdint.h>
template <typename T> class RingBuffer{
public:
T At(uint64_t pos);
RingBuffer(uint64_t size);
~RingBuffer();
protected:
T *mData;
uint64_t mSize;
};
template<typename T>
RingBuffer<T>::RingBuffer(uint64_t size) :
mData(nullptr),
mSize(0) {
mSize = size;
mData = new T[size];
}
template<typename T>
RingBuffer<T>::~RingBuffer(){
delete[] mData;
}
template<typename T>
T RingBuffer<T>::At(uint64_t pos){
return mData[pos];
}
#endif