Imported Upstream version 9.20
[platform/upstream/7zip.git] / CPP / 7zip / Archive / Common / InStreamWithCRC.h
1 // InStreamWithCRC.h\r
2 \r
3 #ifndef __IN_STREAM_WITH_CRC_H\r
4 #define __IN_STREAM_WITH_CRC_H\r
5 \r
6 #include "../../../../C/7zCrc.h"\r
7 \r
8 #include "../../../Common/MyCom.h"\r
9 \r
10 #include "../../IStream.h"\r
11 \r
12 class CSequentialInStreamWithCRC:\r
13   public ISequentialInStream,\r
14   public CMyUnknownImp\r
15 {\r
16 public:\r
17   MY_UNKNOWN_IMP\r
18 \r
19   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r
20 private:\r
21   CMyComPtr<ISequentialInStream> _stream;\r
22   UInt64 _size;\r
23   UInt32 _crc;\r
24   bool _wasFinished;\r
25 public:\r
26   void SetStream(ISequentialInStream *stream) { _stream = stream;  }\r
27   void Init()\r
28   {\r
29     _size = 0;\r
30     _wasFinished = false;\r
31     _crc = CRC_INIT_VAL;\r
32   }\r
33   void ReleaseStream() { _stream.Release(); }\r
34   UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r
35   UInt64 GetSize() const { return _size; }\r
36   bool WasFinished() const { return _wasFinished; }\r
37 };\r
38 \r
39 class CInStreamWithCRC:\r
40   public IInStream,\r
41   public CMyUnknownImp\r
42 {\r
43 public:\r
44   MY_UNKNOWN_IMP1(IInStream)\r
45 \r
46   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);\r
47   STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);\r
48 private:\r
49   CMyComPtr<IInStream> _stream;\r
50   UInt64 _size;\r
51   UInt32 _crc;\r
52   // bool _wasFinished;\r
53 public:\r
54   void SetStream(IInStream *stream) { _stream = stream;  }\r
55   void Init()\r
56   {\r
57     _size = 0;\r
58     // _wasFinished = false;\r
59     _crc = CRC_INIT_VAL;\r
60   }\r
61   void ReleaseStream() { _stream.Release(); }\r
62   UInt32 GetCRC() const { return CRC_GET_DIGEST(_crc); }\r
63   UInt64 GetSize() const { return _size; }\r
64   // bool WasFinished() const { return _wasFinished; }\r
65 };\r
66 \r
67 #endif\r