21 #include "libmesh/utility.h" 23 #ifdef MOOSE_UNIT_TEST 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 static char combineNames(dummy_var_for_known_label, __COUNTER__) = Registry::addKnownLabel(X) 39 #define registerMooseAction(app, classname, task) \ 40 static char combineNames(dummyvar_for_registering_action_##classname, __COUNTER__) = \ 41 Registry::addAction<classname>({app, #classname, "", task, __FILE__, __LINE__, "", ""}) 45 #define registerMooseObject(app, classname) \ 46 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 47 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, "", ""}) 49 #define registerADMooseObject(app, classname) registerMooseObject(app, classname) 53 #define registerMooseObjectAliased(app, classname, alias) \ 54 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 55 Registry::add<classname>({app, #classname, alias, "", __FILE__, __LINE__, "", ""}) 59 #define registerMooseObjectDeprecated(app, classname, time) \ 60 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 61 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, ""}) 63 #define registerADMooseObjectDeprecated(app, classname, time) \ 64 registerMooseObjectDeprecated(app, classname, time) 68 #define registerMooseObjectReplaced(app, classname, time, replacement) \ 69 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 70 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, #replacement}) 76 #define registerMooseObjectRenamed(app, orig_class, time, new_class) \ 77 static char combineNames(dummyvar_for_registering_obj_##orig_class, __COUNTER__) = \ 78 Registry::add<new_class>( \ 79 {app, #new_class, #orig_class, #orig_class, __FILE__, __LINE__, time, #new_class}) 81 #define registerADMooseObjectRenamed(app, orig_class, time, new_class) \ 82 registerMooseObjectRenamed(app, orig_class, time, new_class) 85 #define registerNonAppDataFilePath(name, path) Registry::addDataFilePath(name, path, false) 86 #define registerNonAppDataFilePathWithInfo(name, path, info) \ 88 Registry::addDataFilePath(name, path, false, info) 89 #define registerAppDataFilePath(app) Registry::addAppDataFilePath(app, __FILE__) 93 #define registerMissingDataFilePath(name, info) Registry::addMissingDataFilePath(name, info) 95 #define registerDataFilePath() Registry::addDeprecatedAppDataFilePath(__FILE__) 98 #define registerRepository(repo_name, repo_url) Registry::addRepository(repo_name, repo_url); 152 template <
typename T>
182 template <
typename T>
185 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
194 template <
typename T>
197 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
203 template <
typename T>
222 const std::string & in_tree_path,
223 const bool app =
true,
224 const std::optional<std::string> &
info = {});
227 static void addAppDataFilePath(
const std::string & app_name,
const std::string & app_path);
234 static void addRepository(
const std::string & repo_name,
const std::string & repo_url);
237 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allObjects()
242 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allActions()
277 template <
typename T>
289 #ifdef MOOSE_UNIT_TEST 318 static void setRepos(
const std::map<std::string, std::string> & repos)
325 const std::string & in_tree_path);
336 const std::optional<std::string> & path = {},
337 const std::optional<std::string> & extra_info = {});
346 std::map<std::string, std::string>
_repos;
350 template <
typename T>
355 return getClassName<T>();
358 template <
typename T>
361 static_assert(std::is_base_of_v<MooseObject, T> || std::is_base_of_v<Action, T>,
362 "Not derived from MooseObject or Action");
365 template <
typename T>
366 std::unique_ptr<MooseObject>
369 if constexpr (std::is_base_of_v<MooseObject, T>)
370 return std::make_unique<T>(parameters);
371 mooseError(MooseUtils::prettyCppType<T>(),
" to be built is not a MooseObject.");
373 template <
typename T>
374 std::shared_ptr<MooseObject>
377 if constexpr (std::is_base_of_v<MooseObject, T>)
378 return std::make_shared<T>(parameters);
379 mooseError(MooseUtils::prettyCppType<T>(),
" to be built is not a MooseObject.");
382 template <
typename T>
383 std::shared_ptr<Action>
386 if constexpr (!std::is_base_of_v<Action, T>)
387 mooseError(
"The action to be built is not derived from Action.");
389 return std::make_shared<T>(parameters);
392 template <
typename T>
std::string name(const ElemQuality q)
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.
virtual std::shared_ptr< MooseObject > buildShared(const InputParameters ¶meters) override
virtual std::shared_ptr< Action > buildAction(const InputParameters ¶meters) override
virtual std::unique_ptr< MooseObject > build(const InputParameters ¶meters)=0
proxy functions
static const RegistryEntryBase & objData(const std::string &name)
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_actions
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
virtual InputParameters buildParameters()=0
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...
Holds details and meta-data info for a particular MooseObject or Action for use in the use in the reg...
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 std::string getRegisteredName()
returns the name() for a registered class
std::string _classname
name of the c++ class for the object.
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)
friend class RegistryTest
Friends for unit testing.
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 std::shared_ptr< Action > buildAction(const InputParameters ¶meters)=0
RegistryEntryBase(const RegistryEntryData &data)
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.
std::string _file
file path for the c++ file the object or action was added to the registry in.
static char addAction(const RegistryEntryData &base_info)
Adds information on an Action object to the registry.
virtual ~RegistryEntryBase()
friend class DataFileUtilsTest
static void setDataFilePaths(const std::map< std::string, std::string > &data_file_paths)
Manually set the data file paths.
std::string _name
name that the object will be registered to factories under. If unspecified, _alias is used...
virtual std::shared_ptr< MooseObject > buildShared(const InputParameters ¶meters)=0
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, determineFilePath)
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 char add(const RegistryEntryData &base_info)
Adds information on a MooseObject to the registry.
std::string name() const
resolve the name from _classname, _alias, and _name
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.
Every object that can be built by the factory should be derived from this class.
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.
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_entry
Specialized factory for generic Action System objects.
static void checkDataFilePathName(const std::string &name)
Check a data file path for valid characters.
static std::string getClassName()
static void addRepository(const std::string &repo_name, const std::string &repo_url)
register a repository
virtual std::unique_ptr< MooseObject > build(const InputParameters ¶meters) override
proxy functions
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
int _line
line number in the c++ file the object or action was added to the registry on.
static void setRepos(const std::map< std::string, std::string > &repos)
Manually set the repos.
std::string _label
label (usually app name - e.g. "YourAnimalApp") that the object or action is associated with...
std::set< std::string > _known_labels
std::map< std::string, std::string > _type_to_classname
static bool isRegisteredObj(const std::string &name)
std::string _deprecated_time
time in "mm/dd/yyyy HH:MM" format that the object is/becomes deprecated, blank otherwise.
RegistryEntry(const RegistryEntryData &data)
std::map< std::string, std::string > _repos
Repository name -> repository URL; used for mooseDocumentedError.
virtual InputParameters buildParameters() override
static const std::string & getRepositoryURL(const std::string &repo_name)
Returns the repository URL associated with repo_name.
static const std::map< std::string, std::string > & getDataFilePaths()
Returns a map of all registered data file paths (name -> path)
Registry & operator=(Registry const &)=delete
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 const std::map< std::string, std::string > & getRepos()
Returns a map of all registered repositories.
std::map< std::string, std::vector< std::shared_ptr< RegistryEntryBase > > > _per_label_objects
InputParameters validParams()
static char addKnownLabel(const std::string &label)
addKnownLabel whitelists a label as valid for purposes of the checkLabels function.