kgrams  0.1.0
CircularBuffer.h
1 #ifndef UTILS_H
2 #define UTILS_H
3 
4 template<class T>
6  size_t size_;
7  size_t pos_;
8  std::vector<T> stream_;
9 public:
10  CircularBuffer (size_t size, T init)
11  : size_(size), pos_(0), stream_(size, init) {}
12  void lshift () { pos_ = (pos_ + 1) % size_; }
13  void rshift () { pos_ = pos_ > 0 ? pos_ - 1 : size_ - 1; }
14  const T & read () { return stream_[pos_]; }
15  void write (const T & t) { stream_[pos_] = t; }
16 };
17 
18 #endif // UTILS_H
CircularBuffer
Definition: CircularBuffer.h:5