Elements  5.8
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 <boost/filesystem/path.hpp> // for path
27 
28 #include "ElementsKernel/Exit.h" // for ExitCode
29 #include "ElementsKernel/Unused.h" // for ELEMENTS_UNUSED
30 
32 
33 namespace Elements {
34 
36 
37 ExitCode SimpleProgram::run(int argc, char** argv) noexcept {
38 
39  ExitCode exit_code {ExitCode::OK};
40 
41  setup(argc, argv);
42 
43  using std::cerr;
44  using std::endl;
45 
46  try {
47  exit_code = main();
48  } catch (const std::exception & e) {
49  cerr << "Exception has been thrown : " << e.what() << endl;
50  exit_code = ExitCode::NOT_OK;
51  } catch (...) {
52  cerr << "An unknown exception has been thrown"<< endl;
53  exit_code = ExitCode::NOT_OK;
54  }
55 
56  return exit_code;
57 }
58 
59 
60 void SimpleProgram::setup(ELEMENTS_UNUSED int argc, char** argv) {
61 
62  path prog_path {argv[0]};
63 
64  m_program_name = prog_path.filename();
65  m_program_path = prog_path.parent_path();
66 
67  defineOptions();
68 
69 }
70 
72  return m_program_path;
73 }
74 
76  return m_program_name;
77 }
78 
79 } // namespace Elements
Elements::SimpleProgram::getProgramName
const ELEMENTS_API boost::filesystem::path & getProgramName() const
Definition: SimpleProgram.cpp:75
std::exception
STL class.
Elements::ExitCode
ExitCode
Strongly typed exit numbers.
Definition: Exit.h:97
SimpleProgram.h
Exit.h
define a list of standard exit codes for executables
Elements::ExitCode::NOT_OK
@ NOT_OK
Generic unknown failure.
ElementsServices::DataSync::path
boost::filesystem::path path
Definition: DataSyncUtils.h:33
Elements::SimpleProgram::~SimpleProgram
virtual ~SimpleProgram()
Definition: SimpleProgram.cpp:35
std::cerr
Elements::SimpleProgram::defineOptions
virtual void defineOptions()=0
Elements::SimpleProgram::run
ELEMENTS_API ExitCode run(int argc, char **argv) noexcept
Definition: SimpleProgram.cpp:37
Elements::SimpleProgram::setup
void setup(int argc, char **argv)
Definition: SimpleProgram.cpp:60
Elements::SimpleProgram::m_program_path
boost::filesystem::path m_program_path
Definition: SimpleProgram.h:65
Elements::Units::e
constexpr double e
The base of the natural logarithm .
Definition: MathConstants.h:50
std::endl
T endl(T... args)
Elements::ExitCode::OK
@ OK
Everything is OK.
Elements::SimpleProgram::getProgramPath
const ELEMENTS_API boost::filesystem::path & getProgramPath() const
Definition: SimpleProgram.cpp:71
Unused.h
Macro to silence unused variables warnings from the compiler.
ELEMENTS_UNUSED
#define ELEMENTS_UNUSED
Definition: Unused.h:39
Elements::SimpleProgram::m_program_name
boost::filesystem::path m_program_name
Definition: SimpleProgram.h:64
Elements
Definition: Auxiliary.h:43