242
|
1 #include "StartupParametersBuilder.h"
|
|
2
|
|
3 namespace OrthancStone
|
|
4 {
|
|
5 void StartupParametersBuilder::Clear() {
|
|
6 startupParameters_.clear();
|
|
7 }
|
|
8
|
|
9 void StartupParametersBuilder::SetStartupParameter(const char* name, const char* value) {
|
|
10 startupParameters_.push_back(std::make_tuple(name, value));
|
|
11 }
|
|
12
|
|
13 void StartupParametersBuilder::GetStartupParameters(boost::program_options::variables_map& parameters, const boost::program_options::options_description& options) {
|
|
14
|
|
15 const char* argv[startupParameters_.size() + 1];
|
|
16 int argCounter = 0;
|
|
17 argv[0] = "Toto.exe";
|
|
18 argCounter++;
|
|
19
|
|
20 std::string cmdLine = "";
|
|
21 for (StartupParameters::const_iterator it = startupParameters_.begin(); it != startupParameters_.end(); it++) {
|
|
22 char* arg = new char[128];
|
|
23 snprintf(arg, 128, "--%s=%s", std::get<0>(*it).c_str(), std::get<1>(*it).c_str());
|
|
24 argv[argCounter] = arg;
|
|
25 cmdLine = cmdLine + " --" + std::get<0>(*it) + "=" + std::get<1>(*it);
|
|
26 argCounter++;
|
|
27 }
|
|
28
|
|
29 printf("simulated cmdLine = %s\n", cmdLine.c_str());
|
|
30
|
|
31 try
|
|
32 {
|
|
33 boost::program_options::store(boost::program_options::command_line_parser(argCounter, argv).
|
|
34 options(options).run(), parameters);
|
|
35 boost::program_options::notify(parameters);
|
|
36 }
|
|
37 catch (boost::program_options::error& e)
|
|
38 {
|
|
39 printf("Error while parsing the command-line arguments: %s\n", e.what());
|
|
40 }
|
|
41
|
|
42 }
|
|
43 } |