Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Common/OutMemStream.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // OutMemStream.h | |
2 | |
3 #ifndef __OUTMEMSTREAM_H | |
4 #define __OUTMEMSTREAM_H | |
5 | |
6 #include "Common/MyCom.h" | |
7 #include "MemBlocks.h" | |
8 | |
9 class COutMemStream: | |
10 public IOutStream, | |
11 public CMyUnknownImp | |
12 { | |
13 CMemBlockManagerMt *_memManager; | |
14 size_t _curBlockIndex; | |
15 size_t _curBlockPos; | |
16 bool _realStreamMode; | |
17 | |
18 bool _unlockEventWasSent; | |
19 NWindows::NSynchronization::CAutoResetEvent StopWritingEvent; | |
20 NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent; | |
21 // NWindows::NSynchronization::CAutoResetEvent NoLockEvent; | |
22 | |
23 HRESULT StopWriteResult; | |
24 CMemLockBlocks Blocks; | |
25 | |
26 UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; } | |
27 | |
28 CMyComPtr<ISequentialOutStream> OutSeqStream; | |
29 CMyComPtr<IOutStream> OutStream; | |
30 | |
31 public: | |
32 | |
33 HRes CreateEvents() | |
34 { | |
35 RINOK(StopWritingEvent.CreateIfNotCreated()); | |
36 return WriteToRealStreamEvent.CreateIfNotCreated(); | |
37 } | |
38 | |
39 void SetOutStream(IOutStream *outStream) | |
40 { | |
41 OutStream = outStream; | |
42 OutSeqStream = outStream; | |
43 } | |
44 | |
45 void SetSeqOutStream(ISequentialOutStream *outStream) | |
46 { | |
47 OutStream = NULL; | |
48 OutSeqStream = outStream; | |
49 } | |
50 | |
51 void ReleaseOutStream() | |
52 { | |
53 OutStream.Release(); | |
54 OutSeqStream.Release(); | |
55 } | |
56 | |
57 COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager) { } | |
58 | |
59 ~COutMemStream() { Free(); } | |
60 void Free(); | |
61 | |
62 void Init(); | |
63 HRESULT WriteToRealStream(); | |
64 | |
65 void DetachData(CMemLockBlocks &blocks); | |
66 | |
67 bool WasUnlockEventSent() const { return _unlockEventWasSent; } | |
68 | |
69 void SetRealStreamMode() | |
70 { | |
71 _unlockEventWasSent = true; | |
72 WriteToRealStreamEvent.Set(); | |
73 } | |
74 | |
75 /* | |
76 void SetNoLockMode() | |
77 { | |
78 _unlockEventWasSent = true; | |
79 NoLockEvent.Set(); | |
80 } | |
81 */ | |
82 | |
83 void StopWriting(HRESULT res) | |
84 { | |
85 StopWriteResult = res; | |
86 StopWritingEvent.Set(); | |
87 } | |
88 | |
89 MY_UNKNOWN_IMP | |
90 | |
91 STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); | |
92 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); | |
93 STDMETHOD(SetSize)(Int64 newSize); | |
94 }; | |
95 | |
96 #endif |