20 #include "libmesh/utility.h" 22 #include <gtest/gtest.h> 24 #define combineNames1(X, Y) X##Y 25 #define combineNames(X, Y) combineNames1(X, Y) 31 #define registerKnownLabel(X) \ 32 static char combineNames(dummy_var_for_known_label, __COUNTER__) = Registry::addKnownLabel(X) 36 #define registerMooseAction(app, classname, task) \ 37 static char combineNames(dummyvar_for_registering_action_##classname, __COUNTER__) = \ 38 Registry::addAction<classname>({app, #classname, "", task, __FILE__, __LINE__, "", ""}) 42 #define registerMooseObject(app, classname) \ 43 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 44 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, "", ""}) 46 #define registerADMooseObject(app, classname) registerMooseObject(app, classname) 50 #define registerMooseObjectAliased(app, classname, alias) \ 51 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 52 Registry::add<classname>({app, #classname, alias, "", __FILE__, __LINE__, "", ""}) 56 #define registerMooseObjectDeprecated(app, classname, time) \ 57 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 58 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, ""}) 60 #define registerADMooseObjectDeprecated(app, classname, time) \ 61 registerMooseObjectDeprecated(app, classname, time) 65 #define registerMooseObjectReplaced(app, classname, time, replacement) \ 66 static char combineNames(dummyvar_for_registering_obj_##classname, __COUNTER__) = \ 67 Registry::add<classname>({app, #classname, "", "", __FILE__, __LINE__, time, #replacement}) 73 #define registerMooseObjectRenamed(app, orig_class, time, new_class) \ 74 static char combineNames(dummyvar_for_registering_obj_##orig_class, __COUNTER__) = \ 75 Registry::add<new_class>( \ 76 {app, #new_class, #orig_class, #orig_class, __FILE__, __LINE__, time, #new_class}) 78 #define registerADMooseObjectRenamed(app, orig_class, time, new_class) \ 79 registerMooseObjectRenamed(app, orig_class, time, new_class) 82 #define registerNonAppDataFilePath(name, path) Registry::addDataFilePath(name, path) 83 #define registerAppDataFilePath(app) Registry::addAppDataFilePath(app, __FILE__) 87 #define registerDataFilePath() Registry::addDeprecatedAppDataFilePath(__FILE__) 90 #define registerRepository(repo_name, repo_url) Registry::addRepository(repo_name, repo_url); 143 template <
typename T>
172 template <
typename T>
175 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
184 template <
typename T>
187 const auto info = std::make_shared<RegistryEntry<T>>(base_info);
193 template <
typename T>
211 static void addDataFilePath(
const std::string & name,
const std::string & in_tree_path);
214 static void addAppDataFilePath(
const std::string & app_name,
const std::string & app_path);
219 static void addRepository(
const std::string & repo_name,
const std::string & repo_url);
222 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allObjects()
227 static const std::map<std::string, std::vector<std::shared_ptr<RegistryEntryBase>>> &
allActions()
262 template <
typename T>
300 static void setRepos(
const std::map<std::string, std::string> & repos)
307 const std::string & in_tree_path);
320 std::map<std::string, std::string>
_repos;
324 template <
typename T>
329 return getClassName<T>();
332 template <
typename T>
333 std::unique_ptr<MooseObject>
336 if constexpr (std::is_base_of_v<MooseObject, T>)
337 return std::make_unique<T>(parameters);
338 mooseError(
"The object to be built is not derived from MooseObject.");
341 template <
typename T>
342 std::shared_ptr<Action>
345 if constexpr (!std::is_base_of_v<Action, T>)
346 mooseError(
"The action to be built is not derived from Action.");
348 return std::make_shared<T>(parameters);
351 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< 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.
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.
InputParameters validParams()
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...
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.
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 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
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)