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

FXBzStream.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                         B Z S t r e a m   C l a s s e s                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1999, 2002 by Lyle Johnson. All Rights Reserved.                *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXBzStream.h,v 1.5 2002/04/09 23:06:47 fox Exp $                         *
00023 ********************************************************************************/
00024 #ifdef HAVE_BZ2LIB_H
00025 #ifndef FXBZSTREAM_H
00026 #define FXBZSTREAM_H
00027 
00028 #ifndef FXSTREAM_H
00029 #include "FXStream.h"
00030 #endif
00031 
00032 
00033 namespace FX {
00034 
00035 
00036 /// BZIP2 compressed file stream
00037 class FXAPI FXBzFileStream : public FXStream {
00038   void *file;
00039   void *bzfile;
00040 protected:
00041   virtual void saveItems(const void *buf,unsigned long n);
00042   virtual void loadItems(void *buf,unsigned long n);
00043 public:
00044 
00045   /// Create BZIP2 file stream
00046   FXBzFileStream(const FXObject* cont=NULL);
00047 
00048   /// Open file stream
00049   FXbool open(const char* filename,FXStreamDirection save_or_load);
00050 
00051   /// Close file stream
00052   FXbool close();
00053 
00054   /// Move to position
00055   virtual FXbool position(unsigned long p){ return FALSE; }
00056 
00057   /// Clean up
00058   virtual ~FXBzFileStream();
00059   };
00060 
00061 
00062 /// BZIP2 compressed memory stream
00063 class FXAPI FXBzMemoryStream : public FXStream {
00064 private:
00065   void         *strm;
00066   unsigned long bzpos;
00067   FXuchar      *ptr;
00068   FXuint        space;
00069   FXbool        owns;
00070 protected:
00071   virtual void saveItems(const void *buf, unsigned long n);
00072   virtual void loadItems(void *buf, unsigned long n);
00073   void finish();
00074 public:
00075 
00076   /// Create memory stream
00077   FXBzMemoryStream(const FXObject* cont=NULL);
00078 
00079   /// Open store
00080   FXbool open(FXuchar* data, FXStreamDirection);
00081 
00082   /// Open stream with specified size
00083   FXbool open(FXuchar* data, FXuint sp, FXStreamDirection);
00084 
00085   // Get available space
00086   unsigned long getSpace() const { return space; }
00087 
00088   /// Set available space
00089   void setSpace(unsigned long sp);
00090 
00091   /// Take buffer away from stream
00092   void takeBuffer(FXuchar*& buffer,unsigned long& sp);
00093 
00094   /// Give buffer to stream
00095   void giveBuffer(FXuchar *buffer,unsigned long sp);
00096 
00097   /// Move to position
00098   virtual FXbool position(unsigned long p) { return FALSE; }
00099 
00100   /// Get final size of compressed stream
00101   unsigned long getCompressedSize() const { return bzpos; }
00102 
00103   /// Close
00104   FXbool close();
00105 
00106   /// Destructor
00107   virtual ~FXBzMemoryStream();
00108   };
00109 
00110 }
00111 
00112 #endif
00113 #endif