2 * Copyright (C) 2012-2020 Euclid Science Ground Segment
4 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
5 * Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
13 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 * @file Configuration/_impl/ConfigManager.icpp
22 #include "ElementsKernel/Exception.h"
23 #include "Configuration/Configuration.h"
26 namespace Configuration {
29 void ConfigManager::registerConfiguration() {
30 static_assert(std::is_base_of<Configuration, T>::value,
31 "T template parameter must inherit from Configuration");
32 if (m_state != State::REGISTRATION) {
33 throw Elements::Exception() << "Manager with id '" << m_id << "' is closed "
34 << "for configuration registration";
36 // If the configuration is already registered we do nothing
37 if (m_config_dictionary[{typeid(T)}] == nullptr) {
38 m_config_dictionary[{typeid(T)}].reset(new T{m_id});
42 template <typename T1, typename T2>
43 void ConfigManager::registerDependency() {
44 static_assert(std::is_base_of<Configuration, T1>::value,
45 "T1 template parameter must inherit from Configuration");
46 static_assert(std::is_base_of<Configuration, T2>::value,
47 "T2 template parameter must inherit from Configuration");
48 if (m_state != State::REGISTRATION) {
49 throw Elements::Exception() << "Manager with id '" << m_id << "' is closed "
50 << "for dependency registration";
52 m_dependency_map[typeid(T1)].emplace(typeid(T2));
56 T& ConfigManager::getConfiguration() {
57 static_assert(std::is_base_of<Configuration, T>::value,
58 "T template parameter must inherit from Configuration");
59 if (m_state != State::INITIALIZED) {
60 throw Elements::Exception() << "Method getConfiguration() cannot be called on "
61 << "uninitialized manager with id '" << m_id << "'";
63 if (m_config_dictionary.find(typeid(T)) == m_config_dictionary.end()) {
64 throw Elements::Exception() << "No configuration with type " << typeid(T).name()
65 << " has been registered (manager with id '" << m_id << "')";
67 return static_cast<T&>(*m_config_dictionary.at(typeid(T)));
70 } // Configuration namespace