-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArgumentParser.cu
57 lines (50 loc) · 1.71 KB
/
ArgumentParser.cu
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
#include "ArgumentParser.cuh"
ArgumentParser::ArgumentParser(int argc, char **argv, bool canHaveSource) {
this->argc = argc;
this->argv = argv;
this->canHaveSource = canHaveSource;
this->sourceNode = 0;
hasInput = false;
hasSourceNode = false;
Parse();
}
bool ArgumentParser::Parse() {
try {
for (int i = 1; i < argc - 1; i = i + 2) {
//argv[i]
if (strcmp(argv[i], "--input") == 0) {
input = string(argv[i + 1]);
hasInput = true;
} else if (strcmp(argv[i], "--type") == 0) {
algo = string(argv[i + 1]);
} else if (strcmp(argv[i], "--source") == 0 && canHaveSource) {
sourceNode = atoi(argv[i + 1]);
hasSourceNode = true;
} else if (strcmp(argv[i], "--method") == 0) {
method = atoi(argv[i + 1]);
} else if (strcmp(argv[i], "--adviseK") == 0) {
adviseK = atof(argv[i + 1]);
}
}
if (hasInput)
return true;
}
catch (const std::exception &strException) {
std::cerr << strException.what() << "\n";
GenerateHelpString();
exit(0);
}
catch (...) {
std::cerr << "An exception has occurred.\n";
GenerateHelpString();
exit(0);
}
}
string ArgumentParser::GenerateHelpString() {
string str = "\nRequired arguments:";
str += "\n [--input]: Input graph file. E.g., --input FacebookGraph.txt";
str += "\nOptional arguments";
if (canHaveSource)
str += "\n [--source]: Begins from the source (Default: 0). E.g., --source 10";
return str;
}