|
svMultiPhysics
|
Self-registering factory for ionic models. More...
#include <ionic_model.h>
Static Public Member Functions | |
| template<class Model > | |
| static bool | register_model (const std::string &name) |
| Register a child model. | |
| static std::unique_ptr< IonicModel > | create_model (const std::string &name) |
| Instantiate a model from its name. | |
| static void | visit (const std::function< void(const std::string &, const IonicModel &)> &f) |
| Iterate through registered ionic models. | |
Protected Member Functions | |
| IonicModelFactory ()=default | |
| Default constructor. | |
Static Protected Member Functions | |
| static IonicModelFactory & | get_instance () |
| Access the singleton instance. | |
Protected Attributes | |
| std::map< std::string, std::function< std::unique_ptr< IonicModel >()> > | children |
| Registered ionic models. | |
Self-registering factory for ionic models.
This class gives a way to register ionic models when they are defined, and then instantiate concrete ionic models, derived from IonicModel, by name. To be compatible with this factory, classes derived from IonicModel must be default constructible.
It combines the factory and singleton patterns. There should always exist only one instance of this class, which cannot be accessed directly but only manipulated through the static methods of this class.
To register a new ionic model into the factory, you can call the register_model static method, passing a class derived from Ionic as template argument and a label for the model as argument. A shortcut for this is to use the macro REGISTER_IONIC_MODEL.
|
protecteddefault |
Default constructor.
|
static |
Instantiate a model from its name.
|
inlinestaticprotected |
Access the singleton instance.
|
inlinestatic |
Register a child model.
|
static |
Iterate through registered ionic models.
For every registered ionic model, creates a dummy instance of it, and then calls the provided function on that model. All the dummy model instances are destroyed after the function call.
|
protected |
Registered ionic models.
Each ionic model is represented by a function that takes no argument and returns a unique_ptr<IonicModel> constructing an instance of that model. This requires classes derived from IonicModel to be default constructible.