From: <ust...@us...> - 2009-03-30 20:57:59
|
Revision: 2973 http://clucene.svn.sourceforge.net/clucene/?rev=2973&view=rev Author: ustramooner Date: 2009-03-30 20:57:49 +0000 (Mon, 30 Mar 2009) Log Message: ----------- move away the jstreams into the standard util directory. we're going to support jstreams through a filter class instead.... (Soon!) Modified Paths: -------------- branches/lucene2_3_2/src/core/CLucene/util/CLStreams.h branches/lucene2_3_2/src/core/CLucene/util/Reader.cpp branches/lucene2_3_2/src/core/CLucene/util/_bufferedstream.h branches/lucene2_3_2/src/core/CLucene/util/_streambase.h branches/lucene2_3_2/src/core/CLucene/util/_streambuffer.h Modified: branches/lucene2_3_2/src/core/CLucene/util/CLStreams.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/util/CLStreams.h 2009-03-30 20:54:55 UTC (rev 2972) +++ branches/lucene2_3_2/src/core/CLucene/util/CLStreams.h 2009-03-30 20:57:49 UTC (rev 2973) @@ -95,6 +95,7 @@ * The value obtained from this function can be used to reset the stream. **/ virtual int64_t position() = 0; + int64_t getPosition(){ return this->position(); } virtual size_t size() = 0; }; @@ -175,7 +176,22 @@ void setMinBufSize(int32_t minbufsize); }; +class CLUCENE_EXPORT FilteredBufferedInputStream: public BufferedInputStream{ + class Internal; + Internal* internal; +public: + FilteredBufferedInputStream(InputStream* input, bool deleteInput); + virtual ~FilteredBufferedInputStream(); + + int32_t read(const signed char*& start, int32_t min, int32_t max); + int64_t position(); + int64_t reset(int64_t); + int64_t skip(int64_t ntoskip); + size_t size(); + void setMinBufSize(int32_t minbufsize); +}; + class CLUCENE_EXPORT StringReader: public BufferedReader{ TCHAR* value; bool ownValue; @@ -185,11 +201,30 @@ public: StringReader ( const TCHAR* value, const int32_t length = -1 ); StringReader ( TCHAR* value, const int32_t length, bool copyData = true ); - virtual ~StringReader(); + virtual ~StringReader(); int32_t read(const TCHAR*& start, int32_t min, int32_t max); int64_t position(); int64_t reset(int64_t); + int64_t skip(int64_t ntoskip); + void setMinBufSize(int32_t s); + size_t size(); +}; +class CLUCENE_EXPORT AStringReader: public BufferedInputStream{ + signed char* value; + bool ownValue; + int64_t pos; +protected: + size_t m_size; +public: + AStringReader ( const char* value, const int32_t length = -1 ); + AStringReader ( char* value, const int32_t length, bool copyData = true ); + virtual ~AStringReader(); + + int32_t read(const signed char*& start, int32_t min, int32_t max); + int32_t read(const unsigned char*& start, int32_t min, int32_t max); + int64_t position(); + int64_t reset(int64_t); int64_t skip(int64_t ntoskip); void setMinBufSize(int32_t s); size_t size(); @@ -230,6 +265,7 @@ }; SimpleInputStreamReader(); + SimpleInputStreamReader(InputStream *i, int encoding); virtual ~SimpleInputStreamReader(); int32_t read(const TCHAR*& start, int32_t min, int32_t max); @@ -255,4 +291,7 @@ }; CL_NS_END + +#define jstreams CL_NS(util) + #endif Modified: branches/lucene2_3_2/src/core/CLucene/util/Reader.cpp =================================================================== --- branches/lucene2_3_2/src/core/CLucene/util/Reader.cpp 2009-03-30 20:54:55 UTC (rev 2972) +++ branches/lucene2_3_2/src/core/CLucene/util/Reader.cpp 2009-03-30 20:57:49 UTC (rev 2973) @@ -82,9 +82,75 @@ return s; } + + + +AStringReader::AStringReader ( char* value, const int32_t length, bool copyData ) +{ + this->m_size = length; + this->pos = 0; + if ( copyData ){ + this->value = _CL_NEWARRAY(signed char, this->m_size); + strncpy((char*)this->value, value, this->m_size); + }else{ + this->value = (signed char*)value; + } + this->ownValue = copyData; +} + +AStringReader::AStringReader ( const char* value, const int32_t length ){ + if ( length >= 0 ) + this->m_size = length; + else + this->m_size = strlen(value); + this->pos = 0; + this->value = _CL_NEWARRAY(signed char, this->m_size); + strncpy((char*)this->value, value, this->m_size); + this->ownValue = true; +} +AStringReader::~AStringReader(){ + if ( ownValue ) + _CLDELETE_ARRAY(this->value); +} + +size_t AStringReader::size(){ + return m_size; +} +int32_t AStringReader::read(const signed char*& start, int32_t min, int32_t max){ + if ( m_size == pos ) + return -1; + start = this->value + pos; + int32_t r = (int32_t)cl_min(cl_max(min,max),m_size-pos); + pos += r; + return r; +} +int32_t AStringReader::read(const unsigned char*& start, int32_t min, int32_t max){ + if ( m_size == pos ) + return -1; + start = (unsigned char*)(this->value + pos); + int32_t r = (int32_t)cl_min(cl_max(min,max),m_size-pos); + pos += r; + return r; +} +int64_t AStringReader::position(){ + return pos; +} +void AStringReader::setMinBufSize(int32_t s){ +} +int64_t AStringReader::reset(int64_t pos){ + if ( pos >= 0 && pos < this->m_size ) + this->pos = pos; + return this->pos; +} +int64_t AStringReader::skip(int64_t ntoskip){ + int64_t s = cl_min(ntoskip, m_size-pos); + this->pos += s; + return s; +} + class FileInputStream::Internal{ public: - class JStreamsBuffer: public jstreams::BufferedInputStream{ + class JStreamsBuffer: public BufferedInputStreamImpl{ int32_t fhandle; protected: int32_t fillBuffer(signed char* start, int32_t space){ @@ -95,7 +161,7 @@ // check the file stream status if (nwritten == -1 ) { m_error = "Could not read from file"; - m_status = jstreams::Error; + m_status = CL_NS(util)::Error; if ( fhandle > 0 ){ ::_close(fhandle); fhandle = 0; @@ -146,7 +212,7 @@ else if ( err == EMFILE ) _CLTHROWA(CL_ERR_IO, "Too many open files"); else - _CLTHROWA(CL_ERR_IO, "Could not open file"); + _CLTHROWA(CL_ERR_IO, "Could not open file"); } jsbuffer = new JStreamsBuffer(fhandle, buffersize); @@ -215,7 +281,7 @@ class SimpleInputStreamReader::Internal{ public: - class JStreamsBuffer: public jstreams::BufferedReader{ + class JStreamsBuffer: public BufferedReaderImpl{ InputStream* input; char utf8buf[6]; //< buffer used for converting utf8 characters protected: @@ -261,10 +327,10 @@ }else if ( ret == -1 ) return -1; this->m_error = "Invalid multibyte sequence."; - this->m_status = jstreams::Error; + this->m_status = CL_NS(util)::Error; }else{ this->m_error = "Unexpected encoding"; - this->m_status = jstreams::Error; + this->m_status = CL_NS(util)::Error; } return -1; } @@ -276,7 +342,7 @@ for(i=0;i<space;i++){ c = readChar(); if ( c == -1 ){ - if ( this->m_status == jstreams::Ok ){ + if ( this->m_status == CL_NS(util)::Ok ){ if ( i == 0 ) return -1; break; @@ -293,6 +359,7 @@ JStreamsBuffer(InputStream* input, int encoding){ this->input = input; this->encoding = encoding; + setMinBufSize(1024); } ~JStreamsBuffer(){ _CLDELETE(input); @@ -315,6 +382,9 @@ SimpleInputStreamReader::SimpleInputStreamReader(){ internal = NULL; } +SimpleInputStreamReader::SimpleInputStreamReader(InputStream *i, int encoding){ + internal = new Internal(i, encoding); +} void SimpleInputStreamReader::init(InputStream *i, int encoding){ internal = new Internal(i, encoding); } @@ -343,7 +413,7 @@ class FilteredBufferedReader::Internal{ public: - class JStreamsFilteredBuffer: public jstreams::BufferedReader{ + class JStreamsFilteredBuffer: public BufferedReaderImpl{ Reader* input; bool deleteInput; protected: @@ -401,4 +471,67 @@ return internal->jsbuffer->_setMinBufSize(minbufsize); } + + + +class FilteredBufferedInputStream::Internal{ +public: + class JStreamsFilteredBuffer: public BufferedInputStreamImpl{ + InputStream* input; + bool deleteInput; + protected: + int32_t fillBuffer(signed char* start, int32_t space){ + const signed char* buffer; + int32_t r = input->read(buffer, 1, space); + if ( r > 0 ) + memcpy(start, buffer, r); + return r; + } + public: + JStreamsFilteredBuffer(InputStream* input, bool deleteInput){ + this->input = input; + this->deleteInput = deleteInput; + } + ~JStreamsFilteredBuffer(){ + if ( deleteInput ) + _CLDELETE(input); + } + void _setMinBufSize(int32_t min){ + this->setMinBufSize(min); + } + }; + JStreamsFilteredBuffer* jsbuffer; + + Internal(InputStream* input, bool deleteInput){ + this->jsbuffer = new JStreamsFilteredBuffer(input, deleteInput); + } + ~Internal(){ + delete jsbuffer; + } +}; +FilteredBufferedInputStream::FilteredBufferedInputStream(InputStream* input, bool deleteInput){ + internal = new Internal(input, deleteInput); +} +FilteredBufferedInputStream::~FilteredBufferedInputStream(){ + delete internal; +} +int32_t FilteredBufferedInputStream::read(const signed char*& start, int32_t min, int32_t max){ + return internal->jsbuffer->read(start,min,max); +} +int64_t FilteredBufferedInputStream::position(){ + return internal->jsbuffer->position(); +} +int64_t FilteredBufferedInputStream::reset(int64_t p){ + return internal->jsbuffer->reset(p); +} +int64_t FilteredBufferedInputStream::skip(int64_t ntoskip){ + return internal->jsbuffer->skip(ntoskip); +} +size_t FilteredBufferedInputStream::size(){ + return internal->jsbuffer->size(); +} +void FilteredBufferedInputStream::setMinBufSize(int32_t minbufsize){ + return internal->jsbuffer->_setMinBufSize(minbufsize); +} + CL_NS_END Modified: branches/lucene2_3_2/src/core/CLucene/util/_bufferedstream.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/util/_bufferedstream.h 2009-03-30 20:54:55 UTC (rev 2972) +++ branches/lucene2_3_2/src/core/CLucene/util/_bufferedstream.h 2009-03-30 20:57:49 UTC (rev 2973) @@ -1,21 +1,21 @@ -#ifndef STRIGI_BUFFEREDSTREAM_H -#define STRIGI_BUFFEREDSTREAM_H +#ifndef JSTREAMS_BUFFEREDSTREAM_H +#define JSTREAMS_BUFFEREDSTREAM_H #include "_streambase.h" #include "_streambuffer.h" #include <cassert> -namespace jstreams { +CL_NS_DEF(util) /** - * @brief Abstract class providing a buffered input stream. + * @brief Abstract implementation class providing a buffered input stream. * * You can inherit this class to provide buffered access to a * resource. You just need to implement fillBuffer, and * BufferedStream will do the rest. */ template <class T> -class BufferedStream : public StreamBase<T> { +class BufferedStreamImpl : public StreamBase<T> { private: StreamBuffer<T> buffer; bool finishedWritingToBuffer; @@ -62,7 +62,7 @@ void setMinBufSize(int32_t s) { buffer.makeSpace(s); } - BufferedStream<T>(); + BufferedStreamImpl<T>(); public: int32_t read(const T*& start, int32_t min, int32_t max); int64_t reset(int64_t pos); @@ -71,20 +71,20 @@ /** Abstract class for a buffered stream of bytes */ -typedef BufferedStream<signed char> BufferedInputStream; +typedef BufferedStreamImpl<signed char> BufferedInputStreamImpl; /** Abstract class for a buffered stream of Unicode characters */ -typedef BufferedStream<wchar_t> BufferedReader; +typedef BufferedStreamImpl<wchar_t> BufferedReaderImpl; template <class T> -BufferedStream<T>::BufferedStream() { +BufferedStreamImpl<T>::BufferedStreamImpl() { finishedWritingToBuffer = false; } template <class T> void -BufferedStream<T>::writeToBuffer(int32_t ntoread, int32_t maxread) { +BufferedStreamImpl<T>::writeToBuffer(int32_t ntoread, int32_t maxread) { int32_t missing = ntoread - buffer.avail; int32_t nwritten = 0; while (missing > 0 && nwritten >= 0) { @@ -107,7 +107,7 @@ } template <class T> int32_t -BufferedStream<T>::read(const T*& start, int32_t min, int32_t max) { +BufferedStreamImpl<T>::read(const T*& start, int32_t min, int32_t max) { if (StreamBase<T>::m_status == Error) return -2; if (StreamBase<T>::m_status == Eof) return -1; @@ -143,7 +143,7 @@ } template <class T> int64_t -BufferedStream<T>::reset(int64_t newpos) { +BufferedStreamImpl<T>::reset(int64_t newpos) { assert(newpos >= 0); if (StreamBase<T>::m_status == Error) return -2; // check to see if we have this position @@ -158,7 +158,7 @@ } template <class T> int64_t -BufferedStream<T>::skip(int64_t ntoskip) { +BufferedStreamImpl<T>::skip(int64_t ntoskip) { const T *begin; int32_t nread; int64_t skipped = 0; @@ -174,6 +174,6 @@ return skipped; } -} // end namespace Strigi +CL_NS_END #endif Modified: branches/lucene2_3_2/src/core/CLucene/util/_streambase.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/util/_streambase.h 2009-03-30 20:54:55 UTC (rev 2972) +++ branches/lucene2_3_2/src/core/CLucene/util/_streambase.h 2009-03-30 20:57:49 UTC (rev 2973) @@ -1,13 +1,13 @@ -#ifndef STRIGI_STREAMBASE_H -#define STRIGI_STREAMBASE_H +#ifndef JSTREAMS_STREAMBASE_H +#define JSTREAMS_STREAMBASE_H #include <stdio.h> #include <string> #define INT32MAX 0x7FFFFFFFL -namespace jstreams { +CL_NS_DEF(util) /** Used to indicate the current status of a Stream */ enum StreamStatus { @@ -173,13 +173,6 @@ }; -/** Abstract class for a stream of bytes */ -typedef StreamBase<char> InputStream; - -/** Abstract class for a stream of Unicode characters */ -typedef StreamBase<wchar_t> Reader; - - template <class T> int64_t StreamBase<T>::skip(int64_t ntoskip) { @@ -207,6 +200,6 @@ return skipped; } -} // end namespace Strigi +CL_NS_END #endif Modified: branches/lucene2_3_2/src/core/CLucene/util/_streambuffer.h =================================================================== --- branches/lucene2_3_2/src/core/CLucene/util/_streambuffer.h 2009-03-30 20:54:55 UTC (rev 2972) +++ branches/lucene2_3_2/src/core/CLucene/util/_streambuffer.h 2009-03-30 20:57:49 UTC (rev 2973) @@ -1,11 +1,11 @@ -#ifndef STRIGI_STREAMBUFFER_H -#define STRIGI_STREAMBUFFER_H +#ifndef JSTREAM_STREAMBUFFER_H +#define JSTREAM_STREAMBUFFER_H #include <cstdlib> #include <cstring> -namespace jstreams { +CL_NS_DEF(util) /** * @internal @@ -157,6 +157,6 @@ return max; } -} // end namespace Strigi +CL_NS_END #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |