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