Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/zStreamBuf.h

Go to the documentation of this file.
00001 // Filename: zStreamBuf.h
00002 // Created by:  drose (05Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef ZSTREAMBUF_H
00020 #define ZSTREAMBUF_H
00021 
00022 #include "pandabase.h"
00023 
00024 // This module is not compiled if zlib is not available.
00025 #ifdef HAVE_ZLIB
00026 
00027 #include <zlib.h>
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : ZStreamBuf
00031 // Description : The streambuf object that implements
00032 //               IDecompressStream and OCompressStream.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDAEXPRESS ZStreamBuf : public streambuf {
00035 public:
00036   ZStreamBuf();
00037   virtual ~ZStreamBuf();
00038 
00039   void open_read(istream *source, bool owns_source);
00040   void close_read();
00041 
00042   void open_write(ostream *dest, bool owns_dest, int compression_level);
00043   void close_write();
00044 
00045 protected:
00046   virtual int overflow(int c);
00047   virtual int sync(void);
00048   virtual int underflow(void);
00049 
00050 private:
00051   size_t read_chars(char *start, size_t length);
00052   void write_chars(const char *start, size_t length, int flush);
00053   void show_zlib_error(const char *function, int error_code, z_stream &z);
00054 
00055 private:
00056   istream *_source;
00057   bool _owns_source;
00058 
00059   ostream *_dest;
00060   bool _owns_dest;
00061 
00062   z_stream _z_source;
00063   z_stream _z_dest;
00064 
00065   // We need to store the decompression buffer on the class object,
00066   // because zlib might not consume all of the input characters at
00067   // each call to inflate().  This isn't a problem on output because
00068   // in that case we can afford to wait until it does consume all of
00069   // the characters we give it.
00070   enum {
00071     // It's not clear how large or small this buffer ought to be.  It
00072     // doesn't seem to matter much, especially since this is just a
00073     // temporary holding area before getting copied into zlib's own
00074     // internal buffers.
00075     decompress_buffer_size = 128
00076   };
00077   char decompress_buffer[decompress_buffer_size];
00078 };
00079 
00080 #endif  // HAVE_ZLIB
00081 
00082 #endif

Generated on Fri May 2 00:38:52 2003 for Panda by doxygen1.3