17 #include "libmesh/libmesh_common.h" 28 static Registry * registry_singleton =
nullptr;
29 if (!registry_singleton)
31 return *registry_singleton;
39 for (
const auto & label : labels)
41 r._known_labels.insert(label);
42 if (r._per_label_objects.count(label) == 0)
45 for (
const auto & obj : r._per_label_objects[label])
47 const auto name = obj->name();
48 r._name_to_entry[
name] = obj;
51 if (!obj->_alias.empty())
62 if (
const auto it = r._name_to_entry.find(
name); it != r._name_to_entry.end())
73 for (
const auto & label : labels)
75 r._known_labels.insert(label);
76 if (r._per_label_actions.count(label) == 0)
79 for (
const auto & obj : r._per_label_actions[label])
93 const std::string & in_tree_path,
95 const std::optional<std::string> &
info )
103 const std::string folder = std::filesystem::path(in_tree_path).filename().c_str();
104 if (folder !=
"data")
105 mooseError(
"While registering data file path '",
109 "': The folder must be named 'data' and it is named '",
118 const auto it = dfp.find(
name);
122 dfp.emplace(
name, path);
126 else if (it->second != path)
127 mooseError(
"While registering data file path '",
133 "' is already registered");
147 const auto dir = MooseUtils::splitFileName(app_path).first;
159 ":\nregisterDataFilePath() is deprecated. Use registerAppDataFilePath(\"",
169 const auto it = dfps.find(
name);
170 if (it == dfps.end())
171 mooseError(
"Registry::getDataFilePath(): A data file path for '",
name,
"' is not registered");
179 const auto [it, inserted] = repos.emplace(repo_name, repo_url);
180 if (!inserted && it->second != repo_url)
181 mooseError(
"Registry::registerRepository(): The repository '",
183 "' is already registered with a different URL '",
192 if (
const auto it = repos.find(repo_name); it != repos.end())
194 mooseError(
"Registry::getRepositoryURL(): The repository '", repo_name,
"' is not registered.");
207 const auto installed_path =
216 mooseError(
"Failed to determine data file path for '",
218 "'. Paths searched:\n\n installed: ",
234 if (std::regex_search(app_path, match, std::regex(
"\\/([a-zA-Z0-9_]+)App\\.C$")))
236 std::string
name = match[1];
237 name = std::regex_replace(
name, std::regex(
"(?!^)([A-Z])"),
"_$1");
243 "Registry::appNameFromAppPath(): Failed to parse application name from '", app_path,
"'");
249 if (!std::regex_search(
name, std::regex(
"[a-z0-9_]+")))
250 mooseError(
"Unallowed characters in data file path name '",
252 "'; allowed characters = a-z, 0-9, _");
257 const std::optional<std::string> & path ,
258 const std::optional<std::string> & extra_info )
260 std::string doc =
"Named data path '" +
name +
"' is ";
262 doc +=
"available at '" + *path +
"'";
264 doc +=
"not available";
266 doc +=
"; " + *extra_info;
270 capabilities.
add(
"data_" +
name,
bool(path), doc);
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.
static void addDataFilePath(const std::string &name, const std::string &in_tree_path, const bool app=true, const std::optional< std::string > &info={})
register general search paths; "app" is whether or not the path is an app path
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()
Gets the directory the running executable is on Mac OS X and linux.
static Capabilities & getCapabilities(const GetCapabilitiesPassKey)
Get the singleton Capabilities.
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)
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...
void reg(std::shared_ptr< RegistryEntryBase > obj)
static void addMissingDataFilePath(const std::string &name, const std::string &info)
register a data file path as missing, along with info about how it can be added
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
const std::string & name() const
Get the name of the class.
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...
static void addDataFilePathCapability(const std::string &name, const std::optional< std::string > &path={}, const std::optional< std::string > &extra_info={})
Add a data file path capability.
std::map< std::string, std::string > _data_file_paths
Data file registry; name -> in-tree path.
Capability & add(const std::string_view name, const Moose::Capability::Value &value, const std::string_view doc)
Add a capability.
std::string canonicalPath(const std::string &path)
Specialized factory for generic Action System objects.
static void checkDataFilePathName(const std::string &name)
Check a data file path for valid characters.
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::string toLower(std::string name)
Convert supplied string to lower case.
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
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
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.