www.mooseframework.org
Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
Registry Class Reference

The registry is used as a global singleton to collect information on all available MooseObject and Action classes for use in a moose app/simulation. More...

#include <Registry.h>

Static Public Member Functions

template<typename T >
static char add (const RegistryEntry &info)
 Adds information on a MooseObject to the registry. More...
 
template<typename T >
static char addAction (const RegistryEntry &info)
 Adds information on an Action object to the registry. More...
 
static void registerObjectsTo (Factory &f, const std::set< std::string > &labels)
 This registers all MooseObjects known to the registry that have the given label(s) with the factory f. More...
 
static void registerActionsTo (ActionFactory &f, const std::set< std::string > &labels)
 This registers all Actions known to the registry that have the given label(s) with the factory f. More...
 
static void checkLabels (const std::set< std::string > &known_labels={})
 This runs error checking to make sure that all objects and actions in the registry have valid labels. More...
 
static char addKnownLabel (const std::string &label)
 addKnownLabel whitelists a label as valid for purposes of the checkLabels function. More...
 
static const std::map< std::string, std::vector< RegistryEntry > > & allObjects ()
 Returns a per-label keyed map of all MooseObjects in the registry. More...
 
static const std::map< std::string, std::vector< RegistryEntry > > & allActions ()
 Returns a per-label keyed map of all Actions in the registry. More...
 

Static Private Member Functions

static void addInner (const RegistryEntry &info)
 
static void addActionInner (const RegistryEntry &info)
 

Private Attributes

std::map< std::string, std::vector< RegistryEntry > > _per_label_objects
 
std::map< std::string, std::vector< RegistryEntry > > _per_label_actions
 
std::set< std::string > _known_labels
 

Detailed Description

The registry is used as a global singleton to collect information on all available MooseObject and Action classes for use in a moose app/simulation.

It must be global because we want+need to be able to register objects in global scope during static initialization time before other parts of the moose app execution have started running. This allows us to distribute registration across all the files that define the actual classes being registered so we don't have to have any central location with a bajillion includes that makes (especially incremental) compiles slow. The registry collects the app, name, and other information for each objects and makes it available to the moose object and action factories and others for general use. All public functions in this class modify and return data from the global singleton.

Definition at line 180 of file Registry.h.

Member Function Documentation

◆ add()

template<typename T >
static char Registry::add ( const RegistryEntry info)
inlinestatic

Adds information on a MooseObject to the registry.

The _build_ptr, _build_action_ptr, and _params_ptr objects of the info object should all be nullptr - these are set automatically by the add function itself using the templated type T.

Definition at line 187 of file Registry.h.

188  {
189  RegistryEntry copy = info;
190  copy._build_ptr = &buildObj<T>;
191  copy._params_ptr = &validParams<T>;
192  addInner(copy);
193  return 0;
194  }
buildPtr _build_ptr
function pointer for building instances of the MooseObject (if the entry is for an object)...
Definition: Registry.h:142
paramsPtr _params_ptr
function pointer for building InputParameters objects for the object or action.
Definition: Registry.h:146
static void addInner(const RegistryEntry &info)
Definition: Registry.C:38
Holds details and meta-data info for a particular MooseObject or Action for use in the registry...
Definition: Registry.h:130

◆ addAction()

template<typename T >
static char Registry::addAction ( const RegistryEntry info)
inlinestatic

Adds information on an Action object to the registry.

The _build_ptr, _build_action_ptr, and _params_ptr objects of the info object should all be nullptr - these are set automatically by the addAction function itself using the templated type T.

Definition at line 200 of file Registry.h.

201  {
202  RegistryEntry copy = info;
203  copy._build_action_ptr = &buildAct<T>;
204  copy._params_ptr = &validParams<T>;
205  addActionInner(copy);
206  return 0;
207  }
buildActionPtr _build_action_ptr
function pointer for building instances of the Action (if the entry is for an action).
Definition: Registry.h:144
paramsPtr _params_ptr
function pointer for building InputParameters objects for the object or action.
Definition: Registry.h:146
static void addActionInner(const RegistryEntry &info)
Definition: Registry.C:45
Holds details and meta-data info for a particular MooseObject or Action for use in the registry...
Definition: Registry.h:130

◆ addActionInner()

void Registry::addActionInner ( const RegistryEntry info)
staticprivate

Definition at line 45 of file Registry.C.

Referenced by addAction().

46 {
47  auto & r = getRegistry();
48  r._per_label_actions[info._label].push_back(info);
49 }
static Registry & getRegistry()
Definition: Registry.C:18
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with...
Definition: Registry.h:133

◆ addInner()

void Registry::addInner ( const RegistryEntry info)
staticprivate

Definition at line 38 of file Registry.C.

Referenced by add().

39 {
40  auto & r = getRegistry();
41  r._per_label_objects[info._label].push_back(info);
42 }
static Registry & getRegistry()
Definition: Registry.C:18
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with...
Definition: Registry.h:133

◆ addKnownLabel()

char Registry::addKnownLabel ( const std::string &  label)
static

addKnownLabel whitelists a label as valid for purposes of the checkLabels function.

Definition at line 124 of file Registry.C.

Referenced by MooseApp::MooseApp().

