00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020 #ifndef FLC_STREAM_BUFFER_H
00021 #define FLC_STREAM_BUFFER_H
00022
00023 #include <falcon/stream.h>
00024
00025 namespace Falcon {
00026
00030 class FALCON_DYN_CLASS StreamBuffer: public Stream
00031 {
00032 public:
00033 enum {
00034 default_buffer_size = 4096
00035 } enum_default_buffer_size;
00036
00037 private:
00038 int32 m_bufSize;
00039 bool m_changed;
00040 byte *m_buffer;
00041 int32 m_bufPos;
00042 int32 m_bufLen;
00043
00044 uint64 m_filePos;
00045 bool m_bReseek;
00046
00047 Stream *m_stream;
00048 bool m_streamOwner;
00049
00050 bool refill();
00051
00052 protected:
00053 virtual int64 seek( int64 pos, e_whence whence );
00054
00055 public:
00056 StreamBuffer( Stream *underlying, bool bOwn = true, uint32 bufSize = default_buffer_size );
00057 StreamBuffer( const StreamBuffer &other );
00058 virtual ~StreamBuffer();
00059
00060 virtual FalconData *clone() const;
00061 virtual bool isStreamBuffer() const { return true; }
00062
00063
00067 Stream *underlying() const { return m_stream; }
00068
00069 virtual bool close();
00070 virtual int64 tell();
00071 virtual bool truncate( int64 pos=-1 );
00072 virtual int32 readAvailable( int32 msecs_timeout, const Sys::SystemData *sysData = 0 );
00073 virtual int32 writeAvailable( int32 msecs_timeout, const Sys::SystemData *sysData );
00074 virtual bool flush();
00075
00076 virtual bool get( uint32 &chr );
00077 virtual bool put( uint32 chr );
00078 virtual int32 read( void *buffer, int32 size );
00079 virtual int32 write( const void *buffer, int32 size );
00080
00081 virtual bool errorDescription( ::Falcon::String &description ) const {
00082 return m_stream->errorDescription( description );
00083 }
00084 virtual int64 lastError() const { return m_stream->lastError(); }
00085 virtual t_status status() const { return m_stream->status(); }
00086
00088 void detach() { m_stream = 0; m_streamOwner = false; }
00089
00090 bool resizeBuffer( uint32 size );
00091 uint32 bufferSize() const { return m_bufSize; }
00092 };
00093
00094 }
00095
00096 #endif
00097
00098