www.mooseframework.org
Classes | Public Types | Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ActionFactory Class Reference

Specialized factory for generic Action System objects. More...

#include <ActionFactory.h>

Classes

class  BuildInfo
 

Public Types

typedef std::multimap< std::string, BuildInfo >::iterator iterator
 Typedef for registered Action iterator. More...
 
typedef std::multimap< std::string, BuildInfo >::const_iterator const_iterator
 

Public Member Functions

 ActionFactory (MooseApp &app)
 
virtual ~ActionFactory ()
 
template<typename T >
void reg (const std::string &name, const std::string &task, const std::string &file="", int line=-1)
 
FileLineInfo getLineInfo (const std::string &name, const std::string &task) const
 Gets file and line information where an action was registered. More...
 
std::string getTaskName (const std::string &action)
 
std::shared_ptr< Actioncreate (const std::string &action, const std::string &action_name, InputParameters parameters)
 
InputParameters getValidParams (const std::string &name)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iteratorgetActionsByTask (const std::string &task) const
 
std::set< std::string > getTasksByAction (const std::string &action) const
 

Protected Attributes

MooseApp_app
 
std::multimap< std::string, BuildInfo_name_to_build_info
 
FileLineInfoMap _name_to_line
 
std::multimap< std::string, std::string > _task_to_action_map
 

Static Protected Attributes

static unsigned int _unique_id = 0
 Unique ID for identifying multiple registrations. More...
 

Detailed Description

Specialized factory for generic Action System objects.

Definition at line 70 of file ActionFactory.h.

Member Typedef Documentation

typedef std::multimap<std::string, BuildInfo>::const_iterator ActionFactory::const_iterator

Definition at line 119 of file ActionFactory.h.

typedef std::multimap<std::string, BuildInfo>::iterator ActionFactory::iterator

Typedef for registered Action iterator.

Definition at line 118 of file ActionFactory.h.

Constructor & Destructor Documentation

ActionFactory::ActionFactory ( MooseApp app)

Definition at line 21 of file ActionFactory.C.

21 : _app(app) {}
MooseApp & _app
ActionFactory::~ActionFactory ( )
virtual

Definition at line 23 of file ActionFactory.C.

23 {}

Member Function Documentation

ActionFactory::iterator ActionFactory::begin ( )

Definition at line 107 of file ActionFactory.C.

108 {
109  return _name_to_build_info.begin();
110 }
std::multimap< std::string, BuildInfo > _name_to_build_info
ActionFactory::const_iterator ActionFactory::begin ( ) const

Definition at line 113 of file ActionFactory.C.

114 {
115  return _name_to_build_info.begin();
116 }
std::multimap< std::string, BuildInfo > _name_to_build_info
std::shared_ptr< Action > ActionFactory::create ( const std::string &  action,
const std::string &  action_name,
InputParameters  parameters 
)

Definition at line 26 of file ActionFactory.C.

Referenced by DetermineSystemType::act(), ActionWarehouse::buildBuildableActions(), CommonOutputAction::create(), MaterialOutputAction::createAction(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), SetupDebugAction::createOutputAction(), reg(), and Parser::walkRaw().

29 {
30  parameters.addPrivateParam("_moose_app", &_app);
31  parameters.addPrivateParam("action_type", action);
32  std::pair<ActionFactory::iterator, ActionFactory::iterator> iters;
33  BuildInfo * build_info = NULL;
34 
35  // Check to make sure that all required parameters are supplied
36  parameters.checkParams(action_name);
37 
38  iters = _name_to_build_info.equal_range(action);
39 
40  // Find the Action that matches the one we have registered based on unique_id
41  unsigned short count = 0;
42  for (ActionFactory::iterator it = iters.first; it != iters.second; ++it)
43  {
44  ++count;
45  if (parameters.have_parameter<unsigned int>("unique_id") &&
46  it->second._unique_id == parameters.get<unsigned int>("unique_id"))
47  {
48  build_info = &(it->second);
49  break;
50  }
51  }
52  // For backwards compatibility - If there is only one Action registered but it doesn't contain a
53  // unique_id that
54  // matches, then surely it must still be the correct one
55  if (count == 1 && !build_info)
56  build_info = &(iters.first->second);
57 
58  if (!build_info)
59  mooseError(
60  std::string("Unable to find buildable Action from supplied InputParameters Object for ") +
61  action_name);
62 
63  // Add the name to the parameters and create the object
64  parameters.set<std::string>("_action_name") = action_name;
65  std::shared_ptr<Action> action_obj = (*build_info->_build_pointer)(parameters);
66 
67  if (parameters.get<std::string>("task") == "")
68  action_obj->appendTask(build_info->_task);
69 
70  return action_obj;
71 }
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...
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
std::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
MooseApp & _app
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...
std::multimap< std::string, BuildInfo > _name_to_build_info
ActionFactory::iterator ActionFactory::end ( )

Definition at line 119 of file ActionFactory.C.

