00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef neo_file_bufferstream_h
00022 #define neo_file_bufferstream_h
00023
00027 #include "../core/platform.h"
00028 #include "iostream.h"
00029
00030 namespace neo {
00031 namespace file {
00032
00039 class BufferStreamBuf : public std::basic_streambuf< char >, public core::Noncopyable
00040 {
00041 public:
00042
00044
00049 BufferStreamBuf( unsigned char* p_buffer, unsigned int size, unsigned int mode );
00050
00052
00053 virtual ~BufferStreamBuf();
00054
00056
00058 void truncate( int64_t length );
00059
00061
00062 const unsigned char* getBuffer() const;
00063
00065
00066 unsigned int getBufferSize() const;
00067
00068 protected:
00069
00070 typedef std::basic_streambuf< char >::pos_type pos_type;
00071 typedef std::basic_streambuf< char >::off_type off_type;
00072 typedef std::basic_streambuf< char >::int_type int_type;
00073 typedef std::basic_streambuf< char >::traits_type traits_type;
00074
00076 unsigned char* _p_buffer;
00077
00079 unsigned int _size;
00080
00082 unsigned int _storesize;
00083
00085 unsigned int _mode;
00086
00088
00092 virtual std::basic_streambuf< char >* setbuf( char* p_buffer, std::streamsize size );
00093
00095
00100 virtual pos_type seekoff( off_type offset, std::ios_base::seekdir dir, std::ios_base::openmode mode );
00101
00103
00107 virtual pos_type seekpos( pos_type position, std::ios_base::openmode mode );
00108
00110
00112 virtual int_type underflow();
00113
00115
00118 virtual int_type overflow( int_type c );
00119
00120 friend class BufferStream;
00121 };
00122
00128 class BufferStream : public IOStream
00129 {
00130 public:
00131
00133
00141 BufferStream( unsigned char* p_buffer = 0, unsigned int size = 0, unsigned int mode = ( IN | BINARY ) );
00142
00144
00145 virtual ~BufferStream();
00146
00148
00150 virtual void truncate( int64_t length );
00151
00153
00155 virtual void determineBinaryMode( unsigned int num = 8 );
00156
00158
00159 const unsigned char* getBuffer() const;
00160
00161 virtual BufferStream* clone() const;
00162
00163 protected:
00164
00166 BufferStreamBuf* _p_buf;
00167
00169 std::iostream* _p_stream;
00170 };
00171
00172 }
00173 }
00174
00175 #endif