Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | // StreamObjects.h |
michael@0 | 2 | |
michael@0 | 3 | #ifndef __STREAMOBJECTS_H |
michael@0 | 4 | #define __STREAMOBJECTS_H |
michael@0 | 5 | |
michael@0 | 6 | #include "../../Common/DynamicBuffer.h" |
michael@0 | 7 | #include "../../Common/MyCom.h" |
michael@0 | 8 | #include "../IStream.h" |
michael@0 | 9 | |
michael@0 | 10 | class CSequentialInStreamImp: |
michael@0 | 11 | public ISequentialInStream, |
michael@0 | 12 | public CMyUnknownImp |
michael@0 | 13 | { |
michael@0 | 14 | const Byte *_dataPointer; |
michael@0 | 15 | size_t _size; |
michael@0 | 16 | size_t _pos; |
michael@0 | 17 | |
michael@0 | 18 | public: |
michael@0 | 19 | void Init(const Byte *dataPointer, size_t size) |
michael@0 | 20 | { |
michael@0 | 21 | _dataPointer = dataPointer; |
michael@0 | 22 | _size = size; |
michael@0 | 23 | _pos = 0; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | MY_UNKNOWN_IMP |
michael@0 | 27 | |
michael@0 | 28 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | |
michael@0 | 32 | class CWriteBuffer |
michael@0 | 33 | { |
michael@0 | 34 | CByteDynamicBuffer _buffer; |
michael@0 | 35 | size_t _size; |
michael@0 | 36 | public: |
michael@0 | 37 | CWriteBuffer(): _size(0) {} |
michael@0 | 38 | void Init() { _size = 0; } |
michael@0 | 39 | void Write(const void *data, size_t size); |
michael@0 | 40 | size_t GetSize() const { return _size; } |
michael@0 | 41 | const CByteDynamicBuffer& GetBuffer() const { return _buffer; } |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | class CSequentialOutStreamImp: |
michael@0 | 45 | public ISequentialOutStream, |
michael@0 | 46 | public CMyUnknownImp |
michael@0 | 47 | { |
michael@0 | 48 | CWriteBuffer _writeBuffer; |
michael@0 | 49 | public: |
michael@0 | 50 | void Init() { _writeBuffer.Init(); } |
michael@0 | 51 | size_t GetSize() const { return _writeBuffer.GetSize(); } |
michael@0 | 52 | const CByteDynamicBuffer& GetBuffer() const { return _writeBuffer.GetBuffer(); } |
michael@0 | 53 | |
michael@0 | 54 | MY_UNKNOWN_IMP |
michael@0 | 55 | |
michael@0 | 56 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | class CSequentialOutStreamImp2: |
michael@0 | 60 | public ISequentialOutStream, |
michael@0 | 61 | public CMyUnknownImp |
michael@0 | 62 | { |
michael@0 | 63 | Byte *_buffer; |
michael@0 | 64 | public: |
michael@0 | 65 | size_t _size; |
michael@0 | 66 | size_t _pos; |
michael@0 | 67 | |
michael@0 | 68 | void Init(Byte *buffer, size_t size) |
michael@0 | 69 | { |
michael@0 | 70 | _buffer = buffer; |
michael@0 | 71 | _pos = 0; |
michael@0 | 72 | _size = size; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | MY_UNKNOWN_IMP |
michael@0 | 76 | |
michael@0 | 77 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | class CSequentialInStreamSizeCount: |
michael@0 | 81 | public ISequentialInStream, |
michael@0 | 82 | public CMyUnknownImp |
michael@0 | 83 | { |
michael@0 | 84 | CMyComPtr<ISequentialInStream> _stream; |
michael@0 | 85 | UInt64 _size; |
michael@0 | 86 | public: |
michael@0 | 87 | void Init(ISequentialInStream *stream) |
michael@0 | 88 | { |
michael@0 | 89 | _stream = stream; |
michael@0 | 90 | _size = 0; |
michael@0 | 91 | } |
michael@0 | 92 | UInt64 GetSize() const { return _size; } |
michael@0 | 93 | |
michael@0 | 94 | MY_UNKNOWN_IMP |
michael@0 | 95 | |
michael@0 | 96 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | class CSequentialInStreamRollback: |
michael@0 | 100 | public ISequentialInStream, |
michael@0 | 101 | public CMyUnknownImp |
michael@0 | 102 | { |
michael@0 | 103 | CMyComPtr<ISequentialInStream> _stream; |
michael@0 | 104 | Byte *_buffer; |
michael@0 | 105 | size_t _bufferSize; |
michael@0 | 106 | UInt64 _size; |
michael@0 | 107 | |
michael@0 | 108 | size_t _currentSize; |
michael@0 | 109 | size_t _currentPos; |
michael@0 | 110 | public: |
michael@0 | 111 | CSequentialInStreamRollback(size_t bufferSize): |
michael@0 | 112 | _bufferSize(bufferSize), |
michael@0 | 113 | _buffer(0) |
michael@0 | 114 | { |
michael@0 | 115 | _buffer = new Byte[bufferSize]; |
michael@0 | 116 | } |
michael@0 | 117 | ~CSequentialInStreamRollback() |
michael@0 | 118 | { |
michael@0 | 119 | delete _buffer; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | void Init(ISequentialInStream *stream) |
michael@0 | 123 | { |
michael@0 | 124 | _stream = stream; |
michael@0 | 125 | _size = 0; |
michael@0 | 126 | _currentSize = 0; |
michael@0 | 127 | _currentPos = 0; |
michael@0 | 128 | } |
michael@0 | 129 | UInt64 GetSize() const { return _size; } |
michael@0 | 130 | |
michael@0 | 131 | MY_UNKNOWN_IMP |
michael@0 | 132 | |
michael@0 | 133 | STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 134 | HRESULT Rollback(size_t rollbackSize); |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | class CSequentialOutStreamSizeCount: |
michael@0 | 138 | public ISequentialOutStream, |
michael@0 | 139 | public CMyUnknownImp |
michael@0 | 140 | { |
michael@0 | 141 | CMyComPtr<ISequentialOutStream> _stream; |
michael@0 | 142 | UInt64 _size; |
michael@0 | 143 | public: |
michael@0 | 144 | void Init(ISequentialOutStream *stream) |
michael@0 | 145 | { |
michael@0 | 146 | _stream = stream; |
michael@0 | 147 | _size = 0; |
michael@0 | 148 | } |
michael@0 | 149 | UInt64 GetSize() const { return _size; } |
michael@0 | 150 | |
michael@0 | 151 | MY_UNKNOWN_IMP |
michael@0 | 152 | |
michael@0 | 153 | STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); |
michael@0 | 154 | }; |
michael@0 | 155 | |
michael@0 | 156 | #endif |