21#include "libmesh/utility.h"
24#include <gtest/gtest.h>
27#define combineNames1(X, Y) X##Y
28#define combineNames(X, Y) combineNames1(X, Y)
34#define registerKnownLabel(X) \
35 [[maybe_unused]] static char combineNames(dummy_var_for_known_label, __COUNTER__) = \
36 Registry::addKnownLabel(X)
40#define registerMooseAction(app, classname, task) \
41 [[maybe_unused]] static char combineNames(dummyvar_for_registering_action_##classname, \
43 Registry::addAction<classname>({app, #classname, "", task, __FILE__, __LINE__, "", ""})
47#define registerMooseObject(app, classname) \
48 [[maybe_unused]] static char combineNames(dummyvar_for_registering_obj_##classname, \
50 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, "", ""})
52#define registerADMooseObject(app, classname) registerMooseObject(app, classname)
56#define registerMooseObjectAliased(app, classname, alias) \
57 [[maybe_unused]] static char combineNames(dummyvar_for_registering_obj_##classname, \
59 Registry::add<classname>({app, #classname, alias, "", __FILE__, __LINE__, "", ""})
63#define registerMooseObjectDeprecated(app, classname, time) \
64 [[maybe_unused]] static char combineNames(dummyvar_for_registering_obj_##classname, \
66 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, ""})
68#define registerADMooseObjectDeprecated(app, classname, time) \
69 registerMooseObjectDeprecated(app, classname, time)
73#define registerMooseObjectReplaced(app, classname, time, replacement) \
74 [[maybe_unused]] static char combineNames(dummyvar_for_registering_obj_##classname, \
76 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, #replacement})
82#define registerMooseObjectRenamed(app, orig_class, time, new_class) \
83 [[maybe_unused]] static char combineNames(dummyvar_for_registering_obj_##orig_class, \
85 Registry::add<new_class>( \
86 {app, #new_class, #orig_class, #orig_class, __FILE__, __LINE__, time, #new_class})
88#define registerADMooseObjectRenamed(app, orig_class, time, new_class) \
89 registerMooseObjectRenamed(app, orig_class, time, new_class)
92#define registerNonAppDataFilePath(name, path) Registry::addDataFilePath(name, path, false)
94#define registerNonAppDataFilePathWithInfo(name, path, info) \
95 Registry::addDataFilePath(name, path, false, info)
99#define registerAppDataFilePath(app) Registry::addAppDataFilePath(app, __FILE__)
101#define registerMissingDataFilePath(name, info) Registry::addMissingDataFilePath(name, info)
103#define registerDataFilePath() Registry::addDeprecatedAppDataFilePath(__FILE__)
105#define registerRepository(repo_name, repo_url) Registry::addRepository(repo_name, repo_url);
189 template <
typename T>
192 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
201 template <
typename T>
204 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
210 template <
typename T>
229 const std::string & in_tree_path,
230 const bool app =
true,
231 const std::optional<std::string> & info = {});
234 static void addAppDataFilePath(
const std::string & app_name,
const std::string & app_path);
241 static void addRepository(
const std::string & repo_name,
const std::string & repo_url);
247 addAppCitation(
const std::string & app_name,
const std::string & key,
const std::string & bibtex);
250 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allObjects()
255 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allActions()
291 static const std::map<std::string, std::map<std::string, std::string>> &
getCitations()
299 static const std::map<std::string, std::string> &
getCitations(
const std::string & app_name);
302 template <
typename T>
314#ifdef MOOSE_UNIT_TEST
343 static void setRepos(
const std::map<std::string, std::string> & repos)
350 const std::string & in_tree_path);
361 const std::optional<std::string> & path = {},
362 const std::optional<std::string> & extra_info = {});
371 std::map<std::string, std::string>
_repos;
382 return getClassName<T>();
388 static_assert(std::is_base_of_v<MooseObject, T> || std::is_base_of_v<Action, T>,
389 "Not derived from MooseObject or Action");
393std::unique_ptr<MooseObject>
396 if constexpr (std::is_base_of_v<MooseObject, T>)
397 return std::make_unique<T>(parameters);
398 mooseError(MooseUtils::prettyCppType<T>(),
" to be built is not a MooseObject.");
401std::shared_ptr<MooseObject>
404 if constexpr (std::is_base_of_v<MooseObject, T>)
405 return std::make_shared<T>(parameters);
406 mooseError(MooseUtils::prettyCppType<T>(),
" to be built is not a MooseObject.");
410std::shared_ptr<Action>
413 if constexpr (!std::is_base_of_v<Action, T>)
414 mooseError(
"The action to be built is not derived from Action.");
416 return std::make_shared<T>(parameters);
423 auto params = T::validParams();
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Specialized factory for generic Action System objects.
Generic factory class for build all sorts of objects.
Every object that can be built by the factory should be derived from this class.
The registry is used as a global singleton to collect information on all available MooseObject and Ac...
Registry(Registry const &)=delete
Don't allow creation through copy/move construction or assignment.
static std::string getClassName()
std::map< std::string, std::string > _repos
Repository name -> repository URL; used for mooseDocumentedError.
static const RegistryEntryBase & objData(const std::string &name)
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
static void addAppCitation(const std::string &app_name, const std::string &key, const std::string &bibtex)
Register a citation (the full BibTeX bibtex text, identified by key) tied to the app app_name; emitte...
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...
static std::string appNameFromAppPath(const std::string &app_path)
Internal helper for getting an application name from its path, for example: /path/to/FooBarBazApp....
friend class DataFileUtilsTest
FRIEND_TEST(RegistryTest, addDataFilePathCapability)
static const std::map< std::string, std::string > & getRepos()
Returns a map of all registered repositories.
static void checkDataFilePathName(const std::string &name)
Check a data file path for valid characters.
FRIEND_TEST(RegistryTest, determineFilePath)
static const std::map< std::string, std::string > & getDataFilePaths()
Returns a map of all registered data file paths (name -> path)
static void setDataFilePaths(const std::map< std::string, std::string > &data_file_paths)
Manually set the data file paths.
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_entry
static void addDeprecatedAppDataFilePath(const std::string &app_path)
deprecated method; use addAppDataFilePath instead
Registry & operator=(Registry const &)=delete
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.
static char addAction(const RegistryEntryData &base_info)
Adds information on an Action object to the registry.
std::map< std::string, std::map< std::string, std::string > > _app_citations
App/module name -> (citation key -> BibTeX entry text) for that app.
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)
Registry & operator=(Registry &&)=delete
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.
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 Registry & getRegistry()
Get the global Registry singleton.
Registry(Registry &&)=delete
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.
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...
static std::string getRegisteredName()
returns the name() for a registered class
static bool isRegisteredObj(const std::string &name)
static std::string getDataFilePath(const std::string &name)
Gets a data path for the registered name.
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
FRIEND_TEST(RegistryTest, appNameFromAppPathFailed)
FRIEND_TEST(RegistryTest, appNameFromAppPath)
std::set< std::string > _known_labels
std::map< std::string, std::string > _data_file_paths
Data file registry; name -> in-tree path.
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_actions
static const std::string & getRepositoryURL(const std::string &repo_name)
Returns the repository URL associated with repo_name.
FRIEND_TEST(RegistryTest, determineFilePathFailed)
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_objects
friend class RegistryTest
Friends for unit testing.
std::map< std::string, std::string > _type_to_classname
static void addRepository(const std::string &repo_name, const std::string &repo_url)
register a repository
static char add(const RegistryEntryData &base_info)
Adds information on a MooseObject to the registry.
static void setRepos(const std::map< std::string, std::string > &repos)
Manually set the repos.
static const std::map< std::string, std::map< std::string, std::string > > & getCitations()
Returns the registered citations, keyed by app/module name and then by BibTeX key (app/module name ->...
static char addKnownLabel(const std::string &label)
addKnownLabel whitelists a label as valid for purposes of the checkLabels function.
virtual std::shared_ptr< MooseObject > buildShared(const InputParameters ¶meters)=0
RegistryEntryBase(const RegistryEntryData &data)
virtual InputParameters buildParameters()=0
virtual std::shared_ptr< Action > buildAction(const InputParameters ¶meters)=0
std::string name() const
resolve the name from _classname, _alias, and _name
virtual std::unique_ptr< MooseObject > build(const InputParameters ¶meters)=0
proxy functions
virtual ~RegistryEntryBase()
Holds details and meta-data info for a particular MooseObject or Action for use in the use in the reg...
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with.
std::string _classname
name of the c++ class for the object.
std::string _alias
an alternate name to register the object to factories under.
std::string _replaced_by
class name for an object that replaces this object if deprecated, blank otherwise.
std::string _file
file path for the c++ file the object or action was added to the registry in.
std::string _deprecated_time
time in "mm/dd/yyyy HH:MM" format that the object is/becomes deprecated, blank otherwise.
std::string _name
name that the object will be registered to factories under. If unspecified, _alias is used.
int _line
line number in the c++ file the object or action was added to the registry on.
virtual std::shared_ptr< MooseObject > buildShared(const InputParameters ¶meters) override
virtual std::unique_ptr< MooseObject > build(const InputParameters ¶meters) override
proxy functions
RegistryEntry(const RegistryEntryData &data)
virtual std::shared_ptr< Action > buildAction(const InputParameters ¶meters) override
virtual InputParameters buildParameters() override