Elements 6.1.2
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
ProgramWithArguments.cpp
Go to the documentation of this file.
1
22#include <iostream> // for cout, endl
23#include <map> // for map
24#include <string> // for string
25#include <utility> // for pair, make_pair
26#include <vector> // for vector
27
28#include <boost/program_options.hpp> // for program options from configuration file of command line arguments
29
32
33using std::map;
34using std::string;
35using std::vector;
36
37using boost::program_options::value;
38
39namespace Elements {
40namespace Examples {
41
51
52public:
65
66 // Get logger and log the entry into the mainMethod
67 auto log = Logging::getLogger();
68
69 log.info("This Works");
70
71 using std::cout;
72 using std::endl;
73
74 cout << "This Works too!" << endl;
75
76 if (args.count("input-files") > 0) {
77 vector<string> files = args["input-files"].as<vector<string>>();
78 for (string file : files) {
79 cout << "Input file " << file << endl;
80 }
81 }
82 return ExitCode::OK;
83 }
84
86 OptionsDescription desc{};
87 auto add = desc.add_options();
88
89 add("input-files", value<vector<string>>(), "Input files");
90
92 pos_desc.add("input-files", -1);
93
94 return std::make_pair(desc, pos_desc);
95 }
96};
97
98} // namespace Examples
99} // namespace Elements
100
Macro to silence unused variables warnings from the compiler.
ExitCode mainMethod(ELEMENTS_UNUSED map< string, VariableValue > &args) override
The "main" method.
std::pair< OptionsDescription, PositionalOptionsDescription > defineProgramArguments() override
This methods must be used to the program arguments.
Simple example of an Elements program.
Definition: Program.cpp:79
static Logging getLogger(const std::string &name="")
Definition: Logging.cpp:63
options_description OptionsDescription
Definition: Program.h:62
positional_options_description PositionalOptionsDescription
Definition: Program.h:63
T endl(T... args)
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
#define MAIN_FOR(ELEMENTS_PROGRAM_NAME)
Definition: Main.h:113
#define ELEMENTS_UNUSED
Definition: Unused.h:39
@ OK
Everything is OK.
T make_pair(T... args)