00001 #ifndef _HISTORY_H__
00002 #define _HISTORY_H__
00003
00004 #include <gea/API.h>
00005 #include <gea/Time.h>
00006
00007 template <typename T, unsigned S>
00008 class History {
00009
00010 unsigned n;
00011 std::pair< gea::AbsTime,T> ring[S];
00012 unsigned p;
00013 public:
00014
00015 History() : n(0), p(0) {}
00016
00017 void insert(const T& e) {
00018 ring[p] = std::make_pair( GEA.lastEventTime, e );
00019 p = (p + 1) % S;
00020 if (n < S) n++;
00021 }
00022
00023 bool contains(const T& e) const {
00024 for (unsigned i = 0; i != n; ++i) {
00025 if ( ( GEA.lastEventTime - ring[i].first < gea::Duration(5,1) ) && (ring[i].second == e) )
00026 return true;
00027 }
00028 return false;
00029 }
00030
00031 };
00032
00033
00034 #endif //HISTORY_H__
00035
00036
00037
00038
00039
00040