120 {
121  return _name_to_build_info.end();
122 }
std::multimap< std::string, BuildInfo > _name_to_build_info
ActionFactory::const_iterator ActionFactory::end ( ) const

Definition at line 125 of file ActionFactory.C.

126 {
127  return _name_to_build_info.end();
128 }
std::multimap< std::string, BuildInfo > _name_to_build_info
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > ActionFactory::getActionsByTask ( const std::string &  task) const

Definition at line 132 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions().

133 {
134  return _task_to_action_map.equal_range(task);
135 }
std::multimap< std::string, std::string > _task_to_action_map
FileLineInfo ActionFactory::getLineInfo ( const std::string &  name,
const std::string &  task 
) const

Gets file and line information where an action was registered.

Parameters
nameAction name
tasktask name
Returns
A FileLineInfo associated with the name/task pair

Definition at line 153 of file ActionFactory.C.

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

154 {
155  return _name_to_line.getInfo(name, task);
156 }
FileLineInfoMap _name_to_line
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:81
std::string ActionFactory::getTaskName ( const std::string &  action)

Definition at line 95 of file ActionFactory.C.

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

96 {
97  // We are returning only the first found instance here
98  std::multimap<std::string, BuildInfo>::iterator iter = _name_to_build_info.find(action);
99 
100  if (iter != _name_to_build_info.end())
101  return iter->second._task;
102  else
103  return "";
104 }
std::multimap< std::string, BuildInfo > _name_to_build_info
std::set< std::string > ActionFactory::getTasksByAction ( const std::string &  action) const

Definition at line 138 of file ActionFactory.C.

Referenced by ActionWarehouse::addActionBlock(), and Parser::buildJsonSyntaxTree().

139 {
140  std::set<std::string> tasks;
141 
142  std::pair<std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator,
143  std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator>
144  iters = _name_to_build_info.equal_range(action);
145  for (std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator it = iters.first;
146  it != iters.second;
147  ++it)
148  tasks.insert(it->second._task);
149 
150  return tasks;
151 }
std::multimap< std::string, BuildInfo > _name_to_build_info
InputParameters ActionFactory::getValidParams ( const std::string &  name)

If an Action is registered more than once, it'll appear in the _name_to_build_info data structure multiple times. The actual parameters function remains the same however so we can safely use the first instance

Definition at line 74 of file ActionFactory.C.

Referenced by DetermineSystemType::act(), ActionWarehouse::buildBuildableActions(), Parser::buildFullTree(), Parser::buildJsonSyntaxTree(), MaterialOutputAction::createAction(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), Parser::listValidParams(), reg(), and Parser::walkRaw().

75 {
82 
83  if (iter == _name_to_build_info.end())
84  mooseError(std::string("A '") + name + "' is not a registered Action\n\n");
85 
86  InputParameters params = (iter->second._params_pointer)();
87  params.addPrivateParam<unsigned int>("unique_id", iter->second._unique_id);
88  params.addPrivateParam("_moose_app", &_app);
90 
91  return params;
92 }
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...
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
Storage for action instances.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
MooseApp & _app
ActionWarehouse & actionWarehouse()
Definition: MooseApp.h:130
std::multimap< std::string, BuildInfo > _name_to_build_info
template<typename T >
void ActionFactory::reg ( const std::string &  name,
const std::string &  task,
const std::string &  file = "",
int  line = -1 
)
inline

Definition at line 78 of file ActionFactory.h.

82  {
83  BuildInfo build_info;
84  build_info._build_pointer = &buildAction<T>;
85  build_info._params_pointer = &validParams<T>;
86  build_info._task = task;
87  build_info._unique_id = _unique_id++;
88  _name_to_build_info.insert(std::make_pair(name, build_info));
89  _task_to_action_map.insert(std::make_pair(task, name));
90  _name_to_line.addInfo(name, task, file, line);
91  }
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:40
FileLineInfoMap _name_to_line
std::multimap< std::string, BuildInfo > _name_to_build_info
std::multimap< std::string, std::string > _task_to_action_map
static unsigned int _unique_id
Unique ID for identifying multiple registrations.

Member Data Documentation

MooseApp& ActionFactory::_app
protected

Definition at line 134 of file ActionFactory.h.

Referenced by create(), and getValidParams().

std::multimap<std::string, BuildInfo> ActionFactory::_name_to_build_info
protected

Definition at line 136 of file ActionFactory.h.

Referenced by begin(), create(), end(), getTaskName(), getTasksByAction(), getValidParams(), and reg().

FileLineInfoMap ActionFactory::_name_to_line
protected

Definition at line 138 of file ActionFactory.h.

Referenced by getLineInfo(), and reg().

std::multimap<std::string, std::string> ActionFactory::_task_to_action_map
protected

Definition at line 139 of file ActionFactory.h.

Referenced by getActionsByTask(), and reg().

unsigned int ActionFactory::_unique_id = 0
staticprotected

Unique ID for identifying multiple registrations.

Definition at line 142 of file ActionFactory.h.

Referenced by reg().


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