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