Class Scine::Core::ModuleManager¶
-
class
ModuleManager
¶ The manager for all dynamically loaded modules.
This class is a singleton, in order to ensure that there is only ever one instance of this class controlling all modules loaded.
Use this class by requesting a reference to the single existing instance:
* const auto& manager = ModuleManager::getInstance() * if(manager.has<Calculator>("DFT")) { * auto calculator = manager.get<Calculator>("DFT"); * } *
Public Functions
-
ModuleManager
(ModuleManager const&)¶ Deleted copy constructor, as required by the singleton design pattern.
The constructor could also be private, however public deletion should generate more sensible error messages.
- Parameters
-
void
operator=
(ModuleManager const&)¶ Deleted assignment operator, as required by the singleton design pattern.
The assignment operator could also be private, however public deletion should generate more sensible error messages.
- Parameters
-
void
load
(const boost::filesystem::path &libraryPath)¶ Loads a library as a module.
Loads a shared library from a specified path and constructs the derived module class, adding it to the list of loaded modules.
- Parameters
libraryPath
: Either a full qualified path to the library, or merely the path to it and the name of the library without system-specific pre- and suffixes. E.g. “/usr/lib/libblas.so” or just “/usr/lib/blas”, both should work.
- Exceptions
std::runtime_error
: Under any of the following circumstances:The file is not found
There is not enough memory
The library does not provide the moduleFactory alias entry point to construct a module base class pointer
Loads a module from a shared_library instance.
- Parameters
library
: A shared_library instance that contains the symbol alias “moduleFactory” that is a nullary function yielding a shared_ptr<Module>
-
std::vector<std::string>
getLoadedModuleNames
() const¶ Get a list of all loaded Modules.
- Return
std::vector<std::string> Returns a vector of names corresponding to the Modules currently loaded.
-
template<typename
Interface
>
std::vector<std::string>getLoadedModels
() const¶ Announces a list of all loaded models of a particular interface.
- Return
A list of string-identifiers to the loaded models
- Template Parameters
Interface
: The interface class type (e.g. Calculator)
-
std::vector<std::string>
getLoadedModels
(const std::string &interface) const¶ Announces a list of all loaded models of a particular interface.
- Return
A list of string-identifiers to the loaded models
- Parameters
interface
: The string identifier of a particular interface
-
template<typename
Interface
>
boolhas
(const std::string &model, const std::string moduleName = "") const¶ Checks whether a particular model of an interface is available.
- Return
Whether the model is available. If so, get() should be safe to call.
- Template Parameters
Interface
: The interface class type (e.g. Calculator).
- Parameters
model
: The string identifier of a particular model.moduleName
: The string identifier of a particular module. If given, queries for the exact module-model combination. Module names will be auto expanded in addition to being tested literally: ‘XYZ’ will also query for ‘XYZModule’.
-
bool
has
(const std::string &interface, const std::string &model, const std::string moduleName = "") const¶ Checks whether a particular model of an interface is available.
- Return
Whether the model is available. If so, get() should be safe to call.
- Parameters
interface
: The string identifier of an interface class type.model
: The string identifier of a particular model.moduleName
: The string identifier of a particular module. If given, queries for the exact module-model combination. Module names will be auto expanded in addition to being tested literally: ‘XYZ’ will also query for ‘XYZModule’.
Creates a model of an interface and returns a base-class pointer.
Creates a derived class and yields a base-class pointer to it.
- Return
A base-class pointer to the class derived from the specified interface.
- Template Parameters
Interface
: The interface class type (e.g. Calculator)
- Parameters
model
: The string identifier of a particular model (e.g. DefaultCalculator)moduleName
: The string identifier of a particular module. If given, queries for the exact module-model combination. Module names will be auto expanded in addition to being tested literally: ‘XYZ’ will also query for ‘XYZModule’.
- Exceptions
std::runtime_error
: 1) If no loaded module provides that particular interface model. 2) If the requested module does not exist. 3) If the requested module does not provide the interface model.
-
bool
moduleLoaded
(const std::string &moduleName) const¶ Checks whether a particular module is loaded.
- Return
Whether the purported module is loaded
- Parameters
moduleName
: The self-reported name of the module
Public Static Functions
-
static ModuleManager &
getInstance
()¶ Static instance getter.
This static function assures the single instanciation of a ModuleManager for more information google the singleton design pattern.
- Return
Returns a reference to the ModuleManager instance.
-