-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathact_cmd.h
More file actions
58 lines (52 loc) · 774 Bytes
/
act_cmd.h
File metadata and controls
58 lines (52 loc) · 774 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
#pragma once
#include <string>
#include <map>
#include <cctype>
namespace Act
{
class CommandLine
{
public:
CommandLine(int argc, char *argv[]) :
argc(argc), argv(argv)
{
}
bool Process()
{
for (int i = 0; i < argc; ++i)
{
char* str = argv[i];
if (str[0] == '-')
{
if (!isalpha(str[1]) || str[2] != 0)
{
return false;
}
++i;
if (i == argc)
{
return false;
}
data[str[1]] = std::string(argv[i]);
}
}
return true;
}
bool HasOption(char c)
{
return data.find(c) != data.end();
}
std::string GetOption(char c)
{
if (!HasOption(c))
{
return "";
}
return data[c];
}
private:
int argc;
char** argv;
std::map<char, std::string> data;
};
}