Belle II Software light-2406-ragdoll
ModuleManager.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/FrameworkExceptions.h>
12
13#include <memory>
14
15#include <string>
16#include <map>
17#include <list>
18#include <filesystem>
19
20namespace Belle2 {
26 class Module;
27 class ModuleProxyBase;
28
54
55 public:
56
57 //Define exceptions
59 BELLE2_DEFINE_EXCEPTION(ModuleNotCreatedError, "Cannot create module %1%: %2%")
60
61
66 static ModuleManager& Instance();
67
75 void registerModuleProxy(ModuleProxyBase* moduleProxy);
76
87 void addModuleSearchPath(const std::string& path);
88
94 const std::list<std::string>& getModuleSearchPaths() const;
95
103 const std::map<std::string, std::string>& getAvailableModules() const;
104
121 std::shared_ptr<Module> registerModule(const std::string& moduleName,
122 std::string sharedLibPath = "") noexcept(false);
123
129 const std::list< std::shared_ptr<Module> >& getCreatedModules() const;
130
141 static std::list< std::shared_ptr<Module> > getModulesByProperties(const std::list< std::shared_ptr<Module> >& modulePathList,
142 unsigned int propertyFlags);
143
145 static bool allModulesHaveFlag(const std::list<std::shared_ptr<Module>>& list, unsigned int flag);
146
148 void reset();
149
150
151 private:
153 std::list<std::string> m_moduleSearchPathList;
154
156 std::map<std::string, std::string> m_moduleNameLibMap;
157
158 std::map<std::string, ModuleProxyBase*> m_registeredProxyMap;
159 std::list< std::shared_ptr<Module> > m_createdModulesList;
169 static void fillModuleNameLibMap(std::map<std::string, std::string>& moduleNameLibMap,
170 const std::filesystem::directory_entry& mapPath);
171
176
181
186
192 };
193
195} //end of namespace Belle2
The ModuleManager Class.
Definition: ModuleManager.h:53
void registerModuleProxy(ModuleProxyBase *moduleProxy)
Registers a module proxy.
const std::map< std::string, std::string > & getAvailableModules() const
Returns a map of all modules that were found in the module search paths.
const std::list< std::shared_ptr< Module > > & getCreatedModules() const
Returns a reference to the list of created modules.
std::list< std::shared_ptr< Module > > m_createdModulesList
List of all created modules.
static std::list< std::shared_ptr< Module > > getModulesByProperties(const std::list< std::shared_ptr< Module > > &modulePathList, unsigned int propertyFlags)
Returns a list of those modules which carry property flags matching the specified ones.
const std::list< std::string > & getModuleSearchPaths() const
Returns a reference to the list of the modules search filepaths.
std::shared_ptr< Module > registerModule(const std::string &moduleName, std::string sharedLibPath="") noexcept(false)
Creates an instance of a module and registers it to the ModuleManager.
ModuleManager(const ModuleManager &)
Disable/Hide the copy constructor.
std::list< std::string > m_moduleSearchPathList
List of all checked and validated filepaths that are searched for map files.
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
std::map< std::string, std::string > m_moduleNameLibMap
Maps the module name to the filename of the shared library which containes the module.
static void fillModuleNameLibMap(std::map< std::string, std::string > &moduleNameLibMap, const std::filesystem::directory_entry &mapPath)
Adds the module names defined in the map file to the list of known module names.
~ModuleManager()
The ModuleManager destructor.
ModuleManager & operator=(const ModuleManager &)
Disable/Hide the copy assignment operator.
ModuleManager()
The constructor is hidden to avoid that someone creates an instance of this class.
std::map< std::string, ModuleProxyBase * > m_registeredProxyMap
Maps the module name to a pointer of its proxy.
void reset()
Delete all created modules.
void addModuleSearchPath(const std::string &path)
Adds a new filepath to the list of filepaths which are searched for a requested module.
static bool allModulesHaveFlag(const std::list< std::shared_ptr< Module > > &list, unsigned int flag)
Returns true if and only if all modules in list have the given flag (or list is empty).
The base module proxy class is used to create new instances of a module.
Definition: Module.h:597
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24