XCube Stream Reader SDK
|
00001 00008 #ifndef __CINDEXWRITER_H__ 00009 #define __CINDEXWRITER_H__ 00010 00011 #include <vector> 00012 #include <cassert> 00013 #include "IdxFileFormat.h" 00014 #include "CIndexer.h" 00015 00016 namespace x3c { 00017 namespace indexer { 00018 00019 class CIndexWriter 00020 { 00021 public: 00022 00026 ~CIndexWriter(); 00027 00031 void close(); 00032 00041 void addIndexRecord(UINT64 timestamp, UINT64 offset); 00042 00048 void addIndexRecord(IndexRecord const& record); 00049 00053 UINT32 numRecords() const; 00054 00060 bool flushToDisk(); 00061 00065 std::string const& filename() const; 00066 00067 private: 00068 00072 CIndexWriter& operator=(CIndexWriter const&); 00073 00077 CIndexWriter(CIndexWriter const&); 00078 00084 CIndexWriter(CIndexer<CIndexWriter> const& parent, 00085 UINT32 reservedMem); 00086 00090 bool create(std::string const& filename); 00091 00095 bool writeHeader(); 00096 00100 bool writeIndexRecords(); 00101 00105 bool writeTrailer(); 00106 00108 std::string mFilename; 00109 00111 IndexHeader mHeader; 00112 00114 std::vector<IndexRecord> mIndexRecords; 00115 00117 IndexTrailer mTrailer; 00118 00120 CIndexer<CIndexWriter> const& mParent; 00121 00123 mutable INT32 mFd; 00124 00127 friend class CIndexer<CIndexWriter>; 00128 }; 00129 00130 //====================================================================== 00131 // Inline members 00132 // 00133 00134 00135 inline void CIndexWriter::addIndexRecord(IndexRecord const& record) 00136 { 00137 mIndexRecords.push_back(record); 00138 } 00139 00140 inline void CIndexWriter::addIndexRecord(UINT64 timestamp, 00141 UINT64 offset) 00142 { 00143 // TODO: support the IndexRecord::packet_number field 00144 IndexRecord idx = { timestamp, offset, 0 }; 00145 addIndexRecord(idx); 00146 } 00147 00148 inline std::string const& CIndexWriter::filename() const 00149 { 00150 return mFilename; 00151 } 00152 00153 inline UINT32 CIndexWriter::numRecords() const 00154 { 00155 return mIndexRecords.size(); 00156 } 00157 00158 } /* namespace indexer */ 00159 } /* namespace x3c */ 00160 00161 #endif /* __CINDEXWRITER_H__ */