Elements  5.12
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
std::exception
STL class.
Path.h
provide functions to retrieve resources pointed by environment variables
Elements::Path::Item
boost::filesystem::path Item
Definition: Path.h:61
SimpleProgram.h
Elements::SimpleProgram::m_program_path
Path::Item m_program_path
Definition: SimpleProgram.h:64
Exit.h
define a list of standard exit codes for executables
Elements::SimpleProgram::getProgramPath
ELEMENTS_API const Path::Item & getProgramPath() const
Definition: SimpleProgram.cpp:68
Elements::ExitCode
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:98
Elements::SimpleProgram::~SimpleProgram
virtual ~SimpleProgram()
Definition: SimpleProgram.cpp:32
Elements::SimpleProgram::getProgramName
ELEMENTS_API const Path::Item & getProgramName() const
Definition: SimpleProgram.cpp:72
std::cerr
Elements::SimpleProgram::defineOptions
virtual void defineOptions()=0
Elements::SimpleProgram::run
ELEMENTS_API ExitCode run(int argc, char **argv) noexcept
Definition: SimpleProgram.cpp:34
Elements::SimpleProgram::setup
void setup(int argc, char **argv)
Definition: SimpleProgram.cpp:57
Elements::Units::e
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:50
Elements::SimpleProgram::m_program_name
Path::Item m_program_name
Definition: SimpleProgram.h:63
std::endl
T endl(T... args)
Unused.h
Macro to silence unused variables warnings from the compiler.
ELEMENTS_UNUSED
#define ELEMENTS_UNUSED
Definition: Unused.h:39
Elements
Definition: Auxiliary.h:43