OutBuffer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // OutBuffer.h
  2. #ifndef __OUTBUFFER_H
  3. #define __OUTBUFFER_H
  4. #include "../IStream.h"
  5. #include "../../Common/MyCom.h"
  6. #include "../../Common/MyException.h"
  7. #ifndef _NO_EXCEPTIONS
  8. struct COutBufferException: public CSystemException
  9. {
  10. COutBufferException(HRESULT errorCode): CSystemException(errorCode) {}
  11. };
  12. #endif
  13. class COutBuffer
  14. {
  15. protected:
  16. Byte *_buffer;
  17. UInt32 _pos;
  18. UInt32 _limitPos;
  19. UInt32 _streamPos;
  20. UInt32 _bufferSize;
  21. CMyComPtr<ISequentialOutStream> _stream;
  22. UInt64 _processedSize;
  23. Byte *_buffer2;
  24. bool _overDict;
  25. HRESULT FlushPart();
  26. public:
  27. #ifdef _NO_EXCEPTIONS
  28. HRESULT ErrorCode;
  29. #endif
  30. COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
  31. ~COutBuffer() { Free(); }
  32. bool Create(UInt32 bufferSize);
  33. void Free();
  34. void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
  35. void SetStream(ISequentialOutStream *stream);
  36. void Init();
  37. HRESULT Flush();
  38. void FlushWithCheck();
  39. void ReleaseStream() { _stream.Release(); }
  40. void WriteByte(Byte b)
  41. {
  42. _buffer[_pos++] = b;
  43. if(_pos == _limitPos)
  44. FlushWithCheck();
  45. }
  46. void WriteBytes(const void *data, size_t size)
  47. {
  48. for (size_t i = 0; i < size; i++)
  49. WriteByte(((const Byte *)data)[i]);
  50. }
  51. UInt64 GetProcessedSize() const;
  52. };
  53. #endif