00001 #ifndef SPIKEBUFFER_H_ 00002 #define SPIKEBUFFER_H_ 00003 00004 #include <list> 00005 using std::list; 00006 00008 00011 class SpikeBuffer 00012 { 00013 00014 public: 00015 typedef double SpikeTime; 00016 00017 typedef list<SpikeTime>::const_iterator const_iterator; 00018 typedef list<SpikeTime>::iterator iterator; 00019 00020 typedef list<SpikeTime>::reverse_iterator reverse_iterator; 00021 typedef list<SpikeTime>::const_reverse_iterator const_reverse_iterator; 00022 00023 SpikeBuffer( double max_time_diff = 100e-3 ) : max_time_diff(max_time_diff) 00024 {/* NOOP */ 00025 }; 00026 00027 00028 virtual ~SpikeBuffer() 00029 { /* NOOP */ 00030 }; 00031 00032 void reset( double mtd ) 00033 { 00034 max_time_diff = mtd; 00035 spikes.clear(); 00036 spikes.push_front(InvalidSpikeTime); 00037 } 00038 00039 void insert( double t ) 00040 { 00041 spikes.push_front( SpikeTime(t) ); 00042 } 00043 00044 size_t size() 00045 { 00046 return spikes.size(); 00047 } 00048 00050 00054 void cutoff(double t) 00055 { 00056 iterator it = spikes.begin(); 00057 while ( *it > t - max_time_diff ) it++; 00058 *(it++) = InvalidSpikeTime; 00059 spikes.erase( it, spikes.end() ); 00060 } 00061 00062 00063 const_iterator begin() 00064 { 00065 return spikes.begin(); 00066 } 00067 00068 const_iterator end_of_window() 00069 { 00070 return spikes.end(); 00071 } 00072 00073 SpikeTime const& first() 00074 { 00075 return spikes.front(); 00076 } 00077 00078 SpikeTime const& second() 00079 { 00080 if( spikes.size() < 2 ) { 00081 return InvalidSpikeTime; 00082 } else { 00083 const_iterator i = spikes.begin(); 00084 i++; 00085 return *i; 00086 } 00087 } 00088 00089 SpikeTime const& last() 00090 { 00091 return spikes.back(); 00092 } 00093 00094 static SpikeTime InvalidSpikeTime; 00095 00096 private: 00097 list<SpikeTime> spikes; 00098 double max_time_diff; 00099 00100 }; 00101 00102 #endif /*SPIKEBUFFER_H_*/