Elements  6.0.1
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 "ElementsKernel/Exit.h" // for ExitCode
27 #include "ElementsKernel/Path.h" // for Path::Item
28 #include "ElementsKernel/Unused.h" // for ELEMENTS_UNUSED
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 void SimpleProgram::setup(ELEMENTS_UNUSED int argc, char* argv[]) {
57 
58  Path::Item prog_path{argv[0]};
59 
60  m_program_name = prog_path.filename();
61  m_program_path = prog_path.parent_path();
62 
63  defineOptions();
64 }
65 
67  return m_program_path;
68 }
69 
71  return m_program_name;
72 }
73 
74 } // namespace Elements
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
Generic unknown failure.
Macro to silence unused variables warnings from the compiler.
ELEMENTS_API ExitCode run(int argc, char **argv) noexcept
Everything is OK.
ELEMENTS_API const Path::Item & getProgramPath() const
T endl(T...args)
void setup(int argc, char **argv)
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:51
T what(T...args)
boost::filesystem::path Item
Definition: Path.h:56
int main(int argc, char *argv[])
Definition: cutout.c:31
STL class.
ELEMENTS_API const Path::Item & getProgramName() const
define a list of standard exit codes for executables
provide functions to retrieve resources pointed by environment variables
virtual void defineOptions()=0
#define ELEMENTS_UNUSED
Definition: Unused.h:39