Elements 6.3.3
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
SimpleProgram.cpp
Go to the documentation of this file.
1
21
23
24#include <exception> // for exception
25#include <iostream> // for cerr
26
27#include "ElementsKernel/Exit.h" // for ExitCode
28#include "ElementsKernel/Path.h" // for Path::Item
29#include "ElementsKernel/Unused.h" // for ELEMENTS_UNUSED
30
31namespace Elements {
32
34
35ExitCode SimpleProgram::run(int argc, char* argv[]) noexcept {
36
37 ExitCode exit_code;
38
39 setup(argc, argv);
40
41 using std::cerr;
42 using std::endl;
43
44 try {
45 exit_code = main();
46 } catch (const std::exception& e) {
47 cerr << "Exception has been thrown : " << e.what() << endl;
48 exit_code = ExitCode::NOT_OK;
49 } catch (...) {
50 cerr << "An unknown exception has been thrown" << endl;
51 exit_code = ExitCode::NOT_OK;
52 }
53
54 return exit_code;
55}
56
57void 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
65}
66
67const Path::Item& SimpleProgram::getProgramPath() const {
68 return m_program_path;
69}
70
71const Path::Item& SimpleProgram::getProgramName() const {
72 return m_program_name;
73}
74
75} // namespace Elements
T endl(T... args)
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)
virtual ExitCode main()=0
const Path::Item & getProgramPath() const
ExitCode run(int argc, char **argv) noexcept
virtual void defineOptions()=0
const Path::Item & getProgramName() const
Elements::ExitCode ExitCode
T endl(T... args)
#define ELEMENTS_UNUSED
Definition Unused.h:39
@ NOT_OK
Generic unknown failure.
Definition Exit.h:101