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_IndexInput_ 00008 #define _lucene_store_IndexInput_ 00009 00010 #include "CLucene/LuceneThreads.h" 00011 00012 #include "CLucene/util/bufferedstream.h" 00013 00014 CL_NS_DEF(store) 00015 00016 00021 class IndexInput: LUCENE_BASE { 00022 private: 00023 void skipChars( const int32_t count); 00024 protected: 00025 IndexInput(); 00026 IndexInput(const IndexInput& clone); 00027 public: 00028 virtual ~IndexInput(){} 00029 virtual IndexInput* clone() const =0; 00030 00031 DEFINE_MUTEX(THIS_LOCK) 00032 00033 00036 virtual uint8_t readByte() =0; 00037 00044 virtual void readBytes(uint8_t* b, const int32_t len) =0; 00045 00049 int32_t readInt(); 00050 00056 virtual int32_t readVInt(); 00057 00061 int64_t readLong(); 00062 00066 int64_t readVLong(); 00067 00073 int32_t readString(TCHAR* buffer, const int32_t maxlength); 00074 00078 TCHAR* readString(); 00079 00080 00087 void readChars( TCHAR* buffer, const int32_t start, const int32_t len); 00088 00090 virtual void close() =0; 00091 00096 virtual int64_t getFilePointer() const =0; 00097 00101 virtual void seek(const int64_t pos) =0; 00102 00104 virtual int64_t length() const = 0; 00105 00106 virtual const char* getDirectoryType() const = 0; 00107 00108 virtual const char* getObjectName() = 0; 00109 }; 00110 00116 class BufferedIndexInput: public IndexInput{ 00117 private: 00118 uint8_t* buffer; //array of bytes 00119 void refill(); 00120 protected: 00121 int32_t bufferSize; //size of the buffer 00122 int64_t bufferStart; // position in file of buffer 00123 int32_t bufferLength; // end of valid l_byte_ts 00124 int32_t bufferPosition; // next uint8_t to read 00125 00135 BufferedIndexInput(const BufferedIndexInput& clone); 00136 BufferedIndexInput(int32_t bufferSize = -1); 00137 public: 00138 LUCENE_STATIC_CONSTANT(int32_t, BUFFER_SIZE=LUCENE_STREAM_BUFFER_SIZE); 00139 00140 virtual ~BufferedIndexInput(); 00141 virtual IndexInput* clone() const = 0; 00142 void close(); 00143 inline uint8_t readByte(){ 00144 if (bufferPosition >= bufferLength) 00145 refill(); 00146 00147 return buffer[bufferPosition++]; 00148 } 00149 void readBytes(uint8_t* b, const int32_t len); 00150 int64_t getFilePointer() const; 00151 void seek(const int64_t pos); 00152 00153 void setBufferSize( int32_t newSize ); 00154 00155 const char* getObjectName(){ return BufferedIndexInput::getClassName(); } 00156 static const char* getClassName(){ return "BufferedIndexInput"; } 00157 00158 protected: 00165 virtual void readInternal(uint8_t* b, const int32_t len) = 0; 00166 00171 virtual void seekInternal(const int64_t pos) = 0; 00172 }; 00173 00181 class IndexInputStream: public jstreams::BufferedInputStream<char>{ 00182 IndexInput* input; 00183 public: 00184 IndexInputStream(IndexInput* input); 00185 ~IndexInputStream(); 00186 int32_t fillBuffer(char* start, int32_t space); 00187 }; 00188 CL_NS_END 00189 #endif