-
Notifications
You must be signed in to change notification settings - Fork 5
/
LBPBuffer.h
104 lines (74 loc) · 2.31 KB
/
LBPBuffer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#ifndef LBPEXPORT
#define LBPEXPORT
#endif
#if defined (LBPLIB_APPLE_SPECIFIC)
#define REFCOUNT_INT int32_t
#endif
#if defined (LBPLIB_WINDOWS_SPECIFIC)
#define REFCOUNT_INT LONG
#endif
class CLBPBuffer;
#include "LBPString.h"
class LBPEXPORT CLBPInternalBuffer
{
public:
CLBPInternalBuffer(const void* pBuffer, size_t size);
CLBPInternalBuffer(const CLBPString& s);
CLBPInternalBuffer(size_t size); //Creates an allocated buffer containing random data
CLBPInternalBuffer();
~CLBPInternalBuffer();
int AddRef() { return ::InterlockedIncrement(&m_iRefCount); }
int Release();
void Set(const void* pBuffer, size_t size);
void Set(size_t size);
void Clear() { Set(0); }
int Compare(const CLBPInternalBuffer& b) const;
const CLBPInternalBuffer& operator = (const CLBPInternalBuffer& b);
const CLBPInternalBuffer& operator = (const CLBPString& sBase64);
public:
const CLBPString& Base64() const;
void Base64(CLBPString& s) const;
DWORD CRC(void) const;
private:
BYTE* m_pBytes;
size_t m_NumBytes;
volatile REFCOUNT_INT m_iRefCount;
mutable CLBPString m_sBase64;
mutable bool m_bBase64Dirty = true;
mutable DWORD m_dwCRC = 0;
mutable bool m_bCRCDirty = true;
friend class CLBPBuffer;
};
class LBPEXPORT CLBPBuffer
{
public:
CLBPBuffer();
CLBPBuffer(const void* pBuffer, size_t size);
CLBPBuffer(const CLBPBuffer& src);
CLBPBuffer(const CLBPString& buffer);
CLBPBuffer(size_t size); //Creates an allocated buffer containing random data
~CLBPBuffer();
void Clear() { Set(0); }
static const WCHAR* Base64Prefix();
public:
const CLBPBuffer& operator = (const CLBPBuffer& b);
const CLBPBuffer& operator = (const CLBPString& sBase64);
public:
const CLBPString& Base64() const;
void Base64(CLBPString& s) const;
DWORD CRC(void) const { return m_pBuffer->CRC(); }
public:
void Set(const void* pBuffer, size_t size);
void Set(size_t size);
BYTE* GetBuffer(size_t size);
void ReleaseBuffer();
int Compare(const CLBPBuffer& b) const;
bool operator == (const CLBPBuffer& b) const;
bool operator > (const CLBPBuffer& b) const;
bool operator < (const CLBPBuffer& b) const;
const BYTE* Bytes(void) const { return NULL == m_pBuffer ? NULL : m_pBuffer->m_pBytes; }
size_t NumBytes(void) const { return NULL == m_pBuffer ? 0 : m_pBuffer->m_NumBytes; }
private:
CLBPInternalBuffer* m_pBuffer;
};