other-licenses/7zstub/src/7zip/Common/StreamObjects.h

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

mercurial