00001 #ifndef TIME_STAMPED_EVENT_H 00002 #define TIME_STAMPED_EVENT_H 00003 00034 template <typename IntType> 00035 struct TimeStamper 00036 { 00038 typedef IntType DataType; 00039 static IntType getTimeStamp(); 00041 inline static bool leftOlder(IntType left, IntType right) {return left < right;} 00042 }; 00043 00049 template <typename IntType> 00050 IntType 00051 TimeStamper<IntType>::getTimeStamp() 00052 { 00053 static IntType stamp = 0; 00054 return ++ stamp; 00055 } 00056 00101 typedef TimeStamper<unsigned long int> DefaultTimeStamper; 00102 00118 template <class Stamper = DefaultTimeStamper> 00119 class TimeStampedEvent 00120 { 00121 public: 00127 const typename Stamper::DataType& getTimeStamp() const {return _timeStamp;} 00128 00130 bool isOlderThan(const TimeStampedEvent& tse) const 00131 { 00132 return Stamper::leftOlder(_timeStamp, tse._timeStamp); 00133 } 00134 00136 bool operator<(const TimeStampedEvent& tse) const {return isOlderThan(tse);} 00137 00138 protected: 00140 TimeStampedEvent(): _timeStamp( Stamper::getTimeStamp() ) {} 00143 ~TimeStampedEvent() {} 00144 00145 private: // data 00147 const typename Stamper::DataType _timeStamp; 00148 }; 00149 00150 #endif // TIME_STAMPED_EVENT_H