16 #include "libmesh/libmesh_common.h" 27 static Registry * registry_singleton =
nullptr;
28 if (!registry_singleton)
30 return *registry_singleton;
38 for (
const auto & label : labels)
40 r._known_labels.insert(label);
41 if (r._per_label_objects.count(label) == 0)
44 for (
const auto & obj : r._per_label_objects[label])
46 const auto name = obj->name();
47 r._name_to_entry[
name] = obj;
50 if (!obj->_alias.empty())
61 if (
const auto it = r._name_to_entry.find(
name); it != r._name_to_entry.end())
72 for (
const auto & label : labels)
74 r._known_labels.insert(label);
75 if (r._per_label_actions.count(label) == 0)
78 for (
const auto & obj : r._per_label_actions[label])
93 if (!std::regex_search(
name, std::regex(
"\\w+")))
98 const std::string folder = std::filesystem::path(in_tree_path).filename().c_str();
100 mooseError(
"While registering data file path '",
104 "': The folder must be named 'data' and it is named '",
112 const auto it = dfp.find(
name);
115 dfp.emplace(
name, path);
117 else if (it->second != path)
118 mooseError(
"While registering data file path '",
124 "' is already registered");
143 ":\nregisterDataFilePath() is deprecated. Use registerAppDataFilePath(\"",
153 const auto it = dfps.find(
name);
154 if (it == dfps.end())
155 mooseError(
"Registry::getDataFilePath(): A data file path for '",
name,
"' is not registered");
163 const auto [it, inserted] = repos.emplace(repo_name, repo_url);
164 if (!inserted && it->second != repo_url)
165 mooseError(
"Registry::registerRepository(): The repository '",
167 "' is already registered with a different URL '",
176 if (
const auto it = repos.find(repo_name); it != repos.end())
178 mooseError(
"Registry::getRepositoryURL(): The repository '", repo_name,
"' is not registered.");
191 const auto installed_path =
200 mooseError(
"Failed to determine data file path for '",
202 "'. Paths searched:\n\n installed: ",
218 if (std::regex_search(app_path, match, std::regex(
"\\/([a-zA-Z0-9_]+)App\\.C$")))
220 std::string
name = match[1];
221 name = std::regex_replace(
name, std::regex(
"(?!^)([A-Z])"),
"_$1");
227 "Registry::appNameFromAppPath(): Failed to parse application name from '", app_path,
"'");
static std::string appNameFromAppPath(const std::string &app_path)
Internal helper for getting an application name from its path, for example: /path/to/FooBarBazApp.C -> foo_bar_baz, for use in addDeprecatedAppDataFilePath.
static const RegistryEntryBase & objData(const std::string &name)
static Registry & getRegistry()
Get the global Registry singleton.
std::string toLower(const std::string &name)
Convert supplied string to lower case.
Generic factory class for build all sorts of objects.
static std::string getDataFilePath(const std::string &name)
Gets a data path for the registered name.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static void addAppDataFilePath(const std::string &app_name, const std::string &app_path)
register search paths for an application (path determined relative to app_path); app_path should be p...
std::string getExecutablePath()
This function returns the PATH of the running executable.
static std::string determineDataFilePath(const std::string &name, const std::string &in_tree_path)
Internal helper for determing a root data file path (in-tree vs installed)
void reg(std::shared_ptr< RegistryEntryBase > obj)
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
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...
virtual const std::string & name() const
Get the name of the class.
void reg(std::shared_ptr< RegistryEntryBase > obj)
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
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...
std::map< std::string, std::string > _data_file_paths
Data file registry; name -> in-tree path.
std::string canonicalPath(const std::string &path)
Gets the canonical path of the given path.
Specialized factory for generic Action System objects.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
static void addRepository(const std::string &repo_name, const std::string &repo_url)
register a repository
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
std::set< std::string > _known_labels
std::filesystem::path pathjoin(const std::filesystem::path &p)
std::map< std::string, std::string > _repos
Repository name -> repository URL; used for mooseDocumentedError.
static const std::string & getRepositoryURL(const std::string &repo_name)
Returns the repository URL associated with repo_name.
static void addDeprecatedAppDataFilePath(const std::string &app_path)
deprecated method; use addAppDataFilePath instead
The registry is used as a global singleton to collect information on all available MooseObject and Ac...
static char addKnownLabel(const std::string &label)
addKnownLabel whitelists a label as valid for purposes of the checkLabels function.
static void addDataFilePath(const std::string &name, const std::string &in_tree_path)
register general search paths (folder name must be data)