www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Factory Class Reference

Generic factory class for build all sorts of objects. More...

#include <Factory.h>

Public Member Functions

 Factory (MooseApp &app)
 
virtual ~Factory ()
 
template<typename T >
void reg (const std::string &obj_name, const std::string &file="", int line=-1)
 Register a new object. More...
 
void reg (const std::string &label, const std::string &obj_name, const buildPtr &build_ptr, const paramsPtr &params_ptr, const std::string &deprecated_time="", const std::string &replacement_name="", const std::string &file="", int line=-1)
 
FileLineInfo getLineInfo (const std::string &name) const
 Gets file and line information where an object was initially registered. More...
 
void associateNameToClass (const std::string &name, const std::string &class_name)
 Associates an object name with a class name. More...
 
std::string associatedClassName (const std::string &name) const
 Get the associated class name for an object name. More...
 
template<typename T >
void regDeprecated (const std::string &obj_name, const std::string t_str, const std::string &file, int line)
 Register a deprecated object that expires. More...
 
template<typename T >
void regReplaced (const std::string &dep_obj, const std::string &replacement_name, const std::string time_str, const std::string &file, int line)
 Registers an object as deprecated and associates it with the replacement name. More...
 
template<typename T >
void renameObject (const std::string &orig_name, const std::string &new_name, const std::string time_str, const std::string &file, int line)
 Used when an existing object's name changes. More...
 
InputParameters getValidParams (const std::string &name)
 Get valid parameters for the object. More...
 
std::shared_ptr< MooseObjectcreate (const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
 Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) More...
 
template<typename T >
std::shared_ptr< T > create (const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0)
 Build an object (must be registered) More...
 
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::create method(s). More...
 
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 object not contained within the list. More...
 
registeredMooseObjectIterator registeredObjectsBegin ()
 Access to registered object iterator (begin) More...
 
registeredMooseObjectIterator registeredObjectsEnd ()
 Access to registered object iterator (end) More...
 
std::vector< std::string > getConstructedObjects () const
 Get a list of all constructed Moose Object types. More...
 
void regExecFlag (const ExecFlagType &flag)
 Add a new flag to the app. More...
 
MooseAppapp ()
 

Protected Member Functions

std::time_t parseTime (std::string)
 Parse time string (mm/dd/yyyy HH:MM) More...
 
void deprecatedMessage (const std::string obj_name)
 Show the appropriate message for deprecated objects. More...
 
void reportUnregisteredError (const std::string &obj_name) const
 Prints error information when an object is not registered. More...
 

Protected Attributes

MooseApp_app
 Reference to the application. More...
 
std::map< std::string, buildPtr_name_to_build_pointer
 Storage for pointers to the object. More...
 
std::map< std::string, paramsPtr_name_to_params_pointer
 Storage for pointers to the parameters objects. More...
 
FileLineInfoMap _name_to_line
 
std::map< std::string, std::string > _name_to_class
 Object name to class name association. More...
 
std::map< std::string, std::time_t > _deprecated_time
 Storage for deprecated object experiation dates. More...
 
std::map< std::string, std::string > _deprecated_name
 Storage for the deprecated objects that have replacements. More...
 
std::set< std::string > _registerable_objects
 The list of objects that may be registered. More...
 
MooseObjectID _object_count
 Object id count. More...
 
std::set< std::string > _constructed_types
 Constructed Moose Object types. More...
 
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 - which is okay/allowed, while still allowing us to detect/reject cases of duplicate object name registration where the label/appname is not identical. More...
 

Detailed Description

Generic factory class for build all sorts of objects.

Definition at line 154 of file Factory.h.

Constructor & Destructor Documentation

◆ Factory()

Factory::Factory ( MooseApp app)

Definition at line 16 of file Factory.C.

16 : _app(app) {}
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
MooseApp & app()
Definition: Factory.h:352

◆ ~Factory()

Factory::~Factory ( )
virtual

Definition at line 18 of file Factory.C.

