Mercurial > hg > orthanc-stone
annotate Applications/Wasm/StartupParametersBuilder.cpp @ 860:238693c3bc51 am-dev
merge default -> am-dev
author | Alain Mazy <alain@mazy.be> |
---|---|
date | Mon, 24 Jun 2019 14:35:00 +0200 |
parents | 86930bc676c6 |
children |
rev | line source |
---|---|
242 | 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> |
672 | 3 #include <cstdio> |
4 #include "emscripten/html5.h" | |
242 | 5 |
6 namespace OrthancStone | |
7 { | |
672 | 8 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
|
9 { |
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
|
10 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
|
11 } |
242 | 12 |
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
|
13 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
|
14 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
|
15 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
|
16 { |
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
|
17 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
|
18 } |
242 | 19 |
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
|
20 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
|
21 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
|
22 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
|
23 { |
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 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
|
25 // 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
|
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 // 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
|
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 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
|
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 int argCounter = 0; |
672 | 32 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
|
33 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
|
34 |
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 argCounter++; |
672 | 36 |
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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 { |
672 | 42 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
|
43 |
672 | 44 argSs << "--" << std::get<0>(*it); |
45 if(std::get<1>(*it).length() > 0) | |
46 argSs << "=" << std::get<1>(*it); | |
47 | |
48 argvStrings[argCounter] = argSs.str(); | |
49 cmdLine = cmdLine + " " + argvStrings[argCounter]; | |
50 std::cout << cmdLine << std::endl; | |
51 argv[argCounter] = argvStrings[argCounter].c_str(); | |
52 argCounter++; | |
664 | 53 } |
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 |
242 | 55 |
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
|
56 std::cout << "simulated cmdLine = \"" << cmdLine.c_str() << "\"\n"; |
242 | 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 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
|
59 { |
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::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
|
61 boost::program_options::command_line_parser(argCounter, argv.data()). |
658 | 62 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
|
63 boost::program_options::notify(parameters); |
242 | 64 } |
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
|
65 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
|
66 { |
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 std::cerr << "Error while parsing the command-line arguments: " << |
664 | 68 e.what() << std::endl; |
69 } | |
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
|
70 } |
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
|
71 } |