ampsci
High-precision calculations for one- and two-valence atomic systems
Module::Registry

ok

Singleton registry of all compiled-in modules.

Populated at program startup via static initialisers – one per module .cpp file – and never modified once main() begins.

The "construct on first use" idiom in get() avoids the static-initialisation order fiasco: the Register constructor calls Registry::get(), which forces the singleton to be created before any module tries to register itself. Order of registration across translation units is unspecified, but for this registry that does not matter.

Module authors do not normally need to interact with the Registry directly; they self-register via Register. The ampsci driver uses the Registry via runModule, runModules and list_modules.

#include <Modules.hpp>

Public Member Functions

void add (std::string name, std::string description, ModuleFn fn)
 Append a new entry to the registry.
 
const std::vector< ModuleEntry > & entries () const
 All registered modules, in registration order.
 
const ModuleEntryfind (const std::string &name) const
 Look up a module by name.
 

Static Public Member Functions

static Registryget ()
 Access the singleton instance.
 

Member Function Documentation

◆ get()

static Registry & Module::Registry::get ( )
inlinestatic

Access the singleton instance.

Returns
Reference to the (only) Registry.

◆ add()

void Module::Registry::add ( std::string  name,
std::string  description,
ModuleFn  fn 
)
inline

Append a new entry to the registry.

Normally called only by the Register constructor.

Parameters
nameModule name as used in input files.
descriptionOne-line description (shown by ./ampsci -m).
fnPointer to the module function.

◆ entries()

const std::vector< ModuleEntry > & Module::Registry::entries ( ) const
inline

All registered modules, in registration order.

Returns
Const reference to the underlying vector of ModuleEntry.

◆ find()

const ModuleEntry * Module::Registry::find ( const std::string &  name) const
inline

Look up a module by name.

Parameters
nameModule name (case sensitive; same string passed to Register).
Returns
Pointer to the matching ModuleEntry, or nullptr if no module with that name is registered.

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