#include "CLucene/StdHeader.h" #include "SegmentInfos.h" #include "CLucene/store/Directory.h" #include "SegmentInfo.h" #include "CLucene/util/VoidMap.h" namespace lucene{ namespace index { SegmentInfos::SegmentInfos() :lucene::util::VoidList(true,DELETE_TYPE_DELETE) { counter = 0; } /* DSR: Added this (bool) form of constructor to allow client to instantiate ** SegmentInfos object that does not delete its members upon its own ** deletion. This change was prompted by a bug in IndexWriter::addIndexes. */ SegmentInfos::SegmentInfos(bool deleteMembers) : lucene::util::VoidList(deleteMembers,DELETE_TYPE_DELETE) { counter = 0; } SegmentInfo& SegmentInfos::info(int_t i) { return *at(i); } SegmentInfos::~SegmentInfos(){ clear(); } void SegmentInfos::read(Directory& directory){ InputStream& input = directory.openFile(_T("segments")); _TRY { counter = input.readInt(); // read counter for (int_t i = input.readInt(); i > 0; i--) { // read segmentInfos char_t* name = input.readString(); SegmentInfo* si = new SegmentInfo(name, input.readInt(), directory); delete[] name; push_back(si); } } _FINALLY( input.close(); delete &input; ); } #ifndef CLUCENE_LITE void SegmentInfos::write(Directory& directory){ OutputStream& output = directory.createFile(_T("segments.new")); _TRY { output.writeInt(counter); // write counter output.writeInt(size()); // write infos for (uint_t i = 0; i < size(); i++) { SegmentInfo& si = info(i); output.writeString(si.name); output.writeInt(si.docCount); } } _FINALLY( output.close(); delete &output; ); // install new segment info directory.renameFile(_T("segments.new"), _T("segments")); } #endif //CLUCENE_LITE }}