bufferstream.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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

Generated on Sat Feb 17 20:50:47 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1