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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/7zip/Common/OutBuffer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +// OutBuffer.h
     1.5 +
     1.6 +#ifndef __OUTBUFFER_H
     1.7 +#define __OUTBUFFER_H
     1.8 +
     1.9 +#include "../IStream.h"
    1.10 +#include "../../Common/MyCom.h"
    1.11 +
    1.12 +#ifndef _NO_EXCEPTIONS
    1.13 +struct COutBufferException
    1.14 +{
    1.15 +  HRESULT ErrorCode;
    1.16 +  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
    1.17 +};
    1.18 +#endif
    1.19 +
    1.20 +class COutBuffer
    1.21 +{
    1.22 +protected:
    1.23 +  Byte *_buffer;
    1.24 +  UInt32 _pos;
    1.25 +  UInt32 _limitPos;
    1.26 +  UInt32 _streamPos;
    1.27 +  UInt32 _bufferSize;
    1.28 +  CMyComPtr<ISequentialOutStream> _stream;
    1.29 +  UInt64 _processedSize;
    1.30 +  Byte  *_buffer2;
    1.31 +  bool _overDict;
    1.32 +
    1.33 +  HRESULT FlushPart();
    1.34 +  void FlushWithCheck();
    1.35 +public:
    1.36 +  #ifdef _NO_EXCEPTIONS
    1.37 +  HRESULT ErrorCode;
    1.38 +  #endif
    1.39 +
    1.40 +  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
    1.41 +  ~COutBuffer() { Free(); }
    1.42 +  
    1.43 +  bool Create(UInt32 bufferSize);
    1.44 +  void Free();
    1.45 +
    1.46 +  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
    1.47 +  void SetStream(ISequentialOutStream *stream);
    1.48 +  void Init();
    1.49 +  HRESULT Flush();
    1.50 +  void ReleaseStream() {  _stream.Release(); }
    1.51 +
    1.52 +  void WriteByte(Byte b)
    1.53 +  {
    1.54 +    _buffer[_pos++] = b;
    1.55 +    if(_pos == _limitPos)
    1.56 +      FlushWithCheck();
    1.57 +  }
    1.58 +  void WriteBytes(const void *data, size_t size)
    1.59 +  {
    1.60 +    for (size_t i = 0; i < size; i++)
    1.61 +      WriteByte(((const Byte *)data)[i]);
    1.62 +  }
    1.63 +
    1.64 +  UInt64 GetProcessedSize() const;
    1.65 +};
    1.66 +
    1.67 +#endif

mercurial