Elements  5.12.0
A C++ base framework for the Euclid Software.
SimpleProgram.cpp
Go to the documentation of this file.
1 
23 
24 #include <iostream> // for cerr
25 
26 #include "ElementsKernel/Exit.h" // for ExitCode
27 #include "ElementsKernel/Unused.h" // for ELEMENTS_UNUSED
28 #include "ElementsKernel/Path.h" // for Path::Item
29 
30 namespace Elements {
31 
33 
34 ExitCode SimpleProgram::run(int argc, char** argv) noexcept {
35 
36  ExitCode exit_code {ExitCode::OK};
37 
38  setup(argc, argv);
39 
40  using std::cerr;
41  using std::endl;
42 
43  try {
44  exit_code = main();
45  } catch (const std::exception & e) {
46  cerr << "Exception has been thrown : " << e.what() << endl;
47  exit_code = ExitCode::NOT_OK;
48  } catch (...) {
49  cerr << "An unknown exception has been thrown"<< endl;
50  exit_code = ExitCode::NOT_OK;
51  }
52 
53  return exit_code;
54 }
55 
56 
57 void SimpleProgram::setup(ELEMENTS_UNUSED int argc, char** argv) {
58 
59  Path::Item prog_path {argv[0]};
60 
61  m_program_name = prog_path.filename();
62  m_program_path = prog_path.parent_path();
63 
64  defineOptions();
65 
66 }
67 
69  return m_program_path;
70 }
71 
73  return m_program_name;
74 }
75 
76 } // namespace Elements
define a list of standard exit codes for executables
provide functions to retrieve resources pointed by environment variables
Macro to silence unused variables warnings from the compiler.
void setup(int argc, char **argv)
ELEMENTS_API const Path::Item & getProgramPath() const
ELEMENTS_API ExitCode run(int argc, char **argv) noexcept
virtual void defineOptions()=0
ELEMENTS_API const Path::Item & getProgramName() const
T endl(T... args)
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:98
#define ELEMENTS_UNUSED
Definition: Unused.h:39
boost::filesystem::path Item
Definition: Path.h:61
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:50
@ NOT_OK
Generic unknown failure.
@ OK
Everything is OK.