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_store_Directory 00008 #define _lucene_store_Directory 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/store/Lock.h" 00015 #include "CLucene/util/VoidList.h" 00016 #include "CLucene/util/Misc.h" 00017 00018 #include "IndexInput.h" 00019 #include "IndexOutput.h" 00020 00021 CL_NS_DEF(store) 00022 00023 00035 class Directory: LUCENE_REFBASE { 00036 protected: 00037 Directory(){ 00038 } 00039 // Removes an existing file in the directory. 00040 virtual bool doDeleteFile(const char* name) = 0; 00041 public: 00042 DEFINE_MUTEX(THIS_LOCK) 00043 00044 virtual ~Directory(){ }; 00045 00046 // Returns an null terminated array of strings, one for each file in the directory. 00047 char** list() const{ 00048 vector<string> names; 00049 00050 list(&names); 00051 00052 size_t size = names.size(); 00053 char** ret = _CL_NEWARRAY(char*,size+1); 00054 for ( size_t i=0;i<size;i++ ) 00055 ret[i] = STRDUP_AtoA(names[i].c_str()); 00056 ret[size]=NULL; 00057 return ret; 00058 } 00059 virtual void list(vector<string>* names) const = 0; 00060 00061 // Returns true iff a file with the given name exists. 00062 virtual bool fileExists(const char* name) const = 0; 00063 00064 // Returns the time the named file was last modified. 00065 virtual int64_t fileModified(const char* name) const = 0; 00066 00067 // Returns the length of a file in the directory. 00068 virtual int64_t fileLength(const char* name) const = 0; 00069 00070 // Returns a stream reading an existing file. 00071 virtual IndexInput* openInput(const char* name) = 0; 00072 virtual IndexInput* openInput(const char* name, int32_t bufferSize){ 00073 return openInput(name); //implementation didnt overload the bufferSize 00074 } 00075 00077 virtual void touchFile(const char* name) = 0; 00078 00079 // Removes an existing file in the directory. 00080 virtual bool deleteFile(const char* name, const bool throwError=true){ 00081 bool ret = doDeleteFile(name); 00082 if ( !ret && throwError ){ 00083 char buffer[200]; 00084 _snprintf(buffer,200,"couldn't delete %s",name); 00085 _CLTHROWA(CL_ERR_IO, buffer ); 00086 } 00087 return ret; 00088 } 00089 00090 // Renames an existing file in the directory. 00091 // If a file already exists with the new name, then it is replaced. 00092 // This replacement should be atomic. 00093 virtual void renameFile(const char* from, const char* to) = 0; 00094 00095 // Creates a new, empty file in the directory with the given name. 00096 // Returns a stream writing this file. 00097 virtual IndexOutput* createOutput(const char* name) = 0; 00098 00099 // Construct a {@link Lock}. 00100 // @param name the name of the lock file 00101 virtual LuceneLock* makeLock(const char* name) = 0; 00102 00103 // Closes the store. 00104 virtual void close() = 0; 00105 00106 virtual TCHAR* toString() const = 0; 00107 00108 virtual const char* getDirectoryType() const = 0; 00109 }; 00110 CL_NS_END 00111 #endif 00112 00113