File: OutByte.h

package info (click to toggle)
apngasm 2.91-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,760 kB
  • sloc: ansic: 34,259; cpp: 7,258; makefile: 40
file content (42 lines) | stat: -rw-r--r-- 745 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef __STREAM_OUTBYTE_H
#define __STREAM_OUTBYTE_H

#include "Portable.h"
#include "IInOutStreams.h"

namespace NStream {

class COutByte
{
  BYTE *m_Buffer;
  INT m_Pos;
  INT m_BufferSize;
  ISequentialOutStream* m_Stream;
  UINT64 m_ProcessedSize;

  void WriteBlock();
public:
  COutByte(INT aBufferSize = (1 << 20));
  ~COutByte();

  void Init(ISequentialOutStream *aStream);
  HRESULT Flush();

  void WriteByte(BYTE aByte)
  {
    m_Buffer[m_Pos++] = aByte;
    if(m_Pos >= m_BufferSize)
      WriteBlock();
  }
  void WriteBytes(const void *aBytes, INT aSize)
  {
    for (INT i = 0; i < aSize; i++)
      WriteByte(((const BYTE *)aBytes)[i]);
  }

  UINT64 GetProcessedSize() const { return m_ProcessedSize + m_Pos; }
};

}

#endif