-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.cpp
More file actions
73 lines (59 loc) · 924 Bytes
/
pattern.cpp
File metadata and controls
73 lines (59 loc) · 924 Bytes
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
#include "pattern.h"
void Pattern::BuildString(std::string* str) const
{
char buf[33];
unsigned int i;
for(i=0; i<32; i++)
{
if (mMask & (1<<i))
{
if (mSignature & (1<<i))
buf[31-i] = '1';
else
buf[31-i] = '0';
}
else
{
buf[31-i] = '-';
}
}
buf[32] = 0;
str->assign(buf);
}
void Pattern::Print() const
{
unsigned int i, t;
for(i=0; i<32; i++)
{
t = 1<<(31-i);
if (mMask&t)
printf("%s", mSignature&t? "1" : "0");
else
printf("-");
}
printf("\n");
}
void Pattern::Parse(const char* str)
{
unsigned int i;
mSignature = 0;
mMask = 0;
for(i=0; str[i] != 0; i++)
{
if (str[i] == '0')
{
mSignature = (mSignature<<1) | 0;
mMask = (mMask<<1) | 1;
}
else if (str[i] == '1')
{
mSignature = (mSignature<<1) | 1;
mMask = (mMask<<1) | 1;
}
else if (str[i] == '-')
{
mSignature = (mSignature<<1) | 0;
mMask = (mMask<<1) | 0;
}
}
}