forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionFactory.C
162 lines (136 loc) · 5.05 KB
/
ActionFactory.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
// MOOSE includes
#include "ActionFactory.h"
#include "MooseApp.h"
#include "InputParameterWarehouse.h"
#include "MooseObjectAction.h"
ActionFactory::ActionFactory(MooseApp & app) : _app(app) {}
ActionFactory::~ActionFactory() {}
void
ActionFactory::reg(const std::string & name,
const std::string & task,
buildActionPtr obj_builder,
paramsActionPtr ref_params,
const std::string & file,
int line)
{
auto key = std::make_pair(name, task);
if (_current_objs.count(key) > 0)
return;
_current_objs.insert(key);
BuildInfo build_info;
build_info._build_pointer = obj_builder;
build_info._params_pointer = ref_params;
build_info._task = task;
_name_to_build_info.insert(std::make_pair(name, build_info));
_task_to_action_map.insert(std::make_pair(task, name));
_tasks.insert(task);
_name_to_line.addInfo(name, task, file, line);
}
std::shared_ptr<Action>
ActionFactory::create(const std::string & action,
const std::string & full_action_name,
InputParameters & incoming_parser_params)
{
std::string action_name = MooseUtils::shortName(full_action_name);
incoming_parser_params.addPrivateParam("_moose_app", &_app);
incoming_parser_params.addPrivateParam("action_type", action);
std::pair<ActionFactory::iterator, ActionFactory::iterator> iters;
std::string unique_action_name =
action + incoming_parser_params.get<std::string>("task") + full_action_name;
// Create the actual parameters object that the object will reference
InputParameters & action_params = _app.getInputParameterWarehouse().addInputParameters(
unique_action_name, incoming_parser_params);
// Check to make sure that all required parameters are supplied
action_params.checkParams(action_name);
iters = _name_to_build_info.equal_range(action);
BuildInfo * build_info = &(iters.first->second);
if (!build_info)
mooseError(
std::string("Unable to find buildable Action from supplied InputParameters Object for ") +
action_name);
// Add the name to the parameters and create the object
action_params.set<std::string>("_action_name") = action_name;
action_params.set<std::string>("_unique_action_name") = unique_action_name;
std::shared_ptr<Action> action_obj = (*build_info->_build_pointer)(action_params);
if (action_params.get<std::string>("task") == "")
action_obj->appendTask(build_info->_task);
return action_obj;
}
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
*/
ActionFactory::iterator iter = _name_to_build_info.find(name);
if (iter == _name_to_build_info.end())
mooseError(std::string("A '") + name + "' is not a registered Action\n\n");
InputParameters params = (iter->second._params_pointer)();
params.addPrivateParam("_moose_app", &_app);
params.addPrivateParam<ActionWarehouse *>("awh", &_app.actionWarehouse());
return params;
}
std::string
ActionFactory::getTaskName(const std::string & action)
{
// We are returning only the first found instance here
std::multimap<std::string, BuildInfo>::iterator iter = _name_to_build_info.find(action);
if (iter != _name_to_build_info.end())
return iter->second._task;
else
return "";
}
ActionFactory::iterator
ActionFactory::begin()
{
return _name_to_build_info.begin();
}
ActionFactory::const_iterator
ActionFactory::begin() const
{
return _name_to_build_info.begin();
}
ActionFactory::iterator
ActionFactory::end()
{
return _name_to_build_info.end();
}
ActionFactory::const_iterator
ActionFactory::end() const
{
return _name_to_build_info.end();
}
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
{
return _task_to_action_map.equal_range(task);
}
std::set<std::string>
ActionFactory::getTasksByAction(const std::string & action) const
{
std::set<std::string> tasks;
std::pair<std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator,
std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator>
iters = _name_to_build_info.equal_range(action);
for (std::multimap<std::string, ActionFactory::BuildInfo>::const_iterator it = iters.first;
it != iters.second;
++it)
tasks.insert(it->second._task);
return tasks;
}
FileLineInfo
ActionFactory::getLineInfo(const std::string & name, const std::string & task) const
{
return _name_to_line.getInfo(name, task);
}