3 #ifndef __STREAM_OBJECTS_H
\r
4 #define __STREAM_OBJECTS_H
\r
6 #include "../../Common/Buffer.h"
\r
7 #include "../../Common/MyCom.h"
\r
8 #include "../IStream.h"
\r
10 struct CReferenceBuf:
\r
12 public CMyUnknownImp
\r
20 public CMyUnknownImp
\r
25 CMyComPtr<IUnknown> _ref;
\r
27 void Init(const Byte *data, size_t size, IUnknown *ref = 0)
\r
34 void Init(CReferenceBuf *ref) { Init(ref->Buf, ref->Buf.GetCapacity(), ref); }
\r
36 MY_UNKNOWN_IMP1(IInStream)
\r
37 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
\r
38 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
\r
41 class CByteDynBuffer
\r
46 CByteDynBuffer(): _capacity(0), _buf(0) {};
\r
47 // there is no copy constructor. So don't copy this object.
\r
48 ~CByteDynBuffer() { Free(); }
\r
50 size_t GetCapacity() const { return _capacity; }
\r
51 operator Byte*() const { return _buf; };
\r
52 operator const Byte*() const { return _buf; };
\r
53 bool EnsureCapacity(size_t capacity);
\r
56 class CDynBufSeqOutStream:
\r
57 public ISequentialOutStream,
\r
58 public CMyUnknownImp
\r
60 CByteDynBuffer _buffer;
\r
63 CDynBufSeqOutStream(): _size(0) {}
\r
64 void Init() { _size = 0; }
\r
65 size_t GetSize() const { return _size; }
\r
66 const Byte *GetBuffer() const { return _buffer; }
\r
67 void CopyToBuffer(CByteBuffer &dest) const;
\r
68 Byte *GetBufPtrForWriting(size_t addSize);
\r
69 void UpdateSize(size_t addSize) { _size += addSize; }
\r
72 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
\r
75 class CBufPtrSeqOutStream:
\r
76 public ISequentialOutStream,
\r
77 public CMyUnknownImp
\r
83 void Init(Byte *buffer, size_t size)
\r
89 size_t GetPos() const { return _pos; }
\r
92 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
\r
95 class CSequentialOutStreamSizeCount:
\r
96 public ISequentialOutStream,
\r
97 public CMyUnknownImp
\r
99 CMyComPtr<ISequentialOutStream> _stream;
\r
102 void SetStream(ISequentialOutStream *stream) { _stream = stream; }
\r
103 void Init() { _size = 0; }
\r
104 UInt64 GetSize() const { return _size; }
\r
107 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
\r
110 class CCachedInStream:
\r
112 public CMyUnknownImp
\r
117 unsigned _blockSizeLog;
\r
118 unsigned _numBlocksLog;
\r
122 virtual HRESULT ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize) = 0;
\r
124 CCachedInStream(): _tags(0), _data(0) {}
\r
125 virtual ~CCachedInStream() { Free(); } // the destructor must be virtual (release calls it) !!!
\r
127 bool Alloc(unsigned blockSizeLog, unsigned numBlocksLog);
\r
128 void Init(UInt64 size);
\r
130 MY_UNKNOWN_IMP2(ISequentialInStream, IInStream)
\r
131 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
\r
132 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
\r