Elements  6.2
A C++ base framework for the Euclid Software.
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 
31 #include "ElementsKernel/Unused.h"
32 
33 using std::map;
34 using std::string;
35 using std::vector;
36 
37 using boost::program_options::value;
38 
39 namespace Elements {
40 namespace Examples {
41 
50 class ProgramWithArguments : public Program {
51 
52 public:
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 
Elements::Examples::ProgramWithArguments
Example of an Elements program.
Definition: ProgramWithArguments.cpp:50
Elements::ExitCode::OK
@ OK
Everything is OK.
std::string
STL class.
std::pair
std::vector
STL class.
Elements::Program::OptionsDescription
options_description OptionsDescription
Definition: Program.h:62
Elements::ExitCode
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
Elements::Program::PositionalOptionsDescription
positional_options_description PositionalOptionsDescription
Definition: Program.h:63
Elements::Examples::Program
Simple example of an Elements program.
Definition: Program.cpp:79
std::cout
Elements::Examples::ProgramWithArguments::defineProgramArguments
std::pair< OptionsDescription, PositionalOptionsDescription > defineProgramArguments() override
This methods must be used to the program arguments.
Definition: ProgramWithArguments.cpp:85
std::map
STL class.
ProgramHeaders.h
Elements::Examples::log
auto log
Definition: BackTrace.cpp:36
Elements::Logging::getLogger
static Logging getLogger(const std::string &name="")
Definition: Logging.cpp:63
std::endl
T endl(T... args)
MAIN_FOR
#define MAIN_FOR(ELEMENTS_PROGRAM_NAME)
Definition: Main.h:113
std::make_pair
T make_pair(T... args)
Unused.h
Macro to silence unused variables warnings from the compiler.
ELEMENTS_UNUSED
#define ELEMENTS_UNUSED
Definition: Unused.h:39
Elements::Examples::ProgramWithArguments::mainMethod
ExitCode mainMethod(ELEMENTS_UNUSED map< string, VariableValue > &args) override
The "main" method.
Definition: ProgramWithArguments.cpp:64
Elements
Definition: callBackExample.h:35