Elements 6.3.3
A C++ base framework for the Euclid Software.
|
Class for managing all Elements programs. More...
#include <ProgramManager.h>
Public Member Functions | |
ProgramManager (std::unique_ptr< Program > program_ptr, const std::string &parent_project_version="", const std::string &parent_project_name="", const std::string &parent_project_vcs_version="", const std::string &parent_module_version="", const std::string &parent_module_name="", const std::vector< std::string > &search_dirs={}, const log4cpp::Priority::Value &elements_loglevel=log4cpp::Priority::DEBUG, bool no_config_file=false) | |
Constructor. | |
virtual | ~ProgramManager () |
Destructor. | |
ExitCode | run (int argc, char *argv[]) |
This is the public entry point, i.e., the only method called from the main. | |
std::string | getVersion () const |
This function returns the version of the program computed at compile time. This is the same as the project version that contains the program. |
Static Public Member Functions | |
static void | onTerminate () noexcept |
This is the set_terminate handler that is used in the MAIN_FOR macro. |
Private Member Functions | |
const Path::Item & | getProgramPath () const |
Getter. | |
const Path::Item & | getProgramName () const |
Getter. | |
void | setup (int argc, char *argv[]) |
Program setup taking care of command line options and logging initialization. | |
void | tearDown (const ExitCode &) |
const Program::VariablesMap | getProgramOptions (int argc, char *argv[]) |
Get the program options from the command line into thevariables_map. | |
void | logHeader (std::string program_name) const |
Log Header. | |
void | logFooter (std::string program_name) const |
Log Footer. | |
void | logAllOptions () const |
Log all program options. | |
void | logTheEnvironment () const |
Log the program environment. | |
void | bootstrapEnvironment (char *arg0) |
Bootstrap the Environment from the executable location and the install path computed at install time. | |
template<class charT> | |
void | checkCommandLineOptions (const boost::program_options::basic_parsed_options< charT > &cmd_line_options) |
check the explicit command line arguments. For the moment, it only checks if the configuration file being passed does exist. It exits with ExitCode::CONFIG if the file cannot be found. |
Static Private Member Functions | |
static const Path::Item | getDefaultConfigFile (const Path::Item &program_name, const std::string &module_name="") |
Get a default configuration file name and path, to be used if not provided as a command line option. | |
static const Path::Item | setProgramName (char *arg0) |
Strip the path from argv[0] to set the program name. | |
static const Path::Item | setProgramPath (char *arg0) |
Strip the name from argv[0] to set the program path. |
Private Attributes | |
Program::VariablesMap | m_variables_map {} |
Path::Item | m_program_name |
Path::Item | m_program_path |
std::unique_ptr< Program > | m_program_ptr |
std::string | m_parent_project_version |
std::string | m_parent_project_name |
std::string | m_parent_project_vcs_version |
std::string | m_parent_module_version |
std::string | m_parent_module_name |
std::vector< std::string > | m_search_dirs |
Environment | m_env |
log4cpp::Priority::Value | m_elements_loglevel |
bool | m_no_config_file |
Class for managing all Elements programs.
This base class offers solutions for the common needs of all Elements programs, such as those dealing with program options and logging.
Definition at line 60 of file ProgramManager.h.
|
explicit |
Constructor.
Definition at line 70 of file ProgramManager.cpp.
References m_elements_loglevel, m_env, m_no_config_file, m_parent_module_name, m_parent_module_version, m_parent_project_name, m_parent_project_vcs_version, m_parent_project_version, m_program_ptr, and m_search_dirs.
|
virtual |
Destructor.
Definition at line 475 of file ProgramManager.cpp.
|
private |
Bootstrap the Environment from the executable location and the install path computed at install time.
Definition at line 379 of file ProgramManager.cpp.
References std::vector< T >::begin(), std::vector< T >::insert(), m_env, m_program_name, m_program_path, m_search_dirs, setProgramName(), setProgramPath(), and std::transform().
Referenced by setup().
|
private |
check the explicit command line arguments. For the moment, it only checks if the configuration file being passed does exist. It exits with ExitCode::CONFIG if the file cannot be found.
Referenced by getProgramOptions().
|
staticprivate |
Get a default configuration file name and path, to be used if not provided as a command line option.
Get default config file.
Definition at line 99 of file ProgramManager.cpp.
References std::string::empty().
Referenced by getProgramOptions().
|
private |
Getter.
Definition at line 90 of file ProgramManager.cpp.
References m_program_name.
Referenced by getProgramOptions().
|
private |
Get the program options from the command line into thevariables_map.
Definition at line 146 of file ProgramManager.cpp.
References checkCommandLineOptions(), endl(), std::exit(), getDefaultConfigFile(), getProgramName(), getVersion(), m_no_config_file, m_parent_module_name, m_program_ptr, and Elements::OK.
Referenced by setup().
|
private |
Getter.
Definition at line 86 of file ProgramManager.cpp.
References m_program_path.
string Elements::ProgramManager::getVersion | ( | ) | const |
This function returns the version of the program computed at compile time. This is the same as the project version that contains the program.
Definition at line 468 of file ProgramManager.cpp.
References m_parent_project_name, and m_parent_project_vcs_version.
Referenced by getProgramOptions().
|
private |
Log all program options.
Definition at line 293 of file ProgramManager.cpp.
References endl(), m_elements_loglevel, m_variables_map, and stringstream::str().
Referenced by setup().
|
private |
Log Footer.
Definition at line 283 of file ProgramManager.cpp.
References m_elements_loglevel.
Referenced by tearDown().
|
private |
Log Header.
Definition at line 273 of file ProgramManager.cpp.
References m_elements_loglevel, m_program_name, and m_program_path.
Referenced by setup().
|
private |
Log the program environment.
Definition at line 364 of file ProgramManager.cpp.
References m_env.
Referenced by setup().
|
staticnoexcept |
This is the set_terminate handler that is used in the MAIN_FOR macro.
Definition at line 477 of file ProgramManager.cpp.
References std::_Exit(), Elements::System::backTrace(), std::current_exception(), Elements::Exception::exitCode(), Elements::NOT_OK, std::rethrow_exception(), Elements::Exception::what(), and std::exception::what().
ExitCode Elements::ProgramManager::run | ( | int | argc, |
char * | argv[] ) |
This is the public entry point, i.e., the only method called from the main.
argc | Command line argument number |
argv | Command line arguments |
Definition at line 457 of file ProgramManager.cpp.
References m_program_ptr, m_variables_map, setup(), and tearDown().
|
staticprivate |
Strip the path from argv[0] to set the program name.
arg0 | The first element of the command line, i.e., argv[0] |
Definition at line 129 of file ProgramManager.cpp.
References ELEMENTS_UNUSED, and Elements::getExecutablePath().
Referenced by bootstrapEnvironment().
|
staticprivate |
Strip the name from argv[0] to set the program path.
arg0 | The first element of the command line, i.e., argv[0] |
Definition at line 136 of file ProgramManager.cpp.
References ELEMENTS_UNUSED, and Elements::getExecutablePath().
Referenced by bootstrapEnvironment().
|
private |
Program setup taking care of command line options and logging initialization.
Definition at line 411 of file ProgramManager.cpp.
References std::_Exit(), bootstrapEnvironment(), Elements::CONFIG, getProgramOptions(), logAllOptions(), logHeader(), logTheEnvironment(), m_program_name, m_variables_map, Elements::Logging::setLevel(), and Elements::Logging::setLogFile().
Referenced by run().
|
private |
Definition at line 449 of file ProgramManager.cpp.
References logFooter(), and m_program_name.
Referenced by run().
|
private |
default info level for the Elements internal logging messages
Definition at line 278 of file ProgramManager.h.
Referenced by logAllOptions(), logFooter(), logHeader(), and ProgramManager().
|
private |
Local environment of the executable
Definition at line 273 of file ProgramManager.h.
Referenced by bootstrapEnvironment(), logTheEnvironment(), and ProgramManager().
|
private |
prevent the –config-file option to be added
Definition at line 283 of file ProgramManager.h.
Referenced by getProgramOptions(), and ProgramManager().
|
private |
Name of the parent project.
Definition at line 260 of file ProgramManager.h.
Referenced by getProgramOptions(), and ProgramManager().
|
private |
Version of the parent Elements module
Definition at line 255 of file ProgramManager.h.
Referenced by ProgramManager().
|
private |
Name of the parent project. To avoid ambiguities and because a module can be moved from one project to another, the full version of the program will look like
m_parent_project_version [m_parent_project_name]
Definition at line 244 of file ProgramManager.h.
Referenced by getVersion(), and ProgramManager().
|
private |
Internal version of the program. By convention, it is the same as the VCS version of the parent project
Definition at line 250 of file ProgramManager.h.
Referenced by getVersion(), and ProgramManager().
|
private |
Internal version of the project
Definition at line 235 of file ProgramManager.h.
Referenced by ProgramManager().
|
private |
Name of the executable (from argv[0])
Definition at line 217 of file ProgramManager.h.
Referenced by bootstrapEnvironment(), getProgramName(), logHeader(), setup(), and tearDown().
|
private |
Path of the executable (from argv[0])
Definition at line 222 of file ProgramManager.h.
Referenced by bootstrapEnvironment(), getProgramPath(), and logHeader().
|
private |
Pointer to a program interface, which provides two methods defineSpecificProgramOption() mainMethod()
Definition at line 230 of file ProgramManager.h.
Referenced by getProgramOptions(), ProgramManager(), and run().
|
private |
List of directories needed to update the runtime search environment (PATH, LD_LIBRARY_PATH, ELEMENTS_CONF_PATH, and ELEMENTS_AUX_PATH). This list contains the install locations of all the dependent projects.
Definition at line 268 of file ProgramManager.h.
Referenced by bootstrapEnvironment(), and ProgramManager().
|
private |
This is the BOOST program options variable_map used to store all program options. It is similar to a std::map but the element can be of different types. See the pseudoMain() in ElementsExamples/src/program/Program.cpp to see how to retrieve options from this map.
Definition at line 212 of file ProgramManager.h.
Referenced by logAllOptions(), run(), and setup().