Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Euclid::Configuration::ConfigManager Class Reference

Manages a set of configuration classes. More...

#include <ConfigManager.h>

Collaboration diagram for Euclid::Configuration::ConfigManager:
Collaboration graph
[legend]

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 ConfigManagergetInstance (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_indexm_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
 

Detailed Description

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.

Member Enumeration Documentation

◆ State

Enumerator
REGISTRATION 
WAITING_INITIALIZATION 
INITIALIZED 

Definition at line 208 of file ConfigManager.h.

Constructor & Destructor Documentation

◆ ~ConfigManager()

virtual Euclid::Configuration::ConfigManager::~ConfigManager ( )
virtualdefault

Destructor.

◆ ConfigManager()

Euclid::Configuration::ConfigManager::ConfigManager ( long  id)
explicitprivate

Definition at line 50 of file ConfigManager.cpp.

Member Function Documentation

◆ closeRegistration()

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.

Returns
The options_description describing the parameters of all the managed Configurations
Exceptions
Elements::ExceptionIf 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.

Here is the call graph for this function:

◆ deregisterInstance()

void Euclid::Configuration::ConfigManager::deregisterInstance ( long  id)
static

Destroy a ConfigManager instance

Warning
This is a dangerous thing to do, since something somewhere may be holding a reference to the given instance. However, since the ConfigManager instances are kept on a static map, it is undefined when they will be destroyed at the end of the process. In those situations, it may be necessary to destroy them by hand before some other global dependency is torn down (I am looking at sourcextractor++ and the Python interpreter, which is required by the ModelFittingConfig)

Definition at line 46 of file ConfigManager.cpp.

References Euclid::Configuration::manager_map.

◆ getConfiguration()

template<typename T >
T & Euclid::Configuration::ConfigManager::getConfiguration ( )

Returns a reference to the requested configuration.

Template Parameters
TThe type of the Configuration
Returns
A reference to the requested configuration
Exceptions
Elements::ExceptionIf the manager is not initialized
Elements::ExceptionIf the manager does not manage the requested configuration

◆ getId()

long Euclid::Configuration::ConfigManager::getId ( ) const
inline

Definition at line 102 of file ConfigManager.h.

References m_id.

◆ getInstance()

ConfigManager & Euclid::Configuration::ConfigManager::getInstance ( long  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.

◆ initialize()

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.

Parameters
user_valuesThe user values to initialize the configurations with

Definition at line 162 of file ConfigManager.cpp.

References Elements::Logging::debug(), logger, and Euclid::Configuration::recursiveInitialization().

Here is the call graph for this function:

◆ registerConfiguration()

template<typename T >
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.

Template Parameters
TThe type of the Configuration to register
Exceptions
Elements::ExceptionIf the manager is closed for registration

◆ registerDependency()

template<typename T1 , typename T2 >
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.

Template Parameters
T1The dependant Configuration type
T2The dependency Configuration type
Exceptions
Elements::ExceptionIf the manager is closed for registration

Member Data Documentation

◆ m_config_dictionary

std::map<std::type_index, std::unique_ptr<Configuration> > Euclid::Configuration::ConfigManager::m_config_dictionary
private

Definition at line 213 of file ConfigManager.h.

Referenced by closeRegistration().

◆ m_dependency_map

std::map<std::type_index, std::set<std::type_index> > Euclid::Configuration::ConfigManager::m_dependency_map
private

Definition at line 214 of file ConfigManager.h.

Referenced by closeRegistration().

◆ m_id

long Euclid::Configuration::ConfigManager::m_id
private

Definition at line 210 of file ConfigManager.h.

Referenced by getId().

◆ m_root_config

std::unique_ptr<std::type_index> Euclid::Configuration::ConfigManager::m_root_config
private

Definition at line 212 of file ConfigManager.h.

◆ m_state

State Euclid::Configuration::ConfigManager::m_state = State::REGISTRATION
private

Definition at line 211 of file ConfigManager.h.

Referenced by closeRegistration().


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