annotate Deprecated/Applications/Wasm/StartupParametersBuilder.cpp @ 1458:828a9b4ee1b7

added missing copyright
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 21:23:02 +0200
parents ff8d2e46ac63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
1 /**
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
2 * Stone of Orthanc
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
4 * Department, University Hospital of Liege, Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
6 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
7 * This program is free software: you can redistribute it and/or
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
10 * the License, or (at your option) any later version.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
11 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
12 * This program is distributed in the hope that it will be useful, but
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
15 * Affero General Public License for more details.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
16 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
19 **/
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
20
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1399
diff changeset
21
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
22 #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
23 #include <iostream>
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
24 #include <cstdio>
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
25 #include "emscripten/html5.h"
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
26
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
27 namespace OrthancStone
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
28 {
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
29 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
30 {
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 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
32 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
33
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
34 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
35 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
36 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
37 {
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 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
39 }
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
40
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
41 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
42 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
43 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
44 {
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
45 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
46 // 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
47 // ******************************************************
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
48 // 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
49 // ******************************************************
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
50 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
51
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
52 int argCounter = 0;
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
53 argvStrings[argCounter] = "dummy.exe";
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
54 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
55
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 argCounter++;
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
57
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
58 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
59 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
60 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
61 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
62 {
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
63 std::stringstream argSs;
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
64
672
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
65 argSs << "--" << std::get<0>(*it);
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
66 if(std::get<1>(*it).length() > 0)
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
67 argSs << "=" << std::get<1>(*it);
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
68
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
69 argvStrings[argCounter] = argSs.str();
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
70 cmdLine = cmdLine + " " + argvStrings[argCounter];
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
71 std::cout << cmdLine << std::endl;
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
72 argv[argCounter] = argvStrings[argCounter].c_str();
Alain Mazy <alain@mazy.be>
parents: 670
diff changeset
73 argCounter++;
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
74 }
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
75
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
76
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
77 std::cout << "simulated cmdLine = \"" << cmdLine.c_str() << "\"\n";
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
78
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
79 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
80 {
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
81 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
82 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
83 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
84 boost::program_options::notify(parameters);
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents:
diff changeset
85 }
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
86 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
87 {
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
88 std::cerr << "Error while parsing the command-line arguments: " <<
664
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
89 e.what() << std::endl;
9631a10ed3af fix previous merge
Alain Mazy <alain@mazy.be>
parents: 658
diff changeset
90 }
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
91 }
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
92 }