Taiko-Drum-Controller-Arduino/ATmega32U4/cache.h

31 lines
976 B
C
Raw Normal View History

2016-03-24 14:56:54 +01:00
/***************************************************************
* *
* Taiko Sanro - Arduino *
* Cache data structure *
* *
* Chris *
* wisaly@gmail.com *
* *
***************************************************************/
#ifndef CACHE_H
#define CACHE_H
2016-03-27 14:36:32 +02:00
template <class T, int L>
class Cache {
2016-03-24 14:56:54 +01:00
public:
2023-12-22 02:54:39 +01:00
Cache() { memset(data_, 0, sizeof(data_)); }
inline void put(T value) {
current_ = (current_ + 1) & (L - 1);
data_[current_] = value;
}
inline T get(int offset = 0) const {
return data_[(current_ + offset) & (L - 1)];
}
2016-03-24 14:56:54 +01:00
private:
2023-12-22 02:54:39 +01:00
T data_[L];
2016-03-24 14:56:54 +01:00
int current_ = 0;
};
2023-12-22 02:54:39 +01:00
#endif // CACHE_H