INTRODUCTION Overview Download and Install Quick Start Documentation Publications NONFRAMEWORK CODE Driver Interfaces Drivers Libraries Utilities FRAMEWORK CODE Interfaces Components Libraries Utilities Full Software Listings DEVELOPER Tutorials Examples Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
snapshotlogbuffer.h00001 #ifndef ORCALOG_SNAPSHOTLOGBUFFER_H 00002 #define ORCALOG_SNAPSHOTLOGBUFFER_H 00003 00004 #include <orca/common.h> 00005 #include <deque> 00006 #include <orcalog/logwriter.h> 00007 #include <orcaice/timeutils.h> 00008 00009 namespace orcalog { 00010 00016 template<typename ObjectType,typename LogWriterType> 00017 class SnapshotLogBuffer 00018 { 00019 00020 public: 00021 00022 SnapshotLogBuffer( double timeWindowSec ) 00023 : timeWindow_(timeWindowSec) 00024 {} 00025 00027 void addItem( const ObjectType &obj ) 00028 { 00029 buffer_.push_back( LogItem( obj, orcaice::getNow() ) ); 00030 00031 // std::cout<<"TRACE(snapshotlogbuffer.h): new time window: " << 00032 // orcaice::timeDiffAsDouble( buffer_.back().arrivalTime, buffer_.front().arrivalTime ) << std::endl; 00033 00034 // Delete old stuff if there's too much in the buffer 00035 while ( orcaice::timeDiffAsDouble( buffer_.back().arrivalTime, buffer_.front().arrivalTime ) > timeWindow_ ) 00036 { 00037 buffer_.pop_front(); 00038 // std::cout<<"TRACE(snapshotlogbuffer.h): purgind old data." << std::endl; 00039 } 00040 } 00041 00042 const unsigned int bufferSize() const 00043 { return buffer_.size(); } 00044 00045 const orca::Time &oldestArrivalTime() const 00046 { 00047 assert(buffer_.size()>0); 00048 return buffer_.front().arrivalTime; 00049 } 00050 void writeOldestObjToLogAndDiscard( LogWriterType &logWriter ) 00051 { 00052 assert( buffer_.size()>0 ); 00053 logWriter.write( buffer_.front().obj, buffer_.front().arrivalTime ); 00054 buffer_.pop_front(); 00055 } 00056 00057 private: 00058 00059 struct LogItem { 00060 LogItem() {} 00061 LogItem( const ObjectType &o, const orca::Time &t ) 00062 : obj(o), arrivalTime(t) 00063 {} 00064 00065 ObjectType obj; 00066 orca::Time arrivalTime; 00067 }; 00068 00069 std::deque<LogItem> buffer_; 00070 double timeWindow_; 00071 00072 }; 00073 00074 } 00075 00076 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)