Elements  6.2
A C++ base framework for the Euclid Software.
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Elements::ProgramManager Class Reference

Class for managing all Elements programs. More...

#include <ProgramManager.h>

Collaboration diagram for Elements::ProgramManager:
Collaboration graph
[legend]

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)
 Constructor. More...
 
virtual ~ProgramManager ()
 Destructor. More...
 
ExitCode run (int argc, char *argv[])
 This is the public entry point, i.e., the only method called from the main. More...
 
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. More...
 

Static Public Member Functions

static void onTerminate () noexcept
 This is the set_terminate handler that is used in the MAIN_FOR macro. More...
 

Private Member Functions

const Path::Item & getProgramPath () const
 Getter. More...
 
const Path::Item & getProgramName () const
 Getter. More...
 
void setup (int argc, char *argv[])
 Program setup taking care of command line options and logging initialization. More...
 
void tearDown (const ExitCode &)
 
const Program::VariablesMap getProgramOptions (int argc, char *argv[])
 Get the program options from the command line into thevariables_map. More...
 
void logHeader (std::string program_name) const
 Log Header. More...
 
void logFooter (std::string program_name) const
 Log Footer. More...
 
void logAllOptions () const
 Log all program options. More...
 
void logTheEnvironment () const
 Log the program environment. More...
 
void bootstrapEnvironment (char *arg0)
 Bootstrap the Environment from the executable location and the install path computed at install time. More...
 
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. More...
 

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. More...
 
static const Path::Item setProgramName (char *arg0)
 Strip the path from argv[0] to set the program name. More...
 
static const Path::Item setProgramPath (char *arg0)
 Strip the name from argv[0] to set the program path. More...
 

Private Attributes

Program::VariablesMap m_variables_map {}
 
Path::Item m_program_name
 
Path::Item m_program_path
 
std::unique_ptr< Programm_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::stringm_search_dirs
 
Environment m_env
 
log4cpp::Priority::Value m_elements_loglevel
 

Detailed Description

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 55 of file ProgramManager.h.

Constructor & Destructor Documentation

◆ ProgramManager()

Elements::ProgramManager::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 
)
explicit

Constructor.

Definition at line 68 of file ProgramManager.cpp.

◆ ~ProgramManager()

Elements::ProgramManager::~ProgramManager ( )
virtual

Destructor.

Definition at line 483 of file ProgramManager.cpp.

Member Function Documentation

◆ bootstrapEnvironment()

void Elements::ProgramManager::bootstrapEnvironment ( char *  arg0)
private

◆ checkCommandLineOptions()

template<class charT >
void Elements::ProgramManager::checkCommandLineOptions ( const boost::program_options::basic_parsed_options< charT > &  cmd_line_options)
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.

Definition at line 140 of file ProgramManager.cpp.

References Elements::CONFIG, and Elements::USAGE.

Referenced by getProgramOptions().

◆ getDefaultConfigFile()

const Path::Item Elements::ProgramManager::getDefaultConfigFile ( const Path::Item &  program_name,
const std::string module_name = "" 
)
staticprivate

Get a default configuration file name and path, to be used if not provided as a command line option.

Get default config file.

Returns
A complete name/path to the default configuration file
Todo:
check whether priotities are correct if more than one config file is found in pathSearchInEnvVariable

Definition at line 95 of file ProgramManager.cpp.

References std::string::empty(), Elements::Kernel::getConfigurationLocations(), Elements::Kernel::getConfigurationPath(), and Elements::Examples::log.

Referenced by getProgramOptions().

Here is the call graph for this function:

◆ getProgramName()

const Path::Item & Elements::ProgramManager::getProgramName ( ) const
private

Getter.

Returns
The program name

Definition at line 86 of file ProgramManager.cpp.

References m_program_name.

Referenced by getProgramOptions().

◆ getProgramOptions()

const VariablesMap Elements::ProgramManager::getProgramOptions ( int  argc,
char *  argv[] 
)
private

Get the program options from the command line into thevariables_map.

Returns
A BOOST variable_map

Definition at line 162 of file ProgramManager.cpp.

References checkCommandLineOptions(), Elements::Kernel::Units::e, std::exit(), getDefaultConfigFile(), getProgramName(), getVersion(), m_parent_module_name, m_program_ptr, and Elements::OK.

Referenced by setup().

Here is the call graph for this function:

◆ getProgramPath()

const Path::Item & Elements::ProgramManager::getProgramPath ( ) const
private

Getter.

Returns
The program path

Definition at line 82 of file ProgramManager.cpp.

References m_program_path.

◆ getVersion()

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 476 of file ProgramManager.cpp.

References m_parent_project_name, and m_parent_project_vcs_version.

Referenced by getProgramOptions().

◆ logAllOptions()

void Elements::ProgramManager::logAllOptions ( ) const
private

Log all program options.

Definition at line 301 of file ProgramManager.cpp.

References Elements::Examples::log, m_elements_loglevel, and m_variables_map.

Referenced by setup().

◆ logFooter()

void Elements::ProgramManager::logFooter ( std::string  program_name) const
private

Log Footer.

Definition at line 291 of file ProgramManager.cpp.

References Elements::Examples::log, and m_elements_loglevel.

Referenced by tearDown().

◆ logHeader()

void Elements::ProgramManager::logHeader ( std::string  program_name) const
private

Log Header.

Definition at line 281 of file ProgramManager.cpp.

References Elements::Examples::log, m_elements_loglevel, m_program_name, and m_program_path.

Referenced by setup().

◆ logTheEnvironment()

