Elements  5.12.0
A C++ base framework for the Euclid Software.
Main.h
Go to the documentation of this file.
1 
26 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_MAIN_H_
27 #define ELEMENTSKERNEL_ELEMENTSKERNEL_MAIN_H_
28 
29 #include <exception> // for set_terminate
30 #include <memory> // for unique_ptr
31 #include <log4cpp/Priority.hh>
32 
33 #include "ElementsKernel/Exit.h" // for ExitCode
34 #include "ElementsKernel/ProgramManager.h" // for ProgramManager
35 #include "ElementsKernel/Export.h" // for ELEMENTS_API
36 #include "ElementsKernel/Unused.h" // for ELEMENTS_UNUSED
37 #include "ElementsKernel/Project.h" // for Project
38 #include "ElementsKernel/Module.h" // for Module
39 
40 #ifndef ELEMENTS_DEFAULT_LOGLEVEL
41 # define ELEMENTS_DEFAULT_LOGLEVEL DEBUG
42 #endif
43 
52 #define CREATE_MANAGER_WITH_ARGS(MANAGER, ELEMENTS_PROGRAM, ...) \
53  Elements::ProgramManager MANAGER {std::unique_ptr<Elements::Program>{new ELEMENTS_PROGRAM{__VA_ARGS__}}, \
54  Elements::Project::versionString(), Elements::Project::name(), \
55  Elements::Project::vcsVersion(), \
56  Elements::Module::versionString(), Elements::Module::name(), \
57  Elements::Project::searchDirectories(), \
58  log4cpp::Priority::ELEMENTS_DEFAULT_LOGLEVEL}
59 
68 #define CREATE_MANAGER(ELEMENTS_PROGRAM_NAME, MANAGER) \
69  CREATE_MANAGER_WITH_ARGS(MANAGER, ELEMENTS_PROGRAM_NAME, )
70 
89 #define MAIN_FOR_WITH_ARGS(ELEMENTS_PROGRAM, ...) \
90  ELEMENTS_UNUSED const auto installed = {std::set_terminate(&Elements::ProgramManager::onTerminate)}; \
91  ELEMENTS_API int main(int argc, char* argv[]) \
92  { \
93  CREATE_MANAGER_WITH_ARGS(manager, ELEMENTS_PROGRAM, __VA_ARGS__); \
94  Elements::ExitCode exit_code = manager.run(argc, argv); \
95  return static_cast<Elements::ExitCodeType>(exit_code); \
96  }
97 
116 #define MAIN_FOR(ELEMENTS_PROGRAM_NAME) \
117  MAIN_FOR_WITH_ARGS(ELEMENTS_PROGRAM_NAME, )
118 
119 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_MAIN_H_
120 
define a list of standard exit codes for executables
defines the macros to be used for explicit export of the symbols
Defines tools to describe the current Elmeents module.
Defines tools to describe the current project.
Macro to silence unused variables warnings from the compiler.