This repository was archived by the owner on Sep 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParamManager.h
More file actions
144 lines (127 loc) · 3.52 KB
/
ParamManager.h
File metadata and controls
144 lines (127 loc) · 3.52 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef __PARAMS_MANAGER__
#define __PARAMS_MANAGER__
#include <vector>
#include <iostream>
#include <algorithm>
#include "helpFunctions.h"
using namespace std;
class ParamManager {
public:
class Param {
public:
string small;
string big;
string description;
string valueDescription;
string value = "";
Param() {}
Param(string s, string b, string d, string vd)
: small(s), big(b), description(d), valueDescription(vd)
{}
Param(const Param& org) {
small = org.small;
big = org.big;
description = org.description;
valueDescription = org.valueDescription;
value = org.value;
}
void print() {
cout << right << setw(7) << small << (small.empty()? "": ", ") << left << setw(14) << big
<< setw(20) << valueDescription
<< '\t' << setw(40) << description << '\n';
}
bool operator==(const Param& rhs) {
return rhs.small == small and rhs.big == big and description == rhs.description;
}
bool operator==(const string& rhs) {
return (small == rhs) or (big == rhs);
}
};
private:
vector<Param> params;
public:
ParamManager() {
addParam("-h", "--help", "Shows help", "");
}
void addParam(string small, string big, string description, string valueDescription) {
if(find(params.begin(), params.end(), small) == params.end()
and find(params.begin(), params.end(), big) == params.end()
) {
params.emplace_back(small, big, description, valueDescription);
}
}
void addParamSeparator() {
params.emplace_back("", "", "", "");
}
bool exists(string flag) {
return find_if(params.begin(), params.end(), [&](Param& p) -> bool {
return p == flag;
}) != params.end();
}
bool hasValue(string flag) {
return getValueOf(flag) != "";
}
string getValueOf(string flag) {
auto it = find_if(params.begin(), params.end(), [&](Param& p) -> bool {
return p == flag;
});
if(it != params.end()) {
return (*it).value;
}
return "";
}
void printList() {
for(Param p : params) {
p.print();
}
cout << flush;
}
void printHelp() {
cout << "Usage: vox2obj [OPTION [VALUE]]\n\n"
<< "Converts VOX file(s) into OBJ format file(s)\n\n"
<< "Available options:\n";
printList();
cout << "\nFor more visit: https://github.com/zbigniewcebula/vox2obj\n"
<< endl;
}
bool process(int argc, char** argv) {
string tempStr;
bool paramOverload = false;
auto lastParam = params.end();
for(int i = 1; i < argc; ++i) {
tempStr = argv[i];
if(startsWith(tempStr, "-")) {
lastParam = find_if(params.begin(), params.end(), [&](Param& p) -> bool {
return p == tempStr;
});
if(lastParam == params.end()) {
cerr << "Unknown parameter \"" << tempStr << "\"! Aborting..." << endl;
return false;
} else if((*lastParam) == "-h") {
printHelp();
return false;
} else if((*lastParam) == "-s" || (*lastParam) == "-ms"
|| (*lastParam) == "-fl" || (*lastParam) == "-mc"
|| (*lastParam) == "-t"
) {
(*lastParam).value = "1";
} else if((*lastParam).value != "") {
cerr << "Parameter \"" << tempStr << "\" used multiple times! Aborting..." << endl;
return false;
}
} else {
if(lastParam != params.end()) {
(*lastParam).value = tempStr;
} else {
paramOverload = true;
}
lastParam = params.end();
}
}
if(paramOverload) {
cout << "WARNING! Too much parameters, ignoring not used..." << endl;
}
return true;
}
};
#endif