void Elements::ProgramManager::logTheEnvironment ( ) const
private

Log the program environment.

Definition at line 372 of file ProgramManager.cpp.

References Elements::Examples::log, m_env, and Elements::Kernel::Path::VARIABLE.

Referenced by setup().

◆ onTerminate()

void Elements::ProgramManager::onTerminate ( )
staticnoexcept

This is the set_terminate handler that is used in the MAIN_FOR macro.

Todo:
: set the exit code according to the type of exception if a clear match is found.

Definition at line 485 of file ProgramManager.cpp.

References std::_Exit(), Elements::System::backTrace(), std::current_exception(), Elements::Exception::exitCode(), Elements::Examples::log, Elements::NOT_OK, std::rethrow_exception(), std::exception::what(), and Elements::Exception::what().

Here is the call graph for this function:

◆ run()

ExitCode Elements::ProgramManager::run ( int  argc,
char *  argv[] 
)

This is the public entry point, i.e., the only method called from the main.

Parameters
argcCommand line argument number
argvCommand line arguments

Definition at line 465 of file ProgramManager.cpp.

References m_program_ptr, m_variables_map, setup(), and tearDown().

Here is the call graph for this function:

◆ setProgramName()

const Path::Item Elements::ProgramManager::setProgramName ( char *  arg0)
staticprivate

Strip the path from argv[0] to set the program name.

Parameters
arg0The first element of the command line, i.e., argv[0]
Returns
A BOOST path with the program name

Definition at line 125 of file ProgramManager.cpp.

References Elements::System::getExecutablePath().

Referenced by bootstrapEnvironment().

Here is the call graph for this function:

◆ setProgramPath()

const Path::Item Elements::ProgramManager::setProgramPath ( char *  arg0)
staticprivate

Strip the name from argv[0] to set the program path.

Parameters
arg0The first element of the command line, i.e., argv[0]
Returns
A BOOST path with the program path

Definition at line 132 of file ProgramManager.cpp.

References Elements::System::getExecutablePath().

Referenced by bootstrapEnvironment().

Here is the call graph for this function:

◆ setup()

void Elements::ProgramManager::setup ( int  argc,
char *  argv[] 
)
private

Program setup taking care of command line options and logging initialization.

Definition at line 419 of file ProgramManager.cpp.

References std::_Exit(), bootstrapEnvironment(), Elements::CONFIG, Elements::Kernel::Units::e, getProgramOptions(), Elements::Examples::log, logAllOptions(), logHeader(), logTheEnvironment(), m_program_name, m_variables_map, Elements::Logging::setLevel(), and Elements::Logging::setLogFile().

Referenced by run().

Here is the call graph for this function:

◆ tearDown()

void Elements::ProgramManager::tearDown ( const ExitCode c)
private

Definition at line 457 of file ProgramManager.cpp.

References Elements::Examples::log, logFooter(), and m_program_name.

Referenced by run().

Here is the call graph for this function:

Member Data Documentation

◆ m_elements_loglevel

log4cpp::Priority::Value Elements::ProgramManager::m_elements_loglevel
private

default info level for the Elements internal logging messages

Definition at line 272 of file ProgramManager.h.

Referenced by logAllOptions(), logFooter(), and logHeader().

◆ m_env

Environment Elements::ProgramManager::m_env
private

Local environment of the executable

Definition at line 267 of file ProgramManager.h.

Referenced by bootstrapEnvironment(), and logTheEnvironment().

◆ m_parent_module_name

std::string Elements::ProgramManager::m_parent_module_name
private

Name of the parent project.

Definition at line 254 of file ProgramManager.h.

Referenced by getProgramOptions().

◆ m_parent_module_version

std::string Elements::ProgramManager::m_parent_module_version
private

Version of the parent Elements module

Definition at line 249 of file ProgramManager.h.

◆ m_parent_project_name

std::string Elements::ProgramManager::m_parent_project_name
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 238 of file ProgramManager.h.

Referenced by getVersion().

◆ m_parent_project_vcs_version

std::string Elements::ProgramManager::m_parent_project_vcs_version
private

Internal version of the program. By convention, it is the same as the VCS version of the parent project

Definition at line 244 of file ProgramManager.h.

Referenced by getVersion().

◆ m_parent_project_version

std::string Elements::ProgramManager::m_parent_project_version
private

Internal version of the project

Definition at line 229 of file ProgramManager.h.

◆ m_program_name

Path::Item Elements::ProgramManager::m_program_name
private

Name of the executable (from argv[0])

Definition at line 211 of file ProgramManager.h.

Referenced by bootstrapEnvironment(), getProgramName(), logHeader(), setup(), and tearDown().

◆ m_program_path

Path::Item Elements::ProgramManager::m_program_path
private

Path of the executable (from argv[0])

Definition at line 216 of file ProgramManager.h.

Referenced by bootstrapEnvironment(), getProgramPath(), and logHeader().

◆ m_program_ptr

std::unique_ptr<Program> Elements::ProgramManager::m_program_ptr
private

Pointer to a program interface, which provides two methods defineSpecificProgramOption() mainMethod()

Definition at line 224 of file ProgramManager.h.

Referenced by getProgramOptions(), and run().

◆ m_search_dirs

std::vector<std::string> Elements::ProgramManager::m_search_dirs
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 262 of file ProgramManager.h.

Referenced by bootstrapEnvironment().

◆ m_variables_map

Program::VariablesMap Elements::ProgramManager::m_variables_map {}
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 206 of file ProgramManager.h.

Referenced by logAllOptions(), run(), and setup().


The documentation for this class was generated from the following files: