www.mooseframework.org
Static Public Member Functions | 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>

Public Member Functions

 Registry (Registry const &)=delete
 Don't allow creation through copy/move construction or assignment. More...
 
Registryoperator= (Registry const &)=delete
 
 Registry (Registry &&)=delete
 
Registryoperator= (Registry &&)=delete
 

Static Public Member Functions

static RegistrygetRegistry ()
 Get the global Registry singleton. More...
 
template<typename T >
static char add (const RegistryEntryData &base_info)
 Adds information on a MooseObject to the registry. More...
 
template<typename T >
static char addAction (const RegistryEntryData &base_info)
 Adds information on an Action object to the registry. More...
 
template<typename T >
static std::string getClassName ()
 
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 char addKnownLabel (const std::string &label)
 addKnownLabel whitelists a label as valid for purposes of the checkLabels function. More...
 
static void addDataFilePath (const std::string &path)
 register search paths for built-in data files More...
 
static void addRepository (const std::string &repo_name, const std::string &repo_url)
 register a repository More...
 
static const std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > & allObjects ()
 Returns a per-label keyed map of all MooseObjects in the registry. More...
 
static const std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > & allActions ()
 Returns a per-label keyed map of all Actions in the registry. More...
 
static const RegistryEntryBaseobjData (const std::string &name)
 
static bool isRegisteredObj (const std::string &name)
 
static const std::vector< std::string > & getDataFilePaths ()
 Returns a vector of all registered data file paths. More...
 
static const std::string & getRepositoryURL (const std::string &repo_name)
 Returns the repository URL associated with repo_name. More...
 
template<typename T >
static std::string getRegisteredName ()
 returns the name() for a registered class More...
 

Private Member Functions

 Registry ()
 

Private Attributes

std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_entry
 
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_objects
 
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_actions
 
std::set< std::string > _known_labels
 
std::vector< std::string > _data_file_paths
 
std::map< std::string, std::string > _repos
 Repository name -> repository URL; used for mooseDocumentedError. More...
 
std::map< std::string, std::string > _type_to_classname
 

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 153 of file Registry.h.

Constructor & Destructor Documentation

◆ Registry() [1/3]

Registry::Registry ( Registry const &  )
delete

Don't allow creation through copy/move construction or assignment.

◆ Registry() [2/3]

Registry::Registry ( Registry &&  )
delete

◆ Registry() [3/3]

Registry::Registry ( )
inlineprivate

Definition at line 251 of file Registry.h.

Referenced by getRegistry().

251 {};

Member Function Documentation

◆ add()

