CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_index_compoundfile_h 00008 #define _lucene_index_compoundfile_h 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/store/IndexInput.h" 00015 #include "CLucene/store/IndexOutput.h" 00016 #include "CLucene/store/Directory.h" 00017 #include "CLucene/store/Lock.h" 00018 #include "CLucene/util/VoidList.h" 00019 #include "CLucene/util/VoidMap.h" 00020 00021 00022 CL_NS_DEF(index) 00023 00024 00025 00031 class CompoundFileReader: public CL_NS(store)::Directory { 00032 private: 00038 class CSIndexInput:public CL_NS(store)::BufferedIndexInput { 00039 private: 00040 CL_NS(store)::IndexInput* base; 00041 int64_t fileOffset; 00042 int64_t _length; 00043 protected: 00049 void readInternal(uint8_t* b, const int32_t len); 00050 void seekInternal(const int64_t pos) 00051 { 00052 } 00053 00054 public: 00055 CSIndexInput(CL_NS(store)::IndexInput* base, const int64_t fileOffset, const int64_t length); 00056 CSIndexInput(const CSIndexInput& clone); 00057 ~CSIndexInput(); 00058 00060 void close(); 00061 CL_NS(store)::IndexInput* clone() const; 00062 00063 int64_t length(){ return _length; } 00064 00065 const char* getDirectoryType() const{ return CompoundFileReader::DirectoryType(); } 00066 }; 00067 00068 class FileEntry:LUCENE_BASE { 00069 public: 00070 int64_t offset; 00071 int64_t length; 00072 FileEntry(){ 00073 offset=0; 00074 length=0; 00075 } 00076 ~FileEntry(){ 00077 } 00078 }; 00079 00080 // Base info 00081 CL_NS(store)::Directory* directory; 00082 char fileName[CL_MAX_PATH]; 00083 00084 CL_NS(store)::IndexInput* stream; 00085 00086 typedef CL_NS(util)::CLHashMap<const char*,FileEntry*, 00087 CL_NS(util)::Compare::Char, 00088 CL_NS(util)::Equals::Char, 00089 CL_NS(util)::Deletor::acArray, 00090 CL_NS(util)::Deletor::Object<FileEntry> > EntriesType; 00091 EntriesType entries; 00092 protected: 00094 bool doDeleteFile(const char* name); 00095 00096 public: 00097 CompoundFileReader(CL_NS(store)::Directory* dir, char* name); 00098 ~CompoundFileReader(); 00099 CL_NS(store)::Directory* getDirectory(); 00100 const char* getName() const; 00101 00102 void close(); 00103 CL_NS(store)::IndexInput* openInput(const char* id); 00104 00106 void list(vector<string>* names) const; 00108 bool fileExists(const char* name) const; 00110 int64_t fileModified(const char* name) const; 00112 void touchFile(const char* name); 00116 void renameFile(const char* from, const char* to); 00119 int64_t fileLength(const char* name) const; 00122 CL_NS(store)::IndexOutput* createOutput(const char* name); 00125 CL_NS(store)::LuceneLock* makeLock(const char* name); 00126 00127 TCHAR* toString() const; 00128 00129 static const char* DirectoryType(){ return "CFS"; } 00130 const char* getDirectoryType() const{ return DirectoryType(); } 00131 }; 00132 00133 00155 class CompoundFileWriter:LUCENE_BASE { 00156 class WriterFileEntry:LUCENE_BASE { 00157 public: 00158 WriterFileEntry(){ 00159 directoryOffset=0; 00160 dataOffset=0; 00161 } 00162 ~WriterFileEntry(){ 00163 } 00165 char file[CL_MAX_PATH]; 00166 00168 int64_t directoryOffset; 00169 00171 int64_t dataOffset; 00172 00173 }; 00174 00175 CL_NS(store)::Directory* directory; 00176 char fileName[CL_MAX_PATH]; 00177 CL_NS(util)::CLHashSet<const char*, 00178 CL_NS(util)::Compare::Char,CL_NS(util)::Deletor::acArray> ids; 00179 CL_NS(util)::CLLinkedList<WriterFileEntry*, 00180 CL_NS(util)::Deletor::Object<WriterFileEntry> > entries; 00181 bool merged; 00186 void copyFile(WriterFileEntry* source, CL_NS(store)::IndexOutput* os, uint8_t* buffer, int32_t bufferLength); 00187 public: 00191 CompoundFileWriter(CL_NS(store)::Directory* dir, const char* name); 00192 ~CompoundFileWriter(); 00194 CL_NS(store)::Directory* getDirectory(); 00195 const char* getName() const ; 00204 void addFile(const char* file); 00212 void close(); 00213 }; 00214 00215 CL_NS_END 00216 #endif