-
Notifications
You must be signed in to change notification settings - Fork 2
/
ParseBuffer.h
64 lines (58 loc) · 1.12 KB
/
ParseBuffer.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ParseBuffer.h
//
// Dynamically-growable buffer for parsing
//
// Copyright (c) GDCL 2002-2009
#pragma once
// used by parsers to manage accumulation memory
class ParseBuffer
{
public:
ParseBuffer();
~ParseBuffer();
ParseBuffer(const ParseBuffer& r)
: m_pData(NULL)
{
Assign(r);
}
const ParseBuffer& operator=(const ParseBuffer& r)
{
Done();
Assign(r);
return *this;
}
void Assign(const ParseBuffer& r)
{
m_cSpace = r.m_cSpace;
m_cValid = r.m_cValid;
m_pData = NULL;
if (m_cSpace)
{
m_pData = new BYTE[m_cSpace];
}
if (m_cValid)
{
CopyMemory(m_pData, r.m_pData, m_cValid);
}
}
bool Append(const BYTE* pData, long cBytes);
bool FillFromFile(HANDLE hFile);
void Consume(long cBytes);
long Size()
{
return m_cValid;
}
const BYTE* Data()
{
if (m_cValid)
{
return m_pData;
}
return NULL;
}
void Done();
private:
long m_cSpace;
long m_cValid;
BYTE* m_pData;
};