template<typename T >
static char Registry::add ( const RegistryEntryData base_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 165 of file Registry.h.

166  {
167  const auto info = std::make_shared<RegistryEntry<T>>(base_info);
168  getRegistry()._per_label_objects[info->_label].push_back(info);
169  getRegistry()._type_to_classname[typeid(T).name()] = info->name();
170  return 0;
171  }
std::string name(const ElemQuality q)
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
MPI_Info info
std::map< std::string, std::string > _type_to_classname
Definition: Registry.h:260
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_objects
Definition: Registry.h:254

◆ addAction()

template<typename T >
static char Registry::addAction ( const RegistryEntryData base_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 177 of file Registry.h.

178  {
179  const auto info = std::make_shared<RegistryEntry<T>>(base_info);
180  getRegistry()._per_label_actions[info->_label].push_back(info);
181  getRegistry()._type_to_classname[typeid(T).name()] = info->_classname;
182  return 0;
183  }
std::string name(const ElemQuality q)
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_actions
Definition: Registry.h:255
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
MPI_Info info
std::map< std::string, std::string > _type_to_classname
Definition: Registry.h:260

◆ addDataFilePath()

void Registry::addDataFilePath ( const std::string &  path)
static

register search paths for built-in data files

Definition at line 89 of file Registry.C.

90 {
91  auto & dfp = getRegistry()._data_file_paths;
92 
93  // split the *App.C filename from its containing directory
94  const auto path = MooseUtils::splitFileName(fullpath).first;
95 
96  // This works for both build/unity_src/ and src/base/ as the *App.C file location,
97  // in case __FILE__ doesn't get overriden in unity build
98  const auto data_dir = MooseUtils::pathjoin(path, "../../data");
99 
100  // if the data directory exists and hasn't been added before, add it
101  if (MooseUtils::pathIsDirectory(data_dir) &&
102  std::find(dfp.begin(), dfp.end(), data_dir) == dfp.end())
103  dfp.push_back(data_dir);
104 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
bool pathIsDirectory(const std::string &path)
Definition: MooseUtils.C:247
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
Definition: MooseUtils.h:231
std::vector< std::string > _data_file_paths
Definition: Registry.h:257
std::filesystem::path pathjoin(const std::filesystem::path &p)
Definition: MooseUtils.C:58

◆ addKnownLabel()

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

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

Definition at line 82 of file Registry.C.

Referenced by MooseApp::MooseApp().

83 {
84  getRegistry()._known_labels.insert(label);
85  return 0;
86 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
std::set< std::string > _known_labels
Definition: Registry.h:256

◆ addRepository()

void Registry::addRepository ( const std::string &  repo_name,
const std::string &  repo_url 
)
static

register a repository

Definition at line 107 of file Registry.C.

108 {
109  auto & repos = getRegistry()._repos;
110  const auto [it, inserted] = repos.emplace(repo_name, repo_url);
111  if (!inserted && it->second != repo_url)
112  mooseError("Registry::registerRepository(): The repository '",
113  repo_name,
114  "' is already registered with a different URL '",
115  it->second,
116  "'.");
117 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::map< std::string, std::string > _repos
Repository name -> repository URL; used for mooseDocumentedError.
Definition: Registry.h:259

◆ allActions()

static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase> > >& Registry::allActions ( )
inlinestatic

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

Definition at line 214 of file Registry.h.

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

215  {
217  }
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_actions
Definition: Registry.h:255
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21

◆ allObjects()

static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase> > >& Registry::allObjects ( )
inlinestatic

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

Definition at line 209 of file Registry.h.

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

210  {
212  }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_objects
Definition: Registry.h:254

◆ getClassName()

template<typename T >
static std::string Registry::getClassName ( )
inlinestatic

Definition at line 186 of file Registry.h.

187  {
188  return libmesh_map_find(getRegistry()._type_to_classname, typeid(T).name());
189  }
std::string name(const ElemQuality q)
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
std::map< std::string, std::string > _type_to_classname
Definition: Registry.h:260

◆ getDataFilePaths()

static const std::vector<std::string>& Registry::getDataFilePaths ( )
inlinestatic

Returns a vector of all registered data file paths.

Definition at line 230 of file Registry.h.

231  {
232  return getRegistry()._data_file_paths;
233  }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
std::vector< std::string > _data_file_paths
Definition: Registry.h:257

◆ getRegisteredName()

template<typename T >
std::string Registry::getRegisteredName ( )
static

returns the name() for a registered class

Definition at line 265 of file Registry.h.

266 {
267  mooseDeprecated("Use Registry::getClassName() instead.");
268  return getClassName<T>();
269 }
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:350

◆ getRegistry()

Registry & Registry::getRegistry ( )
static

Get the global Registry singleton.

Definition at line 21 of file Registry.C.

Referenced by add(), addAction(), addDataFilePath(), addKnownLabel(), addRepository(), allActions(), allObjects(), getClassName(), DataFileInterface< Action >::getDataFileNameByName(), getDataFilePaths(), getRepositoryURL(), isRegisteredObj(), objData(), registerActionsTo(), and registerObjectsTo().

22 {
23  // We need a naked new here (_not_ a smart pointer or object instance) due to what seems like a
24  // bug in clang's static object destruction when using dynamic library loading.
25  static Registry * registry_singleton = nullptr;
26  if (!registry_singleton)
27  registry_singleton = new Registry();
28  return *registry_singleton;
29 }
Registry()
Definition: Registry.h:251
The registry is used as a global singleton to collect information on all available MooseObject and Ac...
Definition: Registry.h:153

◆ getRepositoryURL()

const std::string & Registry::getRepositoryURL ( const std::string &  repo_name)
static

Returns the repository URL associated with repo_name.

Definition at line 120 of file Registry.C.

Referenced by moose::internal::formatMooseDocumentedError().

121 {
122  const auto & repos = getRegistry()._repos;
123  if (const auto it = repos.find(repo_name); it != repos.end())
124  return it->second;
125  mooseError("Registry::getRepositoryURL(): The repository '", repo_name, "' is not registered.");
126 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::map< std::string, std::string > _repos
Repository name -> repository URL; used for mooseDocumentedError.
Definition: Registry.h:259

◆ isRegisteredObj()

static bool Registry::isRegisteredObj ( const std::string &  name)
inlinestatic
Returns
true if an object with the given name is registered

Definition at line 224 of file Registry.h.

Referenced by MooseObject::MooseObject().

225  {
226  return getRegistry()._name_to_entry.count(name);
227  }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_entry
Definition: Registry.h:251

◆ objData()

const RegistryEntryBase & Registry::objData ( const std::string &  name)
static

Definition at line 55 of file Registry.C.

56 {
57  auto & r = getRegistry();
58 
59  if (const auto it = r._name_to_entry.find(name); it != r._name_to_entry.end())
60  return *it->second;
61  else
62  mooseError("Object ", name, " is not registered yet");
63 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299

◆ operator=() [1/2]

Registry& Registry::operator= ( Registry const &  )
delete

◆ operator=() [2/2]

Registry& Registry::operator= ( Registry &&  )
delete

◆ 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 66 of file Registry.C.

Referenced by Moose::registerActions().

67 {
68  auto & r = getRegistry();
69 
70  for (const auto & label : labels)
71  {
72  r._known_labels.insert(label);
73  if (r._per_label_actions.count(label) == 0)
74  continue;
75 
76  for (const auto & obj : r._per_label_actions[label])
77  f.reg(obj);
78  }
79 }
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
void reg(std::shared_ptr< RegistryEntryBase > obj)
Definition: ActionFactory.C:21

◆ 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 32 of file Registry.C.

Referenced by Moose::registerObjects().

33 {
34  auto & r = getRegistry();
35 
36  for (const auto & label : labels)
37  {
38  r._known_labels.insert(label);
39  if (r._per_label_objects.count(label) == 0)
40  continue;
41 
42  for (const auto & obj : r._per_label_objects[label])
43  {
44  const auto name = obj->name();
45  r._name_to_entry[name] = obj;
46 
47  f.reg(obj);
48  if (!obj->_alias.empty())
49  f.associateNameToClass(name, obj->_classname);
50  }
51  }
52 }
std::string name(const ElemQuality q)
static Registry & getRegistry()
Get the global Registry singleton.
Definition: Registry.C:21
void reg(std::shared_ptr< RegistryEntryBase > obj)
Definition: Factory.C:22
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
Definition: Factory.C:265

Member Data Documentation

◆ _data_file_paths

std::vector<std::string> Registry::_data_file_paths
private

Definition at line 257 of file Registry.h.

Referenced by addDataFilePath(), and getDataFilePaths().

◆ _known_labels

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

Definition at line 256 of file Registry.h.

Referenced by addKnownLabel().

◆ _name_to_entry

std::map<std::string, std::shared_ptr<RegistryEntryBase> > Registry::_name_to_entry
private

Definition at line 251 of file Registry.h.

Referenced by isRegisteredObj().

◆ _per_label_actions

std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase> > > Registry::_per_label_actions
private

Definition at line 255 of file Registry.h.

Referenced by addAction(), and allActions().

◆ _per_label_objects

std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase> > > Registry::_per_label_objects
private

Definition at line 254 of file Registry.h.

Referenced by add(), and allObjects().

◆ _repos

std::map<std::string, std::string> Registry::_repos
private

Repository name -> repository URL; used for mooseDocumentedError.

Definition at line 259 of file Registry.h.

Referenced by addRepository(), and getRepositoryURL().

◆ _type_to_classname

std::map<std::string, std::string> Registry::_type_to_classname
private

Definition at line 260 of file Registry.h.

Referenced by add(), addAction(), and getClassName().


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