25 const std::string obj_name = obj->name();
26 const std::string & label = obj->_label;
27 const std::string & deprecated_time = obj->_deprecated_time;
28 const std::string & replacement_name = obj->_replaced_by;
29 const std::string & file = obj->_file;
30 const int line = obj->_line;
33 auto key = std::make_pair(label, obj_name);
50 mooseError(
"Object '" + obj_name +
"' registered from multiple files: ",
59 if (!replacement_name.empty())
61 if (!deprecated_time.empty())
80 auto params = it->second->buildParameters();
86 template <
class ptr_type>
89 const std::string & name,
92 const std::optional<std::string> & deprecated_method_name)
94 static_assert(std::is_same_v<ptr_type, std::unique_ptr<MooseObject>> ||
95 std::is_same_v<ptr_type, std::shared_ptr<MooseObject>>,
98 if (deprecated_method_name)
100 const std::string
name =
"Factory::" + *deprecated_method_name;
106 auto & warehouse_params =
initialize(obj_name,
name, parameters, tid);
114 if constexpr (std::is_same_v<ptr_type, std::unique_ptr<MooseObject>>)
115 obj = registry_entry.build(warehouse_params);
117 obj = registry_entry.buildShared(warehouse_params);
127 std::unique_ptr<MooseObject>
129 const std::string & name,
132 bool print_deprecated )
134 std::optional<std::string> deprecated_method_name;
135 if (print_deprecated)
136 deprecated_method_name =
"createUnique";
137 return createTempl<std::unique_ptr<MooseObject>>(
138 obj_name,
name, parameters, tid, deprecated_method_name);
141 std::shared_ptr<MooseObject>
143 const std::string & name,
146 bool print_deprecated )
148 std::optional<std::string> deprecated_method_name;
149 if (print_deprecated)
150 deprecated_method_name =
"create";
151 return createTempl<std::shared_ptr<MooseObject>>(
152 obj_name,
name, parameters, tid, deprecated_method_name);
171 if (t_str.size() != 16)
172 mooseError(
"The deprecated time not formatted correctly; it must be given as mm/dd/yyyy HH:MM");
176 struct tm * t_end_info;
178 t_end_info = localtime(&t_end);
179 t_end_info->tm_mon = std::atoi(t_str.substr(0, 2).c_str()) - 1;
180 t_end_info->tm_mday = std::atoi(t_str.substr(3, 2).c_str());
181 t_end_info->tm_year = std::atoi(t_str.substr(6, 4).c_str()) - 1900;
182 t_end_info->tm_hour = std::atoi(t_str.substr(11, 2).c_str()) + 1;
183 t_end_info->tm_min = std::atoi(t_str.substr(14, 2).c_str());
184 t_end_info->tm_sec = 0;
185 t_end = mktime(t_end_info);
212 std::time_t t_end = time_it->second;
215 std::ostringstream msg;
222 msg <<
"***** Invalid Object: " << obj_name <<
" *****\n";
223 msg <<
"Expired on " << ctime(&t_end);
227 msg <<
"Update your application using the '" << name_it->second <<
"' object";
237 msg <<
"Deprecated Object: " << obj_name <<
"\n";
238 msg <<
"This object will be removed on " << ctime(&t_end);
242 msg <<
"Replace " << obj_name <<
" with " << name_it->second;
253 std::ostringstream oss;
256 oss <<
"A '" + obj_name +
"' is not a registered object.\n";
260 oss <<
"\nWe loaded objects from the following libraries and still couldn't find your " 262 std::copy(paths.begin(), paths.end(), infix_ostream_iterator<std::string>(oss,
"\n\t"));
266 oss <<
"\nIf you are trying to find this object in a dynamically loaded library, make sure that\n" 267 "the library can be found either in your \"Problem/library_path\" parameter or in the\n" 268 "MOOSE_LIBRARY_PATH environment variable.";
273 std::vector<std::string>
276 std::vector<std::string> list;
278 list.push_back(
name);
312 const std::string & name,
361 const auto & object_params =
object.parameters();
362 if (orig_params.
n_parameters() != object_params.n_parameters())
364 std::set<std::string> orig, populated;
365 for (
const auto & it : orig_params)
366 orig.emplace(it.first);
367 for (
const auto & it : object_params)
368 populated.emplace(it.first);
370 std::set<std::string> diff;
371 std::set_difference(populated.begin(),
375 std::inserter(diff, diff.begin()));
379 std::stringstream ss;
380 for (
const auto &
name : diff)
382 object.mooseError(
"Attempted to set unregistered parameter(s):\n ", ss.str().substr(2));
388 template std::unique_ptr<MooseObject>
389 Factory::createTempl<std::unique_ptr<MooseObject>>(
const std::string &,
393 const std::optional<std::string> &);
394 template std::shared_ptr<MooseObject>
395 Factory::createTempl<std::shared_ptr<MooseObject>>(
const std::string &,
399 const std::optional<std::string> &);
std::set< std::pair< std::string, std::string > > _objects_by_label
set<label/appname, objectname> used to track if an object previously added is being added again - whi...
std::string name(const ElemQuality q)
void restrictRegisterableObjects(const std::vector< std::string > &names)
Calling this object with a non-empty vector will cause this factory to ignore registrations from any ...
void reportUnregisteredError(const std::string &obj_name) const
Prints error information when an object is not registered.
bool show_trace
Set to true (the default) to print the stack trace with error and warning messages - false to omit it...
static const std::string app_param
The name of the parameter that contains the MooseApp.
std::set< std::string > _deprecated_types
Set of deprecated object types that have been printed.
MooseApp & _app
Reference to the application.
static const std::string type_param
The name of the parameter that contains the object type.
std::time_t parseTime(std::string)
Parse time string (mm/dd/yyyy HH:MM)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
std::string associatedClassName(const std::string &name) const
Get the associated class name for an object name.
FileLineInfoMap _name_to_line
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
void mooseDeprecationExpired(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Base class for MOOSE-based applications.
const hit::Node * getCurrentActionHitNode() const
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
FileLineInfo getLineInfo(const std::string &name) const
Gets file and line information where an object was initially registered.
std::shared_ptr< FEProblemBase > & problemBase()
void deprecatedMessage(const std::string obj_name) const
Show the appropriate message for deprecated objects.
InputParameters & initialize(const std::string &type, const std::string &name, const InputParameters &from_params, const THREAD_ID tid)
Initializes the data structures and the parameters (in the InputParameterWarehouse) for the object wi...
std::map< std::string, std::time_t > _deprecated_time
Storage for deprecated object expiration dates.
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.
ptr_type createTempl(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, const THREAD_ID tid, const std::optional< std::string > &deprecated_method_name)
Internal method for creating a MooseObject, either as a shared_ptr or as a unique_ptr.
std::set< std::string > _registerable_objects
The list of objects that may be registered.
Every object that can be built by the factory should be derived from this class.
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
std::vector< const InputParameters * > _currently_constructing
The object's parameters that are currently being constructed (if any).
std::map< std::string, std::string > _deprecated_name
Storage for the deprecated objects that have replacements.
Holds file and line information.
std::map< std::string, std::string > _name_to_class
Object name to class name association.
void releaseSharedObjects(const MooseObject &moose_object, THREAD_ID tid=0)
Releases any shared resources created as a side effect of creating an object through the Factory::cre...
std::map< std::string, std::shared_ptr< RegistryEntryBase > > _name_to_object
Storage for pointers to the object registry entry.
void finalize(const std::string &type, const MooseObject &object)
Finalizes the creaction of object of type type.
std::vector< std::string > getConstructedObjects() const
Get a list of all constructed Moose Object types.
std::set< std::string > _constructed_types
Constructed Moose Object types.
std::size_t n_parameters() const
std::unique_ptr< MooseObject > createUnique(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
const InputParameters * currentlyConstructing() const
std::set< std::string > getLoadedLibraryPaths() const
Return the paths of loaded libraries.