#include "CLucene/StdHeader.h" #include "FilteredTermEnum.h" using namespace lucene::index; namespace lucene{ namespace search { void FilteredTermEnum::setEnum(TermEnum* actualEnum) { if (this->actualEnum != NULL) delete this->actualEnum; /* DSR:CL_BUG_LEAK */ this->actualEnum = actualEnum; // Find the first term that matches /* DSR:CL_BUG_LEAK: Ordered getTerm not to return reference ** ownership here. */ Term* term = actualEnum->getTerm(false); if ( termCompare(term) ){ currentTerm->finalize(); currentTerm = term->pointer(); } else next(); } FilteredTermEnum::FilteredTermEnum(IndexReader& reader, Term* term){ currentTerm = NULL; actualEnum = NULL; } FilteredTermEnum::~FilteredTermEnum() { /* DSR:CL_BUG_LEAK: Neither currentTerm nor actualEnum was released. */ if (currentTerm != NULL) currentTerm->finalize(); delete actualEnum; } /** * Returns the docFreq of the current Term in the enumeration. * Initially invalid, valid after next() called for the first time. */ int_t FilteredTermEnum::DocFreq() const { if (actualEnum == NULL) return -1; return actualEnum->DocFreq(); } /** Increments the enumeration to the next element. True if one exists. */ bool FilteredTermEnum::next() { if (actualEnum == NULL) return false; // the actual enumerator is not initialized! currentTerm->finalize(); currentTerm = NULL; while (currentTerm == NULL) { if (EndEnum()) return false; if (actualEnum->next()) { /* DSR:CL_BUG_LEAK: Ordered getTerm not to return reference ** ownership here. */ Term* term = actualEnum->getTerm(false); if (termCompare(term)) { currentTerm->finalize(); currentTerm = term->pointer(); return true; } } else return false; } currentTerm->finalize(); currentTerm = NULL; return false; } /** Returns the current Term in the enumeration. * Initially invalid, valid after next() called for the first time. */ Term* FilteredTermEnum::getTerm(const bool pointer) { if ( pointer && currentTerm!=NULL ) return currentTerm->pointer(); else return currentTerm; } /** Closes the enumeration to further activity, freeing resources. */ void FilteredTermEnum::close(){ actualEnum->close(); /* DSR:CL_BUG_LEAK: actualEnum was closed but not deleted. */ _DELETE(actualEnum); currentTerm->finalize(); currentTerm = NULL; } }}