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 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/util/bufferedstream.h" 00015 #include "IndexOutput.h" 00016 00017 CL_NS_DEF(store) 00018 00019 00024 class IndexInput: LUCENE_BASE { 00025 private: 00026 void skipChars( const int32_t count); 00027 protected: 00028 IndexInput(); 00029 IndexInput(const IndexInput& clone); 00030 public: 00031 virtual ~IndexInput(){} 00032 virtual IndexInput* clone() const =0; 00033 00034 DEFINE_MUTEX(THIS_LOCK) 00035 00036 00039 virtual uint8_t readByte() =0; 00040 00047 virtual void readBytes(uint8_t* b, const int32_t len) =0; 00048 00052 int32_t readInt(); 00053 00059 virtual int32_t readVInt(); 00060 00064 int64_t readLong(); 00065 00069 int64_t readVLong(); 00070 00076 int32_t readString(TCHAR* buffer, const int32_t maxlength); 00077 00083 TCHAR* readString(const bool unique=true); 00084 00085 00092 void readChars( TCHAR* buffer, const int32_t start, const int32_t len); 00093 00095 virtual void close() =0; 00096 00101 virtual int64_t getFilePointer() const =0; 00102 00106 virtual void seek(const int64_t pos) =0; 00107 00109 virtual int64_t length() = 0; 00110 00111 virtual const char* getDirectoryType() const = 0; 00112 }; 00113 00119 class BufferedIndexInput: public IndexInput{ 00120 private: 00121 uint8_t* buffer; //array of bytes 00122 void refill(); 00123 protected: 00124 int32_t bufferSize; //size of the buffer 00125 int64_t bufferStart; // position in file of buffer 00126 int32_t bufferLength; // end of valid l_byte_ts 00127 int32_t bufferPosition; // next uint8_t to read 00128 00138 BufferedIndexInput(const BufferedIndexInput& clone); 00139 BufferedIndexInput(int32_t bufferSize = CL_NS(store)::BufferedIndexOutput::BUFFER_SIZE); 00140 public: 00141 00142 virtual ~BufferedIndexInput(); 00143 virtual IndexInput* clone() const = 0; 00144 void close(); 00145 inline uint8_t readByte(){ 00146 if (bufferPosition >= bufferLength) 00147 refill(); 00148 00149 return buffer[bufferPosition++]; 00150 } 00151 void readBytes(uint8_t* b, const int32_t len); 00152 int64_t getFilePointer() const; 00153 void seek(const int64_t pos); 00154 00155 protected: 00162 virtual void readInternal(uint8_t* b, const int32_t len) = 0; 00163 00168 virtual void seekInternal(const int64_t pos) = 0; 00169 }; 00170 00178 class IndexInputStream: public jstreams::BufferedInputStream<char>{ 00179 IndexInput* input; 00180 public: 00181 IndexInputStream(IndexInput* input); 00182 ~IndexInputStream(); 00183 int32_t fillBuffer(char* start, int32_t space); 00184 }; 00185 CL_NS_END 00186 #endif