Alexandria  2.27.0
SDC-CH common library for the Euclid project
ConfigManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2022 Euclid Science Ground Segment
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 3.0 of the License, or (at your option)
7  * any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
25 #ifndef _CONFIGURATION_CONFIGMANAGER_H
26 #define _CONFIGURATION_CONFIGMANAGER_H
27 
28 #include <boost/program_options/options_description.hpp>
29 #include <boost/program_options/variables_map.hpp>
30 #include <map>
31 #include <memory>
32 #include <string>
33 #include <typeindex>
34 
35 namespace Euclid {
36 namespace Configuration {
37 
38 // Forward definition of the Configuration class. It is included in the .icpp
39 // file. This is done to break the include circle.
40 class Configuration;
41 
86 
87 public:
89  static ConfigManager& getInstance(long id);
90 
100  static void deregisterInstance(long id);
101 
102  long getId() const {
103  return m_id;
104  }
105 
109  virtual ~ConfigManager() = default;
110 
125  template <typename T>
127 
148  template <typename T1, typename T2>
150 
166  boost::program_options::options_description closeRegistration();
167 
188 
202  template <typename T>
204 
205 private:
206  explicit ConfigManager(long id);
207 
209 
210  long m_id;
215 
216 }; /* End of ConfigManager class */
217 
218 } /* namespace Configuration */
219 } /* namespace Euclid */
220 
222 
223 #endif
Manages a set of configuration classes.
Definition: ConfigManager.h:85
std::unique_ptr< std::type_index > m_root_config
void registerConfiguration()
Registers a Configuration to the manager.
void registerDependency()
Registers a dependency between two configurations.
T & getConfiguration()
Returns a reference to the requested configuration.
static void deregisterInstance(long id)
std::map< std::type_index, std::unique_ptr< Configuration > > m_config_dictionary
virtual ~ConfigManager()=default
Destructor.
void initialize(const std::map< std::string, boost::program_options::variable_value > &user_values)
Initialize the manager.
std::map< std::type_index, std::set< std::type_index > > m_dependency_map
boost::program_options::options_description closeRegistration()
Terminates the manager registration phase.
static ConfigManager & getInstance(long id)
Returns a reference to the ConfigManager with the given ID.