MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Tools/Graphical/uIndexedPlayBack/ALogIndexWrapper.cpp
Go to the documentation of this file.
00001 #include "ALogIndexWrapper.h"
00002 
00003 #include <vector>
00004 #include <algorithm>
00005 
00007 ALogIndexWrapper::ALogIndexWrapper() : m_bInitialized(false), m_nLineCount(-1)
00008 { }
00009 
00011 ALogIndexWrapper::~ALogIndexWrapper()
00012 { Close(); }
00013 
00015 bool ALogIndexWrapper::Open(const std::string & sfName)
00016 {
00017     if( m_ALog.Init( sfName ) == false )
00018     {
00019         //printf("Initialisation of indexedAlogReader failed. Ensure that the alog path is correct:\n \t'%s'\n\n and that the corresponding index file exists:\n \t'%s'\n\nIf not, you can build an index file:\n \talogIndexWriter /path/to/file.alog\n\n",sfName.c_str(),(sfName+".idx").c_str());
00020         return false;
00021     }
00022 
00023     m_sFileName = sfName;
00024     m_nLineCount = m_ALog.GetNumRecords();
00025 
00026     m_bInitialized = true;
00027     return true;
00028 }
00029 
00030 
00031 std::string ALogIndexWrapper::GetFileName()
00032 {
00033     return m_sFileName;
00034 }
00035        
00037 bool ALogIndexWrapper::IsOpen()
00038 {
00039     return m_bInitialized;
00040 }
00041 
00043 void ALogIndexWrapper::Close()
00044 {
00045     //m_ALog.Close();
00046 }
00047 
00049 std::string ALogIndexWrapper::GetLine(int nLine)
00050 {
00051     std::string line;
00052     m_ALog.GetLine( nLine, line );
00053     return line;
00054 }
00055 
00057 bool ALogIndexWrapper::GetNextToken(const std::string & s,int & nPos,std::string & sTk)
00058 {
00059     std::string::size_type Start = s.find_first_not_of(" \t", nPos);
00060     nPos     = s.find_first_of(" \t", Start);
00061     if( Start!=std::string::npos)
00062     {
00063         sTk =s.substr(Start,nPos-Start);
00064         return true;
00065     }
00066     return false;
00067 }
00068 
00070 int ALogIndexWrapper::GetLineCount()
00071 {
00072     return m_nLineCount;
00073 }
00074 
00076 int ALogIndexWrapper::SeekToFindTime(double dfT)
00077 {
00078     aloglib::idxRec seekRec;
00079 
00080     // dfT is global time, shift to be relative to log start
00081     seekRec.time = dfT - m_ALog.GetStartTime();
00082 
00083     std::vector<aloglib::idxRec> recs = m_ALog.GetRecordList();
00084     std::vector<aloglib::idxRec>::iterator result;
00085 
00086     // find first record which does not compare < seekRec.time
00087     result = std::lower_bound( recs.begin(), recs.end(), seekRec );
00088 
00089     if( result == recs.end() )
00090     {
00091         return -1;
00092     }
00093     else
00094     {
00095         // return line number rather than record
00096         return std::distance( recs.begin(), result );
00097     }
00098 }
00099 
00101 double ALogIndexWrapper::GetEntryTime(int i)
00102 {
00103     return m_ALog.GetTime( i ) + m_ALog.GetStartTime();
00104 }
00105 
00107 double ALogIndexWrapper::GetStartTime()
00108 {
00109     return m_ALog.GetStartTime();
00110 }
00111 
00113 const std::set<std::string>& ALogIndexWrapper::GetSourceNames()
00114 {
00115     return m_ALog.GetSrcList();
00116 }
00117 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines