Belle II Software  release-06-02-00
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 
19 namespace boost {
20  namespace filesystem {
21  class directory_entry;
22  }
23 }
24 
25 namespace Belle2 {
31  class Module;
32  class ModuleProxyBase;
33 
58  class ModuleManager {
59 
60  public:
61 
62  //Define exceptions
64  BELLE2_DEFINE_EXCEPTION(ModuleNotCreatedError, "Cannot create module %1%: %2%")
65 
66 
71  static ModuleManager& Instance();
72 
80  void registerModuleProxy(ModuleProxyBase* moduleProxy);
81 
92  void addModuleSearchPath(const std::string& path);
93 
99  const std::list<std::string>& getModuleSearchPaths() const;
100 
108  const std::map<std::string, std::string>& getAvailableModules() const;
109 
126  std::shared_ptr<Module> registerModule(const std::string& moduleName,
127  std::string sharedLibPath = "") noexcept(false);
128 
134  const std::list< std::shared_ptr<Module> >& getCreatedModules() const;
135 
146  static std::list< std::shared_ptr<Module> > getModulesByProperties(const std::list< std::shared_ptr<Module> >& modulePathList,
147  unsigned int propertyFlags);
148 
150  static bool allModulesHaveFlag(const std::list<std::shared_ptr<Module>>& list, unsigned int flag);
151 
153  void reset();
154 
155 
156  private:
158  std::list<std::string> m_moduleSearchPathList;
159 
161  std::map<std::string, std::string> m_moduleNameLibMap;
162 
163  std::map<std::string, ModuleProxyBase*> m_registeredProxyMap;
164  std::list< std::shared_ptr<Module> > m_createdModulesList;
174  static void fillModuleNameLibMap(std::map<std::string, std::string>& moduleNameLibMap,
175  const boost::filesystem::directory_entry& mapPath);
176 
181 
186 
191 
197  };
198 
200 } //end of namespace Belle2
The ModuleManager Class.
Definition: ModuleManager.h:58
ModuleManager & operator=(const ModuleManager &)
Disable/Hide the copy assignment operator.
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 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).
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.
~ModuleManager()
The ModuleManager destructor.
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 void fillModuleNameLibMap(std::map< std::string, std::string > &moduleNameLibMap, const boost::filesystem::directory_entry &mapPath)
Adds the module names defined in the map file to the list of known module names.
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.