18 {}

Member Function Documentation

◆ app()

MooseApp& Factory::app ( )
inline

Definition at line 352 of file Factory.h.

352 { return _app; }
MooseApp & _app
Reference to the application.
Definition: Factory.h:374

◆ associatedClassName()

std::string Factory::associatedClassName ( const std::string &  name) const

Get the associated class name for an object name.

This will return an empty string if the name was not previously associated with a class name via associateNameToClass()

Definition at line 298 of file Factory.C.

Referenced by Parser::buildJsonSyntaxTree().

299 {
300  auto it = _name_to_class.find(name);
301  if (it == _name_to_class.end())
302  return "";
303  else
304  return it->second;
305 }
std::map< std::string, std::string > _name_to_class
Object name to class name association.
Definition: Factory.h:385

◆ associateNameToClass()

void Factory::associateNameToClass ( const std::string &  name,
const std::string &  class_name 
)

Associates an object name with a class name.

Primarily used with the registerNamed* macros to store the mapping between the object name and the class that implements the object.

Definition at line 292 of file Factory.C.

Referenced by Registry::registerObjectsTo(), and renameObject().

293 {
294  _name_to_class[name] = class_name;
295 }
std::map< std::string, std::string > _name_to_class
Object name to class name association.
Definition: Factory.h:385

◆ create() [1/2]

MooseObjectPtr Factory::create ( const std::string &  obj_name,
const std::string &  name,
InputParameters  parameters,
THREAD_ID  tid = 0,
bool  print_deprecated = true 
)

Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>())

Parameters
obj_nameType of the object being constructed
nameName for the object
parametersParameters this object should have
tidThe thread id that this copy will be created for
print_deprecatedcontrols the deprecated message
Returns
The created object

Definition at line 87 of file Factory.C.

Referenced by GridPartitioner::_do_partition(), CreateExecutionerAction::act(), PartitionerAction::act(), CreateProblemAction::act(), CreateProblemDefaultAction::act(), SetupMeshAction::act(), CreateDisplacedProblemAction::act(), SetupPreconditionerAction::act(), SetupPredictorAction::act(), SetupTimeStepperAction::act(), MaterialDerivativeTestAction::act(), AddControlAction::act(), NonlinearSystemBase::addBoundaryCondition(), NonlinearSystemBase::addConstraint(), NonlinearSystemBase::addDamper(), NonlinearSystemBase::addDGKernel(), NonlinearSystemBase::addDiracKernel(), FEProblemBase::addDistribution(), FEProblemBase::addFunction(), FEProblemBase::addIndicator(), FEProblemBase::addInitialCondition(), NonlinearSystemBase::addInterfaceKernel(), MooseEigenSystem::addKernel(), AuxiliarySystem::addKernel(), NonlinearSystemBase::addKernel(), FEProblem::addLineSearch(), FEProblemBase::addMarker(), FEProblemBase::addMaterialHelper(), MooseApp::addMeshGenerator(), MooseApp::addMeshModifier(), FEProblemBase::addMultiApp(), NonlinearSystemBase::addNodalKernel(), FEProblemBase::addOutput(), FEProblemBase::addPredictor(), MooseObjectAction::addRelationshipManagers(), MooseADObjectAction::addRelationshipManagers(), FEProblemBase::addSampler(), AuxiliarySystem::addScalarKernel(), NonlinearSystemBase::addScalarKernel(), NonlinearSystemBase::addSplit(), AuxiliarySystem::addTimeIntegrator(), NonlinearSystemBase::addTimeIntegrator(), FEProblemBase::addTransfer(), FEProblemBase::addUserObject(), AStableDirk4::AStableDirk4(), MooseObjectUnitTest::buildObjects(), create(), and Transient::init().

