Belle II Software  release-08-01-10
CreatorManager Class Reference

Class to manage all creators and provide factory access. More...

#include <CreatorManager.h>

Collaboration diagram for CreatorManager:

Public Types

typedef CreatorBaseCreatorFactory()
 Typedef for a factory function.
 

Static Public Member Functions

static void registerCreatorFactory (const std::string &name, CreatorFactory *factory)
 Register a new creator by providing a name and a pointer to a factory for this kind of creator. More...
 
static CreatorBasegetCreator (const std::string &name, const std::string &library="")
 Return a new instance of a creator with the given name. More...
 

Protected Member Functions

 CreatorManager ()
 singleton, hide constructor
 
 CreatorManager (const CreatorManager &)=delete
 singleton, hide copy constructor
 
void operator= (const CreatorManager &)=delete
 singleton, hide assignment operator
 

Static Protected Member Functions

static CreatorManagergetInstance ()
 getter for the singleton instance
 

Protected Attributes

std::map< std::string, CreatorFactory * > m_creatorFactories
 Static map to hold all registered factories.
 

Detailed Description

Class to manage all creators and provide factory access.

Definition at line 24 of file CreatorManager.h.

Member Function Documentation

◆ getCreator()

CreatorBase * getCreator ( const std::string &  name,
const std::string &  library = "" 
)
static

Return a new instance of a creator with the given name.

If library is not empty, the specified library will be loaded before attempting to create the creator to allow for on-demand loading of libraries.

Returns 0 if no creator with the given name is registered. Ownership of the creator is transferred to the caller who is responsible of freeing the creator.

Parameters
nameName of the Creator to be created
libraryShort name of the library which should be loaded before trying to create the creator. When library is "foo", libfoo.so will be loaded

Definition at line 31 of file CreatorManager.cc.

32 {
33  if (!library.empty()) {
34  FileSystem::loadLibrary(library, false);
35  }
36 
37  CreatorManager& instance = getInstance();
38  auto it = instance.m_creatorFactories.find(name);
39  if (it == instance.m_creatorFactories.end()) {
40  B2ERROR("Could not find a geometry creator named " << name);
41  return nullptr;
42  }
43  return it->second();
44 }
static bool loadLibrary(std::string library, bool fullname=true)
Load a shared library.
Definition: FileSystem.cc:63
Class to manage all creators and provide factory access.
std::map< std::string, CreatorFactory * > m_creatorFactories
Static map to hold all registered factories.
static CreatorManager & getInstance()
getter for the singleton instance

◆ registerCreatorFactory()

void registerCreatorFactory ( const std::string &  name,
CreatorFactory factory 
)
static

Register a new creator by providing a name and a pointer to a factory for this kind of creator.

Parameters
nameName of the creator to be registered
factoryPointer to a function returning new instances of the creator

Definition at line 26 of file CreatorManager.cc.


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