Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
Manages a set of configuration classes. More...
#include <ConfigManager.h>
Public Member Functions | |
long | getId () const |
virtual | ~ConfigManager ()=default |
Destructor. | |
template<typename T > | |
void | registerConfiguration () |
Registers a Configuration to the manager. | |
template<typename T1 , typename T2 > | |
void | registerDependency () |
Registers a dependency between two configurations. | |
boost::program_options::options_description | closeRegistration () |
Terminates the manager registration phase. | |
void | initialize (const std::map< std::string, boost::program_options::variable_value > &user_values) |
Initialize the manager. | |
template<typename T > | |
T & | getConfiguration () |
Returns a reference to the requested configuration. | |
Static Public Member Functions | |
static ConfigManager & | getInstance (long id) |
Returns a reference to the ConfigManager with the given ID. | |
static void | deregisterInstance (long id) |
Private Types | |
enum class | State { REGISTRATION , WAITING_INITIALIZATION , INITIALIZED } |
Private Member Functions | |
ConfigManager (long id) | |
Private Attributes | |
long | m_id |
State | m_state = State::REGISTRATION |
std::unique_ptr< std::type_index > | m_root_config |
std::map< std::type_index, std::unique_ptr< Configuration > > | m_config_dictionary |
std::map< std::type_index, std::set< std::type_index > > | m_dependency_map |
Manages a set of configuration classes.
The ConfigManager is responsible for handling a set of configuration classes. For flexibility (for the case an executable is called from another one), this class is not implemented as a singleton, but a factory method is provided, which returns the manager instances based on an ID.
Each manager instance is responsible for managing a set of configurations, which can be registered by using the registerConfiguration() method. When this method is used, all the dependencies of the configuration being registered are also registered automatically.
A manager can be under the following states, which describe how it can be used:
Definition at line 85 of file ConfigManager.h.
|
strongprivate |
Enumerator | |
---|---|
REGISTRATION | |
WAITING_INITIALIZATION | |
INITIALIZED |
Definition at line 208 of file ConfigManager.h.
|
virtualdefault |
Destructor.
|
explicitprivate |
Definition at line 50 of file ConfigManager.cpp.
po::options_description Euclid::Configuration::ConfigManager::closeRegistration | ( | ) |
Terminates the manager registration phase.
This call will make a test that there are no circular dependencies between the registered configurations. The returned options_description can be used for parsing the user input.
Elements::Exception | If there are circular dependencies between the configurations |
Definition at line 99 of file ConfigManager.cpp.
References Euclid::Configuration::cleanupNonRegisteredDependencies(), std::map< K, T >::emplace(), Elements::Logging::error(), std::map< K, T >::find(), Euclid::Configuration::hasCircularDependencies(), std::map< K, T >::insert(), Euclid::Configuration::logger, m_config_dictionary, m_dependency_map, m_state, and WAITING_INITIALIZATION.
|
static |
Destroy a ConfigManager instance
Definition at line 46 of file ConfigManager.cpp.
References Euclid::Configuration::manager_map.
T & Euclid::Configuration::ConfigManager::getConfiguration | ( | ) |
Returns a reference to the requested configuration.
T | The type of the Configuration |
Elements::Exception | If the manager is not initialized |
Elements::Exception | If the manager does not manage the requested configuration |
|
inline |
Definition at line 102 of file ConfigManager.h.
References m_id.
|
static |
Returns a reference to the ConfigManager with the given ID.
Definition at line 38 of file ConfigManager.cpp.
References Euclid::Configuration::manager_map.
void Euclid::Configuration::ConfigManager::initialize | ( | const std::map< std::string, boost::program_options::variable_value > & | user_values | ) |
Initialize the manager.
This method gets as arguments the user parameters to initialize the configurations with. During the initialization phase, the manager performs three actions. First, it calls the preInitialize() method of all its managed configurations, in arbitrary order. Second, it calls the initialize() method of the managed configurations, in such order so all dependencies of a configuration have already been initialized before its method is called. Finally, it calls the postInitialize() methods, again in arbitrary order.
When this method returns, all the configurations are in FINAL state and the manager in INITIALIZED state.
user_values | The user values to initialize the configurations with |
Definition at line 162 of file ConfigManager.cpp.
References Elements::Logging::debug(), logger, and Euclid::Configuration::recursiveInitialization().
void Euclid::Configuration::ConfigManager::registerConfiguration | ( | ) |
Registers a Configuration to the manager.
After this method is executed all the dependencies of the Configuration will also be registered (recursively). This method can be executed more than one time for the same configuration. Consecutive calls have no extra effect.
T | The type of the Configuration to register |
Elements::Exception | If the manager is closed for registration |
void Euclid::Configuration::ConfigManager::registerDependency | ( | ) |
Registers a dependency between two configurations.
This method can be used to define extra dependencies between configurations than the ones defined by the configurations themselves. Calling this method does not register the related configurations. If any of the related configurations is not registered during the registration phase, the dependency is ignored.
The meaning of the template parameters is that the T1 depends on T2.
T1 | The dependant Configuration type |
T2 | The dependency Configuration type |
Elements::Exception | If the manager is closed for registration |
|
private |
Definition at line 213 of file ConfigManager.h.
Referenced by closeRegistration().
|
private |
Definition at line 214 of file ConfigManager.h.
Referenced by closeRegistration().
|
private |
Definition at line 210 of file ConfigManager.h.
Referenced by getId().
|
private |
Definition at line 212 of file ConfigManager.h.
|
private |
Definition at line 211 of file ConfigManager.h.
Referenced by closeRegistration().