添加ringbuffer的模板类
parent
2cf452ef79
commit
eed3fe05bd
|
@ -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
|
Loading…
Reference in New Issue