-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtclap_loader.hpp
48 lines (40 loc) · 1.13 KB
/
tclap_loader.hpp
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
/*
When using TCLAP
static TCLAP::CmdLine cmd("", ' ', "1.0");
static TCLAP::ValueArg<std::string> server_ip("", "server_ip", "", false, IP_ANY, "server port");
static TCLAP::ValueArg<std::string> server_port("", "server_port", "", false, std::to_string(SERVER_PORT), "server port");
int main() {
// this loads params into Commands system, and they can be saved later
cmd.add( server_ip );
cmd.add( server_port );
try {
cmd.parse( argc, argv );
} catch (TCLAP::ArgException &e) {
return -1;
}
Commands::TCLAP_LoadVariables(cmd);
std::cout << "server_ip is: " << Command::Get("server_ip").to_string() << "\n";
}
*/
#ifndef TCLAP_LOADER
#define TCLAP_LOADER
#include <tclap/CmdLine.h>
#include "Commands.hpp"
#include <list>
#include <iostream>
namespace Commands {
void TCLAP_LoadVariables(TCLAP::CmdLine& cmd) {
std::list<TCLAP::Arg*> args = cmd.getArgList();
for(auto& a : args) {
if(a->is_string) {
TCLAP::ValueArg<std::string>* v = (TCLAP::ValueArg<std::string>*)a;
if(v) {
std::string name(a->getName());
std::string value(v->getValue());
Command::Set(name, value);
}
}
}
}
}
#endif