www.mooseframework.org
Classes | Public Types | Public Member Functions | 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 ()
 
MooseAppapp ()
 
template<typename T >
void reg (const std::string &name, const std::string &task, const std::string &file="", int line=-1)
 
void reg (const std::string &name, const std::string &task, buildActionPtr obj_builder, paramsActionPtr ref_params, 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
 
std::set< std::pair< std::string, std::string > > _current_objs
 set<objectname, task> used to track if an object previously added is being added again More...
 

Detailed Description

Specialized factory for generic Action System objects.

Definition at line 65 of file ActionFactory.h.

Member Typedef Documentation

◆ const_iterator

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

Definition at line 115 of file ActionFactory.h.

◆ iterator

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

Typedef for registered Action iterator.

Definition at line 114 of file ActionFactory.h.

Constructor & Destructor Documentation

◆ ActionFactory()

ActionFactory::ActionFactory ( MooseApp app)

Definition at line 14 of file ActionFactory.C.

14 : _app(app) {}
MooseApp & _app
MooseApp & app()
Definition: ActionFactory.h:72

◆ ~ActionFactory()

ActionFactory::~ActionFactory ( )
virtual

Definition at line 16 of file ActionFactory.C.

16 {}

Member Function Documentation

◆ app()

MooseApp& ActionFactory::app ( )
inline

Definition at line 72 of file ActionFactory.h.

72 { return _app; }
MooseApp & _app

◆ begin() [1/2]

ActionFactory::iterator ActionFactory::begin ( )

Definition at line 102 of file ActionFactory.C.

103 {
104  return _name_to_build_info.begin();
105 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ begin() [2/2]

ActionFactory::const_iterator ActionFactory::begin ( ) const

Definition at line 108 of file ActionFactory.C.

109 {
110  return _name_to_build_info.begin();
111 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ create()

std::shared_ptr< Action > ActionFactory::create ( const std::string &  action,
const std::string &  action_name,
InputParameters  parameters 
)

Definition at line 41 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions(), CommonOutputAction::create(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), and Parser::walkRaw().

44 {
45  parameters.addPrivateParam("_moose_app", &_app);
46  parameters.addPrivateParam("action_type", action);
47  std::pair<ActionFactory::iterator, ActionFactory::iterator> iters;
48 
49  // Check to make sure that all required parameters are supplied
50  parameters.checkParams(action_name);
51 
52  iters = _name_to_build_info.equal_range(action);
53  BuildInfo * build_info = &(iters.first->second);
54  if (!build_info)
55  mooseError(
56  std::string("Unable to find buildable Action from supplied InputParameters Object for ") +
57  action_name);
58 
59  // Add the name to the parameters and create the object
60  parameters.set<std::string>("_action_name") = action_name;
61  std::shared_ptr<Action> action_obj = (*build_info->_build_pointer)(parameters);
62 
63  if (parameters.get<std::string>("task") == "")
64  action_obj->appendTask(build_info->_task);
65 
66  return action_obj;
67 }
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:208
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
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

◆ end() [1/2]

ActionFactory::iterator ActionFactory::end ( )

Definition at line 114 of file ActionFactory.C.

115 {
116  return _name_to_build_info.end();
117 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ end() [2/2]

ActionFactory::const_iterator ActionFactory::end ( ) const

Definition at line 120 of file ActionFactory.C.

121 {
122  return _name_to_build_info.end();
123 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getActionsByTask()

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 127 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions().

128 {
129  return _task_to_action_map.equal_range(task);
130 }
std::multimap< std::string, std::string > _task_to_action_map

◆ getLineInfo()

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 148 of file ActionFactory.C.

Referenced by Parser::buildJsonSyntaxTree().

149 {
150  return _name_to_line.getInfo(name, task);
151 }
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:76
FileLineInfoMap _name_to_line

◆ getTaskName()

std::string ActionFactory::getTaskName ( const std::string &  action)

Definition at line 90 of file ActionFactory.C.

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

91 {
92  // We are returning only the first found instance here
93  std::multimap<std::string, BuildInfo>::iterator iter = _name_to_build_info.find(action);
94 
95  if (iter != _name_to_build_info.end())
96  return iter->second._task;
97  else
98  return "";
99 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getTasksByAction()

std::set< std::string > ActionFactory::getTasksByAction ( const std::string &  action) const

Definition at line 133 of file ActionFactory.C.

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

134 {
135  std::set<std::string> tasks;
136 
137  std::pair<std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator,
138  std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator>
139  iters = _name_to_build_info.equal_range(action);
140  for (std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator it = iters.first;
141  it != iters.second;
142  ++it)
143  tasks.insert(it->second._task);
144 
145  return tasks;
146 }
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ getValidParams()

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 70 of file ActionFactory.C.

Referenced by ActionWarehouse::buildBuildableActions(), Parser::buildFullTree(), Parser::buildJsonSyntaxTree(), AddVariableAction::createInitialConditionAction(), MooseApp::createMinimalApp(), Parser::listValidParams(), and Parser::walkRaw().

71 {
78 
79  if (iter == _name_to_build_info.end())
80  mooseError(std::string("A '") + name + "' is not a registered Action\n\n");
81 
82  InputParameters params = (iter->second._params_pointer)();
83  params.addPrivateParam("_moose_app", &_app);
85 
86  return params;
87 }
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:208
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:139
std::multimap< std::string, BuildInfo > _name_to_build_info

◆ reg() [1/2]

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 75 of file ActionFactory.h.

Referenced by Registry::registerActionsTo().

79  {
80  reg(name, task, &buildAction<T>, &validParams<T>, file, line);
81  }
void reg(const std::string &name, const std::string &task, const std::string &file="", int line=-1)
Definition: ActionFactory.h:75

◆ reg() [2/2]

void ActionFactory::reg ( const std::string &  name,
const std::string &  task,
buildActionPtr  obj_builder,
paramsActionPtr  ref_params,
const std::string &  file = "",
int  line = -1 
)

Definition at line 19 of file ActionFactory.C.

25 {
26  auto key = std::make_pair(name, task);
27  if (_current_objs.count(key) > 0)
28  return;
29  _current_objs.insert(key);
30 
31  BuildInfo build_info;
32  build_info._build_pointer = obj_builder;
33  build_info._params_pointer = ref_params;
34  build_info._task = task;
35  _name_to_build_info.insert(std::make_pair(name, build_info));
36  _task_to_action_map.insert(std::make_pair(task, name));
37  _name_to_line.addInfo(name, task, file, line);
38 }
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:35
FileLineInfoMap _name_to_line
std::set< std::pair< std::string, std::string > > _current_objs
set<objectname, task> used to track if an object previously added is being added again ...
std::multimap< std::string, BuildInfo > _name_to_build_info
std::multimap< std::string, std::string > _task_to_action_map

Member Data Documentation

◆ _app

MooseApp& ActionFactory::_app
protected

Definition at line 130 of file ActionFactory.h.

Referenced by app(), create(), and getValidParams().

◆ _current_objs

std::set<std::pair<std::string, std::string> > ActionFactory::_current_objs
protected

set<objectname, task> used to track if an object previously added is being added again

Definition at line 138 of file ActionFactory.h.

Referenced by reg().

◆ _name_to_build_info

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

Definition at line 132 of file ActionFactory.h.

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

◆ _name_to_line

FileLineInfoMap ActionFactory::_name_to_line
protected

Definition at line 134 of file ActionFactory.h.

Referenced by getLineInfo(), and reg().

◆ _task_to_action_map

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

Definition at line 135 of file ActionFactory.h.

Referenced by getActionsByTask(), and reg().


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