-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmask.cpp
61 lines (53 loc) · 1.03 KB
/
mask.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
#include "mask.h"
#include <QDebug>
Mask::Mask()
{
clear();
}
bool Mask::at(int i, int j) const
{
if(i < 32 && j < 32 && i >= 0 && j >= 0)
{
int numByte = (i / 8) + (j * 4);
int numBit = i % 8;
return (_mask[numByte] & (1 << (7 - numBit)));
}
return false;
}
void Mask::change(int i, int j, bool value)
{
if(i < 32 && j < 32 && i >= 0 && j >= 0)
{
int numByte = (i / 8) + (j * 4);
int numBit = i % 8;
if(value)
{
_mask[numByte] |= (1 << (7 - numBit));
}
else
{
_mask[numByte] &= ~(1 << (7 - numBit));
}
}
}
void Mask::clear()
{
for(int i = 0; i < 128; i++)
{
_mask[i] = 0;
}
}
QString Mask::data()
{
QString str = "{\n";
for(int i = 0, numWordInLine = 1; i < 128; i++, numWordInLine++)
{
str += " 0x" + QString::number(_mask[i], 16) + ",";
if( !(numWordInLine % 8))
{
str += "\n";
}
}
str += "}";
return str;
}