annotate Applications/Wasm/StartupParametersBuilder.cpp @ 254:abc1c6231947 am-2

cleanup
author am@osimis.io
date Tue, 03 Jul 2018 11:49:02 +0200
parents 092db46c6291
children 70992b38aa8a 9e3bb8b4f726
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
1 #include "StartupParametersBuilder.h"
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
2
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
3 namespace OrthancStone
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
4 {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
5 void StartupParametersBuilder::Clear() {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
6 startupParameters_.clear();
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
7 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
8
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
9 void StartupParametersBuilder::SetStartupParameter(const char* name, const char* value) {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
10 startupParameters_.push_back(std::make_tuple(name, value));
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
11 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
12
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
13 void StartupParametersBuilder::GetStartupParameters(boost::program_options::variables_map& parameters, const boost::program_options::options_description& options) {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
14
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
15 const char* argv[startupParameters_.size() + 1];
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
16 int argCounter = 0;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
17 argv[0] = "Toto.exe";
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
18 argCounter++;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
19
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
20 std::string cmdLine = "";
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
21 for (StartupParameters::const_iterator it = startupParameters_.begin(); it != startupParameters_.end(); it++) {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
22 char* arg = new char[128];
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
23 snprintf(arg, 128, "--%s=%s", std::get<0>(*it).c_str(), std::get<1>(*it).c_str());
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
24 argv[argCounter] = arg;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
25 cmdLine = cmdLine + " --" + std::get<0>(*it) + "=" + std::get<1>(*it);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
26 argCounter++;
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
27 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
28
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
29 printf("simulated cmdLine = %s\n", cmdLine.c_str());
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
30
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
31 try
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
32 {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
33 boost::program_options::store(boost::program_options::command_line_parser(argCounter, argv).
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
34 options(options).run(), parameters);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
35 boost::program_options::notify(parameters);
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
36 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
37 catch (boost::program_options::error& e)
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
38 {
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
39 printf("Error while parsing the command-line arguments: %s\n", e.what());
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
40 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
41
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
42 }
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
43 }