125 {
126  auto & r = getRegistry();
127  r._known_labels.insert(label);
128  return 0;
129 }
static Registry & getRegistry()
Definition: Registry.C:18

◆ allActions()

const std::map< std::string, std::vector< RegistryEntry > > & Registry::allActions ( )
static

Returns a per-label keyed map of all Actions in the registry.

Definition at line 32 of file Registry.C.

Referenced by JsonSyntaxTree::JsonSyntaxTree(), and MooseApp::setupOptions().

33 {
35 }
std::map< std::string, std::vector< RegistryEntry > > _per_label_actions
Definition: Registry.h:236
static Registry & getRegistry()
Definition: Registry.C:18

◆ allObjects()

const std::map< std::string, std::vector< RegistryEntry > > & Registry::allObjects ( )
static

Returns a per-label keyed map of all MooseObjects in the registry.

Definition at line 27 of file Registry.C.

Referenced by JsonSyntaxTree::JsonSyntaxTree(), and MooseApp::setupOptions().

28 {
30 }
std::map< std::string, std::vector< RegistryEntry > > _per_label_objects
Definition: Registry.h:235
static Registry & getRegistry()
Definition: Registry.C:18

◆ checkLabels()

void Registry::checkLabels ( const std::set< std::string > &  known_labels = {})
static

This runs error checking to make sure that all objects and actions in the registry have valid labels.

Labels are considered valid if they have been added to the list of known labels via the addKnownLabel function or they have been used to register objects to a factory via registerObjectsTo or registerActionsTo.

Definition at line 101 of file Registry.C.

Referenced by MooseApp::checkRegistryLabels().

102 {
103  auto & r = getRegistry();
104  std::vector<RegistryEntry> orphs;
105 
106  for (auto & entry : r._per_label_objects)
107  if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0)
108  orphs.insert(orphs.end(), entry.second.begin(), entry.second.end());
109  for (auto & entry : r._per_label_actions)
110  if (known_labels.count(entry.first) == 0 && r._known_labels.count(entry.first) == 0)
111  orphs.insert(orphs.end(), entry.second.begin(), entry.second.end());
112 
113  if (orphs.size() > 0)
114  {
115  std::stringstream lst;
116  for (auto & orph : orphs)
117  lst << "\n\t" << orph._classname << " (app='" << orph._label << "')";
118  mooseError("The following objects/actions have been registered to unknown applications/labels:",
119  lst.str());
120  }
121 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
static Registry & getRegistry()
Definition: Registry.C:18

◆ registerActionsTo()

void Registry::registerActionsTo ( ActionFactory f,
const std::set< std::string > &  labels 
)
static

This registers all Actions known to the registry that have the given label(s) with the factory f.

Definition at line 85 of file Registry.C.

Referenced by Moose::registerActions().

86 {
87  auto & r = getRegistry();
88  for (const auto & label : labels)
89  {
90  r._known_labels.insert(label);
91  if (r._per_label_actions.count(label) == 0)
92  continue;
93 
94  for (const auto & obj : r._per_label_actions[label])
95  f.reg(
96  obj._classname, obj._name, obj._build_action_ptr, obj._params_ptr, obj._file, obj._line);
97  }
98 }
void reg(const std::string &name, const std::string &task, const std::string &file="", int line=-1)
Definition: ActionFactory.h:75
static Registry & getRegistry()
Definition: Registry.C:18

◆ registerObjectsTo()

void Registry::registerObjectsTo ( Factory f,
const std::set< std::string > &  labels 
)
static

This registers all MooseObjects known to the registry that have the given label(s) with the factory f.

Definition at line 52 of file Registry.C.

Referenced by Moose::registerObjects().

53 {
54  auto & r = getRegistry();
55  for (const auto & label : labels)
56  {
57  r._known_labels.insert(label);
58  if (r._per_label_objects.count(label) == 0)
59  continue;
60 
61  for (const auto & obj : r._per_label_objects[label])
62  {
63  std::string name = obj._name;
64  if (name.empty())
65  name = obj._alias;
66  if (name.empty())
67  name = obj._classname;
68 
69  f.reg(obj._label,
70  name,
71  obj._build_ptr,
72  obj._params_ptr,
73  obj._deprecated_time,
74  obj._replaced_by,
75  obj._file,
76  obj._line);
77 
78  if (!obj._alias.empty())
79  f.associateNameToClass(name, obj._classname);
80  }
81  }
82 }
if(nl->nonlinearSolver() ->matvec &&nl->nonlinearSolver() ->residual_and_jacobian_object)
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
Definition: Factory.C:292
void reg(const std::string &obj_name, const std::string &file="", int line=-1)
Register a new object.
Definition: Factory.h:165
static Registry & getRegistry()
Definition: Registry.C:18

Member Data Documentation

◆ _known_labels

std::set<std::string> Registry::_known_labels
private

Definition at line 237 of file Registry.h.

◆ _per_label_actions

std::map<std::string, std::vector<RegistryEntry> > Registry::_per_label_actions
private

Definition at line 236 of file Registry.h.

Referenced by allActions().

◆ _per_label_objects

std::map<std::string, std::vector<RegistryEntry> > Registry::_per_label_objects
private

Definition at line 235 of file Registry.h.

Referenced by allObjects().


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