src/stream/ZStream_ZLib.h

00001 /*  @(#) $Id: ZStream_ZLib.h,v 1.10 2006/04/10 20:44:21 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2002 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023 ------------------------------------------------------------ */
00024 
00025 #ifndef __ZStream_ZLib__
00026 #define __ZStream_ZLib__ 1
00027 #include "zconfig.h"
00028 #include "ZCONFIG_API.h"
00029 #include "ZCONFIG_SPI.h"
00030 
00031 #ifndef ZCONFIG_API_Avail__Stream_ZLib
00032 #       define ZCONFIG_API_Avail__Stream_ZLib ZCONFIG_SPI_Enabled(zlib)
00033 #endif
00034 
00035 #ifndef ZCONFIG_API_Desired__Stream_ZLib
00036 #       define ZCONFIG_API_Desired__Stream_ZLib 1
00037 #endif
00038 
00039 #include "ZStreamer.h"
00040 
00041 #if ZCONFIG_API_Enabled(Stream_ZLib)
00042 
00043 #include <zlib.h>
00044 
00045 // =================================================================================================
00046 #pragma mark -
00047 #pragma mark * ZStreamR_ZLibDecode
00048 
00050 
00051 class ZStreamR_ZLibDecode : public ZStreamR
00052         {
00053 public:
00054         ZStreamR_ZLibDecode(const ZStreamR& iStreamSource);
00055         ZStreamR_ZLibDecode(size_t iBufferSize, const ZStreamR& iStreamSource);
00056         ~ZStreamR_ZLibDecode();
00057 
00058 // From ZStreamR
00059         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00060         virtual size_t Imp_CountReadable();
00061 
00062 protected:
00063         void Internal_Init(size_t iBufferSize);
00064 
00065         const ZStreamR& fStreamSource;
00066         z_stream fState;
00067         Bytef* fBuffer;
00068         size_t fBufferSize;
00069         };
00070 
00071 typedef ZStreamerR_FT<ZStreamR_ZLibDecode> ZStreamerR_ZLibDecode;
00072 
00073 // =================================================================================================
00074 #pragma mark -
00075 #pragma mark * ZStreamW_ZLibEncode
00076 
00078 
00079 class ZStreamW_ZLibEncode : public ZStreamW
00080         {
00081 public:
00082         ZStreamW_ZLibEncode(int iCompressionLevel, const ZStreamW& iStreamSink);
00083         ZStreamW_ZLibEncode(int iCompressionLevel, size_t iBufferSize, const ZStreamW& iStreamSink);
00084         ~ZStreamW_ZLibEncode();
00085 
00086 // From ZStreamW
00087         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00088         virtual void Imp_Flush();
00089 
00090 protected:
00091         void Internal_Init(int iCompressionLevel, size_t iBufferSize);
00092         void Internal_Flush();
00093 
00094         const ZStreamW& fStreamSink;
00095         z_stream fState;
00096         Bytef* fBuffer;
00097         size_t fBufferSize;
00098         };
00099 
00100 // =================================================================================================
00101 #pragma mark -
00102 #pragma mark * ZStreamerW_ZLibEncode
00103 
00105 
00106 class ZStreamerW_ZLibEncode : public ZStreamerW
00107         {
00108 public:
00109         ZStreamerW_ZLibEncode(int iCompressionLevel, ZRef<ZStreamerW> iStreamer);
00110         ZStreamerW_ZLibEncode(int iCompressionLevel, size_t iBufferSize, ZRef<ZStreamerW> iStreamer);
00111 
00112         virtual ~ZStreamerW_ZLibEncode();
00113 
00114 // From ZStreamerW
00115         virtual const ZStreamW& GetStreamW();
00116 
00117 protected:
00118         ZRef<ZStreamerW> fStreamer;
00119         ZStreamW_ZLibEncode fStream;
00120         };
00121 
00122 // =================================================================================================
00123 
00124 #endif // ZCONFIG_API_Enabled(Stream_ZLib)
00125 
00126 #endif // __ZStream_ZLib__

Generated on Thu Jul 26 11:21:54 2007 for ZooLib by  doxygen 1.4.7