92 {
93  if (print_deprecated)
94  mooseDeprecated("Factory::create() is deprecated, please use Factory::create<T>() instead");
95 
96  // Pointer to the object constructor
97  std::map<std::string, buildPtr>::iterator it = _name_to_build_pointer.find(obj_name);
98 
99  // Check if the object is registered
100  if (it == _name_to_build_pointer.end())
101  reportUnregisteredError(obj_name);
102 
103  // Print out deprecated message, if it exists
104  deprecatedMessage(obj_name);
105 
106  // Create the actual parameters object that the object will reference
107  InputParameters & params =
108  _app.getInputParameterWarehouse().addInputParameters(name, parameters, tid);
109 
110  // Set the _type parameter
111  params.set<std::string>("_type") = obj_name;
112 
113  // Check to make sure that all required parameters are supplied
114  params.checkParams(name);
115 
116  // register type name as constructed
117  _constructed_types.insert(obj_name);
118 
119  // add FEProblem pointers to object's params object
121  _app.actionWarehouse().problemBase()->setInputParametersFEProblem(params);
122 
123  // call the function pointer to build the object
124  buildPtr & func = it->second;
125  auto obj = (*func)(params);
126 
127  auto fep = std::dynamic_pointer_cast<FEProblemBase>(obj);
128  if (fep)
129  _app.actionWarehouse().problemBase() = fep;
130 
131  // Make sure no unexpected parameters were added by the object's constructor or by the action
132  // initiating this create call. All parameters modified by the constructor must have already
133  // been specified in the object's validParams function.
134  InputParameters orig_params = getValidParams(obj_name);
135  if (orig_params.n_parameters() != parameters.n_parameters())
136  {
137  std::set<std::string> orig, populated;
138  for (const auto & it : orig_params)
139  orig.emplace(it.first);
140  for (const auto & it : parameters)
141  populated.emplace(it.first);
142 
143  std::set<std::string> diff;
144  std::set_difference(populated.begin(),
145  populated.end(),
146  orig.begin(),
147  orig.end(),
148  std::inserter(diff, diff.begin()));
149 
150  if (!diff.empty())
151  {
152  std::stringstream ss;
153  for (const auto & name : diff)
154  ss << ", " << name;
155  mooseError("attempted to set unregistered parameter(s) for ",
156  obj_name,
157  " object:\n ",
158  ss.str().substr(2));
159  }
160  }
161 
162  return obj;
163 }
void reportUnregisteredError(const std::string &obj_name) const
Prints error information when an object is not registered.
Definition: Factory.C:251
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
InputParameters getValidParams(const std::string &name)
Get valid parameters for the object.
Definition: Factory.C:67
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:1328
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
MooseObjectPtr(*)(const InputParameters &parameters) buildPtr
alias for method to build objects
Definition: Factory.h:134
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::shared_ptr< FEProblemBase > & problemBase()
void deprecatedMessage(const std::string obj_name)
Show the appropriate message for deprecated objects.
Definition: Factory.C:200
ActionWarehouse & actionWarehouse()
Definition: MooseApp.h:139
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237
void checkParams(const std::string &parsing_syntax)
This function checks parameters stored in the object to make sure they are in the correct state as th...
InputParameters & addInputParameters(const std::string &name, InputParameters parameters, THREAD_ID tid=0)
Method for adding a new InputParameters object.
std::set< std::string > _constructed_types
Constructed Moose Object types.
Definition: Factory.h:400
std::map< std::string, buildPtr > _name_to_build_pointer
Storage for pointers to the object.
Definition: Factory.h:377

◆ create() [2/2]

template<typename T >
std::shared_ptr<T> Factory::create ( const std::string &  obj_name,
const std::string &  name,
InputParameters  parameters,
THREAD_ID  tid = 0 
)
inline

Build an object (must be registered)

Parameters
obj_nameType of the object being constructed
nameName for the object
parametersParameters this object should have
tidThe thread id that this copy will be created for
Returns
The created object

Definition at line 300 of file Factory.h.

