MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Tools/Graphical/libAlogTools/alogTools/indexReader.cpp
Go to the documentation of this file.
00001 #include "indexReader.h"
00002 #include "FileNotFoundException.h"
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <iterator>
00007 #include <iostream>
00008 #include <fstream>
00009 
00010 using namespace std;
00011 
00013 indexReader::indexReader():
00014     m_alogHeader(),
00015     m_alogMsgList(),
00016     m_alogSrcList(),
00017     m_alogRecords()
00018 {}
00019 
00021 indexReader::~indexReader()
00022 {}
00023 
00025 void indexReader::clear()
00026 {
00027   m_alogHeader.clear();
00028   m_alogMsgList.clear();
00029   m_alogSrcList.clear();
00030   m_alogRecords.clear();
00031 }
00032 
00034 void indexReader::GetMsgTypes(vector<string> &msgTypes)
00035 {
00036   msgTypes.clear();
00037   msgTypes.reserve(m_alogMsgList.size());
00038   std::copy(m_alogMsgList.begin(), m_alogMsgList.end(), inserter(msgTypes, msgTypes.begin()));
00039 }
00040 
00042 void indexReader::ReadIndexFile( std::string alogIndexFilename )
00043 {
00044     clear();
00045 
00046     std::ifstream idxFileStream( alogIndexFilename.c_str() );
00047 
00048     if(!idxFileStream.is_open())
00049     {
00050       throw FileNotFoundException(alogIndexFilename);
00051     }
00052 
00053     // Read in index file's header
00054     // This could throw a VersionException
00055     idxFileStream >> m_alogHeader;
00056     
00057     // Read in the list of message types contained in the alog
00058     idxFileStream >> m_alogMsgList;
00059 
00060     // Read in the list of sources contained in the alog
00061     idxFileStream >> m_alogSrcList;
00062 
00063     // Read all of the index records into a vector
00064     m_alogRecords.reserve(m_alogHeader.numRecs);
00065     for(int i = 0; i < m_alogHeader.numRecs; ++i)
00066     {
00067         aloglib::idxRec alogRecord;
00068         idxFileStream >> alogRecord;
00069 
00070         m_alogRecords.push_back( alogRecord );
00071     }
00072 
00073 }
00074 
00076 const aloglib::idxRec& indexReader::GetLineRecord(unsigned int lineNum ) const
00077 { 
00078     return m_alogRecords.at(lineNum);
00079 }
00080 
00082 double indexReader::GetTime( int i ) const
00083 {
00084     const aloglib::idxRec &rec = GetLineRecord( i );
00085     return rec.time;
00086 }
00087 
00089 double indexReader::GetStartTime() const
00090 {
00091     return m_alogHeader.startTime;
00092 }
00093 
00095 int indexReader::GetNumRecords() const
00096 {
00097     return m_alogRecords.size();
00098 }
00099 
00101 const aloglib::idxMsgList& indexReader::GetMsgList() const
00102 {
00103     return m_alogMsgList;
00104 }
00105 
00107 const aloglib::idxSrcList& indexReader::GetSrcList() const
00108 {
00109     return m_alogSrcList;
00110 }
00111 
00113 const std::vector<aloglib::idxRec>& indexReader::GetRecordList() const
00114 {
00115     return m_alogRecords;
00116 }
00117 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines