src/stream/ZStream_Buffered.h

00001 /*  @(#) $Id: ZStream_Buffered.h,v 1.6 2007/01/10 01:28:06 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2004 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_Buffered__
00026 #define __ZStream_Buffered__ 1
00027 
00028 #include "zconfig.h"
00029 
00030 #include "ZStreamer.h"
00031 
00032 // =================================================================================================
00033 #pragma mark -
00034 #pragma mark * ZStreamR_Buffered
00035 
00037 
00038 class ZStreamR_Buffered : public ZStreamR
00039         {
00040 public:
00041         ZStreamR_Buffered(size_t iBufferSize, const ZStreamR& iStreamSource);
00042         ~ZStreamR_Buffered();
00043 
00044 // From ZStreamR
00045         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00046         virtual size_t Imp_CountReadable();
00047         virtual void Imp_Skip(uint64 iCount, uint64* oCountSkipped);
00048 
00049 // Our protocol
00051         void Abandon();
00052 
00053 protected:
00054         const ZStreamR& fStreamSource;
00055         uint8* fBuffer;
00056         size_t fBufferSize;
00057         size_t fBufferOffset;
00058         };
00059 
00060 typedef ZStreamerR_FT<ZStreamR_Buffered> ZStreamerR_Buffered;
00061 
00062 // =================================================================================================
00063 #pragma mark -
00064 #pragma mark * ZStreamW_Buffered
00065 
00067 
00068 class ZStreamW_Buffered : public ZStreamW
00069         {
00070 public:
00071         ZStreamW_Buffered(size_t iBufferSize, const ZStreamW& iStreamSink);
00072         ~ZStreamW_Buffered();
00073 
00074 // From ZStreamW
00075         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00076         virtual void Imp_Flush();
00077 
00078 // Our protocol
00079         void Abandon();
00080 
00081 protected:
00082         void Internal_Flush();
00083 
00084         const ZStreamW& fStreamSink;
00085         uint8* fBuffer;
00086         size_t fBufferSize;
00087         size_t fBufferOffset;
00088         };
00089 
00090 typedef ZStreamerW_FT<ZStreamW_Buffered> ZStreamerW_Buffered;
00091 
00092 // =================================================================================================
00093 #pragma mark -
00094 #pragma mark * ZStreamR_DynamicBuffered
00095 
00097 
00098 class ZStreamR_DynamicBuffered : public ZStreamR
00099         {
00100 public:
00101         ZStreamR_DynamicBuffered(const ZStreamR& iStreamSource, const ZStreamRWPos& iStreamBuffer);
00102         ~ZStreamR_DynamicBuffered();
00103 
00104 // From ZStreamR
00105         virtual void Imp_Read(void* iDest, size_t iCount, size_t* oCountRead);
00106         virtual size_t Imp_CountReadable();
00107 
00108 // Our protocol
00109         void Rewind();
00110         void Commit();
00111 
00112 protected:
00113         const ZStreamR& fStreamSource;
00114         const ZStreamRWPos& fStreamBuffer;
00115         enum { eModeReadBufferThenAppend, eModeReadBufferThenStream, eModeAppend, eModeStream } fMode;
00116         };
00117 
00118 // =================================================================================================
00119 #pragma mark -
00120 #pragma mark * ZStreamerR_DynamicBuffered
00121 
00123 
00124 class ZStreamerR_DynamicBuffered : public ZStreamerR
00125         {
00126 public:
00127         ZStreamerR_DynamicBuffered(ZRef<ZStreamerR> iStreamerSource,
00128                 ZRef<ZStreamerRWPos> iStreamerBuffer);
00129 
00130         virtual ~ZStreamerR_DynamicBuffered();
00131 
00132 // From ZStreamerR
00133         virtual const ZStreamR& GetStreamR();
00134 
00135 // Our protocol
00136         ZStreamR_DynamicBuffered& GetStream();
00137 
00138 protected:
00139         ZRef<ZStreamerR> fStreamerSource;
00140         ZRef<ZStreamerR> fStreamerBuffer;
00141         ZStreamR_DynamicBuffered fStream;
00142         };
00143 
00144 // =================================================================================================
00145 #pragma mark -
00146 #pragma mark * ZStreamW_DynamicBuffered
00147 
00149 
00150 class ZStreamW_DynamicBuffered : public ZStreamW
00151         {
00152 public:
00153         ZStreamW_DynamicBuffered(const ZStreamW& iStreamSink, const ZStreamRWPos& iStreamBuffer);
00154         ~ZStreamW_DynamicBuffered();
00155 
00156 // From ZStreamW
00157         virtual void Imp_Write(const void* iSource, size_t iCount, size_t* oCountWritten);
00158 
00159         virtual void Imp_CopyFromDispatch(const ZStreamR& iStreamR, uint64 iCount,
00160                 uint64* oCountRead, uint64* oCountWritten);
00161 
00162         virtual void Imp_CopyFrom(const ZStreamR& iStreamR, uint64 iCount,
00163                 uint64* oCountRead, uint64* oCountWritten);
00164 
00165         virtual void Imp_Flush();
00166 
00167 protected:
00168         void Internal_Flush();
00169 
00170         const ZStreamW& fStreamSink;
00171         const ZStreamRWPos& fStreamBuffer;
00172         };
00173 
00174 // =================================================================================================
00175 #pragma mark -
00176 #pragma mark * ZStreamerW_DynamicBuffered
00177 
00179 
00180 class ZStreamerW_DynamicBuffered : public ZStreamerW
00181         {
00182 public:
00183         ZStreamerW_DynamicBuffered(
00184                 ZRef<ZStreamerW> iStreamerReal, ZRef<ZStreamerRWPos> iStreamerBuffer);
00185 
00186         virtual ~ZStreamerW_DynamicBuffered();
00187 
00188 // From ZStreamerW
00189         virtual const ZStreamW& GetStreamW();
00190 
00191 protected:
00192         ZRef<ZStreamerW> fStreamerSink;
00193         ZRef<ZStreamerRWPos> fStreamerBuffer;
00194         ZStreamW_DynamicBuffered fStream;
00195         };
00196 
00197 #endif // __ZStream_Buffered__

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