304  {
305  std::shared_ptr<T> new_object =
306  std::dynamic_pointer_cast<T>(create(obj_name, name, parameters, tid, false));
307  if (!new_object)
308  mooseError("We expected to create an object of type '" + demangle(typeid(T).name()) +
309  "'.\nInstead we received a parameters object for type '" + obj_name +
310  "'.\nDid you call the wrong \"add\" method in your Action?");
311 
312  return new_object;
313  }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:87
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)

◆ deprecatedMessage()

void Factory::deprecatedMessage ( const std::string  obj_name)
protected

Show the appropriate message for deprecated objects.

Parameters
obj_nameName of the deprecated object

Definition at line 200 of file Factory.C.

Referenced by create(), and getValidParams().

201 {
202  std::map<std::string, std::time_t>::iterator time_it = _deprecated_time.find(obj_name);
203 
204  // If the object is not deprecated return
205  if (time_it == _deprecated_time.end())
206  return;
207 
208  // Get the current time
209  std::time_t now;
210  time(&now);
211 
212  // Get the stop time
213  std::time_t t_end = time_it->second;
214 
215  // Message storage
216  std::ostringstream msg;
217 
218  std::map<std::string, std::string>::iterator name_it = _deprecated_name.find(obj_name);
219 
220  // Expired object
221  if (now > t_end)
222  {
223  msg << "***** Invalid Object: " << obj_name << " *****\n";
224  msg << "Expired on " << ctime(&t_end);
225 
226  // Append replacement object, if it exsits
227  if (name_it != _deprecated_name.end())
228  msg << "Update your application using the '" << name_it->second << "' object";
229 
230  // Produce the error message
231  mooseDeprecationExpired(msg.str());
232  }
233 
234  // Expiring object
235  else
236  {
237  // Build the basic message
238  msg << "Deprecated Object: " << obj_name << "\n";
239  msg << "This object will be removed on " << ctime(&t_end);
240 
241  // Append replacement object, if it exsits
242  if (name_it != _deprecated_name.end())
243  msg << "Replace " << obj_name << " with " << name_it->second;
244 
245  // Produce the error message
246  mooseDeprecated(msg.str());
247  }
248 }
void mooseDeprecationExpired(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:245
std::map< std::string, std::time_t > _deprecated_time
Storage for deprecated object experiation dates.
Definition: Factory.h:388
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237
std::map< std::string, std::string > _deprecated_name
Storage for the deprecated objects that have replacements.
Definition: Factory.h:391

◆ getConstructedObjects()

std::vector< std::string > Factory::getConstructedObjects ( ) const

Get a list of all constructed Moose Object types.

Definition at line 277 of file Factory.C.

Referenced by MooseApp::runInputFile().

278 {
279  std::vector<std::string> list;
280  for (const auto & name : _constructed_types)
281  list.push_back(name);
282  return list;
283 }
std::set< std::string > _constructed_types
Constructed Moose Object types.
Definition: Factory.h:400

◆ getLineInfo()

FileLineInfo Factory::getLineInfo ( const std::string &  name) const

Gets file and line information where an object was initially registered.

Parameters
nameObject name
Returns
The FileLineInfo associated with name

Definition at line 286 of file Factory.C.

Referenced by Parser::buildJsonSyntaxTree().

287 {
288  return _name_to_line.getInfo(name);
289 }
FileLineInfoMap _name_to_line
Definition: Factory.h:382
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:76

◆ getValidParams()

InputParameters Factory::getValidParams ( const std::string &  name)

Get valid parameters for the object.

Parameters
nameName of the object whose parameter we are requesting
Returns
Parameters of the object

Definition at line 67 of file Factory.C.

Referenced by AB2PredictorCorrector::AB2PredictorCorrector(), CreateProblemDefaultAction::act(), SetupDebugAction::act(), CreateDisplacedProblemAction::act(), SetupResidualDebugAction::act(), MaterialDerivativeTestAction::act(), AddNodalNormalsAction::act(), Executioner::addAttributeReporter(), FEProblem::addLineSearch(), MooseObjectAction::addRelationshipManagers(), MooseADObjectAction::addRelationshipManagers(), AStableDirk4::AStableDirk4(), MooseObjectUnitTest::buildObjects(), create(), DumpObjectsProblem::deduceNecessaryParameters(), FEProblemBase::getFunction(), MaterialOutputAction::getParams(), Transient::init(), and Transient::setupTimeIntegrator().

68 {
69  std::map<std::string, paramsPtr>::iterator it = _name_to_params_pointer.find(obj_name);
70 
71  // Check if the object is registered
72  if (it == _name_to_params_pointer.end())
73  reportUnregisteredError(obj_name);
74 
75  // Print out deprecated message, if it exists
76  deprecatedMessage(obj_name);
77 
78  // Return the parameters
79  paramsPtr & func = it->second;
80  InputParameters params = (*func)();
81  params.addPrivateParam("_moose_app", &_app);
82 
83  return params;
84 }
void reportUnregisteredError(const std::string &obj_name) const
Prints error information when an object is not registered.
Definition: Factory.C:251
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void deprecatedMessage(const std::string obj_name)
Show the appropriate message for deprecated objects.
Definition: Factory.C:200
std::map< std::string, paramsPtr > _name_to_params_pointer
Storage for pointers to the parameters objects.
Definition: Factory.h:380
InputParameters(*)() paramsPtr
alias for validParams function
Definition: AppFactory.h:33

◆ parseTime()

std::time_t Factory::parseTime ( std::string  t_str)
protected

Parse time string (mm/dd/yyyy HH:MM)

Parameters
t_strString with the object expiration date, this must be in the form mm/dd/yyyy HH:MM
Returns
A time_t object with the expiration date

Definition at line 178 of file Factory.C.

Referenced by reg(), and renameObject().

179 {
180  // The string must be a certain length to be valid
181  if (t_str.size() != 16)
182  mooseError("The deprecated time not formatted correctly; it must be given as mm/dd/yyyy HH:MM");
183 
184  // Store the time, the time must be specified as: mm/dd/yyyy HH:MM
185  std::time_t t_end;
186  struct tm * t_end_info;
187  time(&t_end);
188  t_end_info = localtime(&t_end);
189  t_end_info->tm_mon = std::atoi(t_str.substr(0, 2).c_str()) - 1;
190  t_end_info->tm_mday = std::atoi(t_str.substr(3, 2).c_str());
191  t_end_info->tm_year = std::atoi(t_str.substr(6, 4).c_str()) - 1900;
192  t_end_info->tm_hour = std::atoi(t_str.substr(11, 2).c_str()) + 1;
193  t_end_info->tm_min = std::atoi(t_str.substr(14, 2).c_str());
194  t_end_info->tm_sec = 0;
195  t_end = mktime(t_end_info);
196  return t_end;
197 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ reg() [1/2]

template<typename T >
void Factory::reg ( const std::string &  obj_name,
const std::string &  file = "",
int  line = -1 
)
inline

Register a new object.

Parameters
obj_nameName of the object to register

Definition at line 165 of file Factory.h.

Referenced by regDeprecated(), Registry::registerObjectsTo(), and regReplaced().

166  {
167  reg("", obj_name, &buildObject<T>, &validParams<T>, "", "", file, line);
168  }
void reg(const std::string &obj_name, const std::string &file="", int line=-1)
Register a new object.
Definition: Factory.h:165

◆ reg() [2/2]

void Factory::reg ( const std::string &  label,
const std::string &  obj_name,
const buildPtr build_ptr,
const paramsPtr params_ptr,
const std::string &  deprecated_time = "",
const std::string &  replacement_name = "",
const std::string &  file = "",
int  line = -1 
)

Definition at line 21 of file Factory.C.

29 {
30  // do nothing if we have already added this exact object before
31  auto key = std::make_pair(label, obj_name);
32  if (_objects_by_label.find(key) != _objects_by_label.end())
33  return;
34 
35  /*
36  * If _registerable_objects has been set the user has requested that we only register some
37  * subset
38  * of the objects for a dynamically loaded application. The objects listed in *this*
39  * application's
40  * registerObjects() method will have already been registered before that member was set.
41  *
42  * If _registerable_objects is empty, the factory is unrestricted
43  */
44  if (_registerable_objects.empty() ||
45  _registerable_objects.find(obj_name) != _registerable_objects.end())
46  {
47  if (_name_to_build_pointer.find(obj_name) != _name_to_build_pointer.end())
48  mooseError("Object '" + obj_name + "' registered from multiple files: ",
49  file,
50  " and ",
51  _name_to_line.getInfo(obj_name).file());
52  _name_to_build_pointer[obj_name] = build_ptr;
53  _name_to_params_pointer[obj_name] = params_ptr;
54  _objects_by_label.insert(key);
55  }
56  _name_to_line.addInfo(obj_name, file, line);
57 
58  if (!replacement_name.empty())
59  _deprecated_name[obj_name] = replacement_name;
60  if (!deprecated_time.empty())
61  _deprecated_time[obj_name] = parseTime(deprecated_time);
62 
63  // TODO: Possibly store and print information about objects that are skipped here?
64 }
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...
Definition: Factory.h:405
std::time_t parseTime(std::string)
Parse time string (mm/dd/yyyy HH:MM)
Definition: Factory.C:178
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
FileLineInfoMap _name_to_line
Definition: Factory.h:382
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:76
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:35
std::map< std::string, std::time_t > _deprecated_time
Storage for deprecated object experiation dates.
Definition: Factory.h:388
std::set< std::string > _registerable_objects
The list of objects that may be registered.
Definition: Factory.h:394
std::map< std::string, std::string > _deprecated_name
Storage for the deprecated objects that have replacements.
Definition: Factory.h:391
std::map< std::string, paramsPtr > _name_to_params_pointer
Storage for pointers to the parameters objects.
Definition: Factory.h:380
std::string file() const
Definition: FileLineInfo.C:29
std::map< std::string, buildPtr > _name_to_build_pointer
Storage for pointers to the object.
Definition: Factory.h:377

◆ regDeprecated()

template<typename T >
void Factory::regDeprecated ( const std::string &  obj_name,
const std::string  t_str,
const std::string &  file,
int  line 
)
inline

Register a deprecated object that expires.

Parameters
obj_nameThe name of the object to register
t_strString containing the expiration date for the object in "MM/DD/YYYY HH:MM" format. Note that the HH:MM is not optional

Note: Params file and line are supplied by the macro

Definition at line 209 of file Factory.h.

213  {
214  reg("", obj_name, &buildObject<T>, &validParams<T>, t_str, "", file, line);
215  }
void reg(const std::string &obj_name, const std::string &file="", int line=-1)
Register a new object.
Definition: Factory.h:165

◆ regExecFlag()

void Factory::regExecFlag ( const ExecFlagType flag)

Add a new flag to the app.

Parameters
flagThe flag to add as available to the app level ExecFlagEnum.

Definition at line 308 of file Factory.C.

309 {
310  _app.addExecFlag(flag);
311 }
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
void addExecFlag(const ExecFlagType &flag)
WARNING: This is an internal method for MOOSE, if you need the add new ExecFlagTypes then use the reg...
Definition: MooseApp.C:1677

◆ registeredObjectsBegin()

registeredMooseObjectIterator Factory::registeredObjectsBegin ( )
inline

Access to registered object iterator (begin)

Definition at line 334 of file Factory.h.

Referenced by Parser::buildFullTree(), and Parser::buildJsonSyntaxTree().

334 { return _name_to_params_pointer.begin(); }
std::map< std::string, paramsPtr > _name_to_params_pointer
Storage for pointers to the parameters objects.
Definition: Factory.h:380

◆ registeredObjectsEnd()

registeredMooseObjectIterator Factory::registeredObjectsEnd ( )
inline

Access to registered object iterator (end)

Definition at line 339 of file Factory.h.

Referenced by Parser::buildFullTree(), and Parser::buildJsonSyntaxTree().

339 { return _name_to_params_pointer.end(); }
std::map< std::string, paramsPtr > _name_to_params_pointer
Storage for pointers to the parameters objects.
Definition: Factory.h:380

◆ regReplaced()

template<typename T >
void Factory::regReplaced ( const std::string &  dep_obj,
const std::string &  replacement_name,
const std::string  time_str,
const std::string &  file,
int  line 
)
inline

Registers an object as deprecated and associates it with the replacement name.

Parameters
dep_obj- The name (type) of the object being registered (the deprecated type)
replacement_name- The name of the object replacing the deprecated object (new name)
time_str- Time at which the deprecated message prints as an error "MM/DD/YYYY HH:MM" Note that the HH:MM is not optional

Note: Params file and line are supplied by the macro

Definition at line 227 of file Factory.h.

232  {
233  reg("", dep_obj, &buildObject<T>, &validParams<T>, time_str, replacement_name, file, line);
234  }
void reg(const std::string &obj_name, const std::string &file="", int line=-1)
Register a new object.
Definition: Factory.h:165

◆ releaseSharedObjects()

void Factory::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::create method(s).

Currently, this object just moves the InputParameters object from the InputParameterWarehouse. Normally this method does not need to be explicitly called during a normal simulation.

Definition at line 166 of file Factory.C.

Referenced by MooseADObjectAction::addRelationshipManagers(), and MooseObjectAction::addRelationshipManagers().

167 {
169 }
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:1328
void removeInputParameters(const MooseObject &moose_object, THREAD_ID tid=0)
Allows for the deletion and cleanup of an object while the simulation is running. ...

◆ renameObject()

template<typename T >
void Factory::renameObject ( const std::string &  orig_name,
const std::string &  new_name,
const std::string  time_str,
const std::string &  file,
int  line 
)
inline

Used when an existing object's name changes.

Template T: The type of the new class

Parameters
orig_nameThe name of the original class
new_nameThe name of the new class
time_strThe date the deprecation will expire

Note: Params file and line are supplied by the macro

Definition at line 248 of file Factory.h.

253  {
254  // Deprecate the old name
255  // Store the time
256  _deprecated_time[orig_name] = parseTime(time_str);
257 
258  // Store the new name
259  _deprecated_name[orig_name] = new_name;
260 
261  // Register the new object with the old name
262  reg<T>(orig_name, __FILE__, __LINE__);
263  associateNameToClass(orig_name, new_name);
264 
265  // Register the new object with the new name
266  reg<T>(new_name, file, line);
267  }
std::time_t parseTime(std::string)
Parse time string (mm/dd/yyyy HH:MM)
Definition: Factory.C:178
std::map< std::string, std::time_t > _deprecated_time
Storage for deprecated object experiation dates.
Definition: Factory.h:388
void associateNameToClass(const std::string &name, const std::string &class_name)
Associates an object name with a class name.
Definition: Factory.C:292
std::map< std::string, std::string > _deprecated_name
Storage for the deprecated objects that have replacements.
Definition: Factory.h:391

◆ reportUnregisteredError()

void Factory::reportUnregisteredError ( const std::string &  obj_name) const
protected

Prints error information when an object is not registered.

Definition at line 251 of file Factory.C.

Referenced by create(), and getValidParams().

252 {
253  // Make sure that we don't have an improperly registered object first
255 
256  std::ostringstream oss;
257  std::set<std::string> paths = _app.getLoadedLibraryPaths();
258 
259  oss << "A '" + obj_name + "' is not a registered object.\n";
260 
261  if (!paths.empty())
262  {
263  oss << "\nWe loaded objects from the following libraries and still couldn't find your "
264  "object:\n\t";
265  std::copy(paths.begin(), paths.end(), infix_ostream_iterator<std::string>(oss, "\n\t"));
266  oss << '\n';
267  }
268 
269  oss << "\nIf you are trying to find this object in a dynamically linked library, make sure that\n"
270  "the library can be found either in your \"Problem/library_path\" parameter or in the\n"
271  "MOOSE_LIBRARY_PATH environment variable.";
272 
273  mooseError(oss.str());
274 }
MooseApp & _app
Reference to the application.
Definition: Factory.h:374
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
virtual void checkRegistryLabels()
Definition: MooseApp.C:402
std::set< std::string > getLoadedLibraryPaths() const
Return the loaded library filenames in a std::vector.
Definition: MooseApp.C:1317

◆ restrictRegisterableObjects()

void Factory::restrictRegisterableObjects ( const std::vector< std::string > &  names)

Calling this object with a non-empty vector will cause this factory to ignore registrations from any object not contained within the list.

Parameters
namesa vector containing the names of objects that this factory will register

Definition at line 172 of file Factory.C.

Referenced by DynamicObjectRegistrationAction::DynamicObjectRegistrationAction().

173 {
174  _registerable_objects.insert(names.begin(), names.end());
175 }
std::set< std::string > _registerable_objects
The list of objects that may be registered.
Definition: Factory.h:394

Member Data Documentation

◆ _app

MooseApp& Factory::_app
protected

Reference to the application.

Definition at line 374 of file Factory.h.

Referenced by app(), create(), getValidParams(), regExecFlag(), releaseSharedObjects(), and reportUnregisteredError().

◆ _constructed_types

std::set<std::string> Factory::_constructed_types
protected

Constructed Moose Object types.

Definition at line 400 of file Factory.h.

Referenced by create(), and getConstructedObjects().

◆ _deprecated_name

std::map<std::string, std::string> Factory::_deprecated_name
protected

Storage for the deprecated objects that have replacements.

Definition at line 391 of file Factory.h.

Referenced by deprecatedMessage(), reg(), and renameObject().

◆ _deprecated_time

std::map<std::string, std::time_t> Factory::_deprecated_time
protected

Storage for deprecated object experiation dates.

Definition at line 388 of file Factory.h.

Referenced by deprecatedMessage(), reg(), and renameObject().

◆ _name_to_build_pointer

std::map<std::string, buildPtr> Factory::_name_to_build_pointer
protected

Storage for pointers to the object.

Definition at line 377 of file Factory.h.

Referenced by create(), and reg().

◆ _name_to_class

std::map<std::string, std::string> Factory::_name_to_class
protected

Object name to class name association.

Definition at line 385 of file Factory.h.

Referenced by associatedClassName(), and associateNameToClass().

◆ _name_to_line

FileLineInfoMap Factory::_name_to_line
protected

Definition at line 382 of file Factory.h.

Referenced by getLineInfo(), and reg().

◆ _name_to_params_pointer

std::map<std::string, paramsPtr> Factory::_name_to_params_pointer
protected

Storage for pointers to the parameters objects.

Definition at line 380 of file Factory.h.

Referenced by getValidParams(), reg(), registeredObjectsBegin(), and registeredObjectsEnd().

◆ _object_count

MooseObjectID Factory::_object_count
protected

Object id count.

Definition at line 397 of file Factory.h.

◆ _objects_by_label

std::set<std::pair<std::string, std::string> > Factory::_objects_by_label
protected

set<label/appname, objectname> used to track if an object previously added is being added again - which is okay/allowed, while still allowing us to detect/reject cases of duplicate object name registration where the label/appname is not identical.

Definition at line 405 of file Factory.h.

Referenced by reg().

◆ _registerable_objects

std::set<std::string> Factory::_registerable_objects
protected

The list of objects that may be registered.

Definition at line 394 of file Factory.h.

Referenced by reg(), and restrictRegisterableObjects().


The documentation for this class was generated from the following files: