annotate Applications/Wasm/StartupParametersBuilder.cpp @ 670:5dd496343fad

Restored missing code + fixed key ordering when generating code
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 15 May 2019 18:29:42 +0200
parents 9631a10ed3af
children 86930bc676c6
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"
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
2 #include <iostream>
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
3
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
4 namespace OrthancStone
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
5 {
658
63982c8c294a merge am-dev -> default
Alain Mazy <alain@mazy.be>
parents: 603 657
diff changeset
6 void StartupParametersBuilder::Clear()
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
7 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
8 startupParameters_.clear();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
9 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
10
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
11 void StartupParametersBuilder::SetStartupParameter(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
12 const char* name,
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
13 const char* value)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
14 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
15 startupParameters_.push_back(std::make_tuple(name, value));
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
16 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
17
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
18 void StartupParametersBuilder::GetStartupParameters(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
19 boost::program_options::variables_map& parameters,
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
20 const boost::program_options::options_description& options)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
21 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
22 std::vector<std::string> argvStrings(startupParameters_.size() + 1);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
23 // argv mirrors pointers to the internal argvStrings buffers.
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
24 // ******************************************************
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
25 // THIS IS HIGHLY DANGEROUS SO BEWARE!!!!!!!!!!!!!!
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
26 // ******************************************************
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
27 std::vector<const char*> argv(startupParameters_.size() + 1);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
28
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
29 int argCounter = 0;
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
30 argvStrings[argCounter] = "Toto.exe";
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
31 argv[argCounter] = argvStrings[argCounter].c_str();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
32
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
33 argCounter++;
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
34
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
35 std::string cmdLine = "";
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
36 for ( StartupParameters::const_iterator it = startupParameters_.begin();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
37 it != startupParameters_.end();
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
38 it++)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
39 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
40 std::stringstream argSs;
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
41
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
42 argSs << "--" << std::get<0>(*it);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
43 if(std::get<1>(*it).length() > 0)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
44 argSs << "=" << std::get<1>(*it);
670
5dd496343fad Restored missing code + fixed key ordering when generating code
Benjamin Golinvaux <bgo@osimis.io>
parents: 664
diff changeset
45
5dd496343fad Restored missing code + fixed key ordering when generating code
Benjamin Golinvaux <bgo@osimis.io>
parents: 664
diff changeset
46 argvStrings[argCounter] = argSs.str();
5dd496343fad Restored missing code + fixed key ordering when generating code
Benjamin Golinvaux <bgo@osimis.io>
parents: 664
diff changeset
47 cmdLine = cmdLine + " " + argvStrings[argCounter];
5dd496343fad Restored missing code + fixed key ordering when generating code
Benjamin Golinvaux <bgo@osimis.io>
parents: 664
diff changeset
48 argv[argCounter] = argvStrings[argCounter].c_str();
5dd496343fad Restored missing code + fixed key ordering when generating code
Benjamin Golinvaux <bgo@osimis.io>
parents: 664
diff changeset
49 argCounter++;
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
50 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
51
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
52
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
53 std::cout << "simulated cmdLine = \"" << cmdLine.c_str() << "\"\n";
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
54
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
55 try
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
56 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
57 boost::program_options::store(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
58 boost::program_options::command_line_parser(argCounter, argv.data()).
658
63982c8c294a merge am-dev -> default
Alain Mazy <alain@mazy.be>
parents: 603 657
diff changeset
59 options(options).allow_unregistered().run(), parameters);
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
60 boost::program_options::notify(parameters);
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
61 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
62 catch (boost::program_options::error& e)
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
63 {
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
64 std::cerr << "Error while parsing the command-line arguments: " <<
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
65 e.what() << std::endl;
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
66 }
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
67 }
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 242
diff changeset
68 }