view 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
line wrap: on
line source
1 // OutMemStream.h
3 #ifndef __OUTMEMSTREAM_H
4 #define __OUTMEMSTREAM_H
6 #include "Common/MyCom.h"
7 #include "MemBlocks.h"
9 class COutMemStream:
10 public IOutStream,
11 public CMyUnknownImp
12 {
13 CMemBlockManagerMt *_memManager;
14 size_t _curBlockIndex;
15 size_t _curBlockPos;
16 bool _realStreamMode;
18 bool _unlockEventWasSent;
19 NWindows::NSynchronization::CAutoResetEvent StopWritingEvent;
20 NWindows::NSynchronization::CAutoResetEvent WriteToRealStreamEvent;
21 // NWindows::NSynchronization::CAutoResetEvent NoLockEvent;
23 HRESULT StopWriteResult;
24 CMemLockBlocks Blocks;
26 UInt64 GetPos() const { return (UInt64)_curBlockIndex * _memManager->GetBlockSize() + _curBlockPos; }
28 CMyComPtr<ISequentialOutStream> OutSeqStream;
29 CMyComPtr<IOutStream> OutStream;
31 public:
33 HRes CreateEvents()
34 {
35 RINOK(StopWritingEvent.CreateIfNotCreated());
36 return WriteToRealStreamEvent.CreateIfNotCreated();
37 }
39 void SetOutStream(IOutStream *outStream)
40 {
41 OutStream = outStream;
42 OutSeqStream = outStream;
43 }
45 void SetSeqOutStream(ISequentialOutStream *outStream)
46 {
47 OutStream = NULL;
48 OutSeqStream = outStream;
49 }
51 void ReleaseOutStream()
52 {
53 OutStream.Release();
54 OutSeqStream.Release();
55 }
57 COutMemStream(CMemBlockManagerMt *memManager): _memManager(memManager) { }
59 ~COutMemStream() { Free(); }
60 void Free();
62 void Init();
63 HRESULT WriteToRealStream();
65 void DetachData(CMemLockBlocks &blocks);
67 bool WasUnlockEventSent() const { return _unlockEventWasSent; }
69 void SetRealStreamMode()
70 {
71 _unlockEventWasSent = true;
72 WriteToRealStreamEvent.Set();
73 }
75 /*
76 void SetNoLockMode()
77 {
78 _unlockEventWasSent = true;
79 NoLockEvent.Set();
80 }
81 */
83 void StopWriting(HRESULT res)
84 {
85 StopWriteResult = res;
86 StopWritingEvent.Set();
87 }
89 MY_UNKNOWN_IMP
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 };
96 #endif