svMultiPhysics
Loading...
Searching...
No Matches
Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
IonicModelFactory Class Reference

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< IonicModelcreate_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 IonicModelFactoryget_instance ()
 Access the singleton instance.
 

Protected Attributes

std::map< std::string, std::function< std::unique_ptr< IonicModel >()> > children
 Registered ionic models.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ IonicModelFactory()

IonicModelFactory::IonicModelFactory ( )
protecteddefault

Default constructor.

Member Function Documentation

◆ create_model()

std::unique_ptr< IonicModel > IonicModelFactory::create_model ( const std::string &  name)
static

Instantiate a model from its name.

◆ get_instance()

static IonicModelFactory & IonicModelFactory::get_instance ( )
inlinestaticprotected

Access the singleton instance.

◆ register_model()

template<class Model >
static bool IonicModelFactory::register_model ( const std::string &  name)
inlinestatic

Register a child model.

◆ visit()

void IonicModelFactory::visit ( const std::function< void(const std::string &, const IonicModel &)> &  f)
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.

Member Data Documentation

◆ children

std::map<std::string, std::function<std::unique_ptr<IonicModel>()> > IonicModelFactory::children
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.


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