/
XSwitchFlags.cpp
55 lines (46 loc) · 1.33 KB
/
XSwitchFlags.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
#include "defines.h"
// Constructor
XSwitchFlags::XSwitchFlags(const TString &switches) {
ZeroMemory(flags, sizeof(bool) * 28);
ZeroMemory(flags_cap, sizeof(bool) * 26);
// no - sign, & no + sign, invalid syntax
if (switches[0] == TEXT('-'))
flags[26] = true;
else if (switches[0] == TEXT('+'))
flags[27] = true;
else
return;
const unsigned int len = (UINT)switches.len();
TCHAR c;
// Parse the switches
for (UINT i = 1; i < len; i++)
{
c = switches[i];
// Check if its in the right range
if (c >= TEXT('a') && c <= TEXT('z'))
flags[(int) (c - TEXT('a'))] = true;
else if (c >= TEXT('A') && (c <= TEXT('Z')))
flags_cap[(int) (c - TEXT('A'))] = true;
}
}
// Destructor
XSwitchFlags::~XSwitchFlags(void) {
}
// Checks if flags are set.
bool XSwitchFlags::isSet(const char c) const {
// Lower-case
if ((c >= TEXT('a')) && (c <= TEXT('z')))
return flags[(int) (c - TEXT('a'))];
// Upper-case
else if ((c >= TEXT('A')) && (c <= TEXT('Z')))
return flags_cap[(int) (c - TEXT('A'))];
else if (c == TEXT('-')) // check if - flag identifier used.
return flags[26];
else if (c == TEXT('+')) // check if + flag identifier used.
return flags[27];
return false;
}
// Wrapper for isSet()
bool XSwitchFlags::operator[](const char c) const {
return this->isSet(c);
}