Elements  6.2
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/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
Elements::Kernel::Path::Item
boost::filesystem::path Item
Definition: Path.h:56
Elements::ExitCode::OK
@ OK
Everything is OK.
std::exception
STL class.
Path.h
provide functions to retrieve resources pointed by environment variables
SimpleProgram.h
main
int main(int argc, char *argv[])
Definition: cutout.c:31
Elements::SimpleProgram::m_program_path
Path::Item m_program_path
Definition: SimpleProgram.h:59
Exit.h
define a list of standard exit codes for executables
Elements::SimpleProgram::getProgramPath
const ELEMENTS_API Path::Item & getProgramPath() const
Definition: SimpleProgram.cpp:66
Elements::ExitCode
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
Elements::SimpleProgram::~SimpleProgram
virtual ~SimpleProgram()
Definition: SimpleProgram.cpp:32
Elements::ExitCode::NOT_OK
@ NOT_OK
Generic unknown failure.
Elements::SimpleProgram::getProgramName
const ELEMENTS_API Path::Item & getProgramName() const
Definition: SimpleProgram.cpp:70
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:56
Elements::SimpleProgram::m_program_name
Path::Item m_program_name
Definition: SimpleProgram.h:58
std::endl
T endl(T... args)
Unused.h
Macro to silence unused variables warnings from the compiler.
Elements::Kernel::Units::e
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:51
ELEMENTS_UNUSED
#define ELEMENTS_UNUSED
Definition: Unused.h:39
Elements
Definition: callBackExample.h:35