8 #ifndef RINGBUFFER_HPP_ 9 #define RINGBUFFER_HPP_ 18 RingBuffer(
int numLevels,
int numItems, T initialValue = (T)0) {
20 mNumLevels = numLevels;
22 mBuffer.resize(numLevels);
23 for (
auto &b : mBuffer) {
24 b.resize(numItems, initialValue);
29 int getNumLevels() {
return mNumLevels; }
31 int getNumItems() {
return mNumItems; }
33 void newLevel() { mCurrentLevel = (mNumLevels + mCurrentLevel - 1) % mNumLevels; }
35 T *getBuffer(
int level,
int offset) {
return &mBuffer[levelIndex(level)].at(offset); }
37 T *getBuffer(
int offset) {
return &mBuffer[mCurrentLevel].at(offset); }
39 T *getBuffer() {
return mBuffer[mCurrentLevel].data(); }
42 int levelIndex(
int level)
const {
return ((level + mCurrentLevel) % mNumLevels); }
48 std::vector<std::vector<T>> mBuffer;