Alexandria  2.22.0
Please provide a description of the project.
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:
[legend]

Public Member Functions

virtual ~ConfigManager ()=default
 Destructor. More...
 
template<typename T >
void registerConfiguration ()
 Registers a Configuration to the manager. More...
 
template<typename T1 , typename T2 >
void registerDependency ()
 Registers a dependency between two configurations. More...
 
boost::program_options::options_description closeRegistration ()
 Terminates the manager registration phase. More...
 
void initialize (const std::map< std::string, boost::program_options::variable_value > &user_values)
 Initialize the manager. More...
 
template<typename T >
T & getConfiguration ()
 Returns a reference to the requested configuration. More...
 

Static Public Member Functions

static ConfigManagergetInstance (long id)
 Returns a reference to the ConfigManager with the given ID. More...
 

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 81 of file ConfigManager.h.

Member Enumeration Documentation

◆ State

Enumerator
REGISTRATION 
WAITING_INITIALIZATION 
INITIALIZED 

Definition at line 189 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 43 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 94 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:

◆ 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

◆ getInstance()

ConfigManager & Euclid::Configuration::ConfigManager::getInstance ( long  id)
static

Returns a reference to the ConfigManager with the given ID.

Definition at line 34 of file ConfigManager.cpp.

◆ 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 157 of file ConfigManager.cpp.

References Elements::Logging::debug(), Euclid::Configuration::Configuration::FINAL, INITIALIZED, Euclid::Configuration::logger, m_config_dictionary, m_dependency_map, m_state, Euclid::Configuration::Configuration::PRE_INITIALIZED, 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 194 of file ConfigManager.h.

Referenced by closeRegistration(), and initialize().

◆ m_dependency_map

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

Definition at line 195 of file ConfigManager.h.

Referenced by closeRegistration(), and initialize().

◆ m_id

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

Definition at line 191 of file ConfigManager.h.

◆ m_root_config

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

Definition at line 193 of file ConfigManager.h.

◆ m_state

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

Definition at line 192 of file ConfigManager.h.

Referenced by closeRegistration(), and initialize().


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