Belle II Software light-2406-ragdoll
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.
 
static CreatorBasegetCreator (const std::string &name, const std::string &library="")
 Return a new instance of a creator with the given name.
 

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 Typedef Documentation

◆ CreatorFactory

Typedef for a factory function.

Definition at line 27 of file CreatorManager.h.

Constructor & Destructor Documentation

◆ CreatorManager()

CreatorManager ( )
inlineprotected

singleton, hide constructor

Definition at line 55 of file CreatorManager.h.

55{}

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

◆ getInstance()

CreatorManager & getInstance ( )
staticprotected

getter for the singleton instance

Definition at line 18 of file CreatorManager.cc.

19{
20 static unique_ptr<CreatorManager> instance(new CreatorManager());
21 return *instance;
22}
CreatorManager()
singleton, hide constructor

◆ 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.

27{
28 getInstance().m_creatorFactories[name] = factory;
29}

Member Data Documentation

◆ m_creatorFactories

std::map<std::string, CreatorFactory*> m_creatorFactories
protected

Static map to hold all registered factories.

Definition at line 63 of file CreatorManager.h.


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