Elements 6.1.2
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
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
30namespace Elements {
31
33
34ExitCode 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
56void 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
64}
65
66const Path::Item& SimpleProgram::getProgramPath() const {
67 return m_program_path;
68}
69
70const Path::Item& SimpleProgram::getProgramName() const {
71 return m_program_name;
72}
73
74} // 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
int main(int argc, char *argv[])
Definition: cutout.c:31
T endl(T... args)
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
#define ELEMENTS_UNUSED
Definition: Unused.h:39
@ NOT_OK
Generic unknown failure.
@ OK
Everything is OK.