-
Notifications
You must be signed in to change notification settings - Fork 3
/
lbitfield_dynamic.cpp
93 lines (68 loc) · 1.57 KB
/
lbitfield_dynamic.cpp
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
#include "lbitfield_dynamic.h"
#include <string.h>
namespace LM { // namespace start
void LBitField_Dynamic::Initialize() {assert (0 && "LBitField_Dynamic : Does not support Initialize, use IT version");}
void LBitField_Dynamic::Terminate() {assert (0 && "LBitField_Dynamic : Does not support Terminate, use IT version");}
void LBitField_Dynamic_IT::Initialize()
{
Initialize_Do();
}
void LBitField_Dynamic_IT::Terminate()
{
Terminate_Do();
}
void LBitField_Dynamic_IT::Initialize_Do()
{
memset (this, 0, sizeof (LBitField_Dynamic));
}
void LBitField_Dynamic_IT::Terminate_Do()
{
Destroy();
}
void LBitField_Dynamic_IT::CopyFrom(const LBitField_Dynamic_IT &source)
{
Create(source.GetNumBits(), false);
memcpy(m_pucData, source.GetData(), source.GetNumBytes());
}
void LBitField_Dynamic_IT::Create(unsigned int uiNumBits, bool bBlank)
{
// first delete any initial
Destroy();
m_uiNumBits = uiNumBits;
if (uiNumBits)
{
m_uiNumBytes = (uiNumBits / 8) + 1;
m_pucData = new unsigned char[m_uiNumBytes];
if (bBlank)
Blank(false);
}
}
void LBitField_Dynamic_IT::Destroy()
{
if (m_pucData)
{
delete[] m_pucData;
m_pucData = 0;
}
memset (this, 0, sizeof (LBitField_Dynamic));
}
void LBitField_Dynamic_IT::Blank(bool bSetOrZero)
{
if (bSetOrZero)
{
memset(m_pucData, 255, m_uiNumBytes);
}
else
{
memset(m_pucData, 0, m_uiNumBytes);
}
}
void LBitField_Dynamic_IT::Invert()
{
for (unsigned int n=0; n<m_uiNumBytes; n++)
{
m_pucData[n] = ~m_pucData[n];
}
}
////////////////////////////////////////////////////////////////////////////
} // namespace end