https://mooseframework.inl.gov
ActionFactory.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include <vector>
13 #include <map>
14 #include <set>
15 
16 #include "Action.h" // Technically required for std::shared_ptr<Action>(Action*) constructor
17 #include "InputParameters.h"
18 #include "FileLineInfo.h"
19 
23 #define registerSyntax(action, action_syntax) \
24  syntax.registerActionSyntax(action, action_syntax, "", __FILE__, __LINE__)
25 #define registerSyntaxTask(action, action_syntax, task) \
26  syntax.registerActionSyntax(action, action_syntax, task, __FILE__, __LINE__)
27 #define registerDeprecatedSyntax(action, action_syntax, message) \
28  syntax.registerActionSyntax(action, action_syntax, "", __FILE__, __LINE__); \
29  syntax.deprecateActionSyntax(action_syntax, message)
30 #define registerDeprecatedSyntaxTask(action, action_syntax, task, message) \
31  syntax.registerActionSyntax(action, action_syntax, task, __FILE__, __LINE__); \
32  syntax.deprecateActionSyntax(action_syntax, message)
33 #define registerTask(name, is_required) syntax.registerTaskName(name, is_required)
34 #define registerMooseObjectTask(name, moose_system, is_required) \
35  syntax.registerTaskName(name, stringifyName(moose_system), is_required)
36 #define appendMooseObjectTask(name, moose_system) \
37  syntax.appendTaskName(name, stringifyName(moose_system), false)
38 #define appendDeprecatedMooseObjectTask(name, moose_system) \
39  syntax.appendTaskName(name, stringifyName(moose_system), true)
40 #define addTaskDependency(action, depends_on) syntax.addDependency(action, depends_on)
41 
42 // Forward Declaration
43 class MooseApp;
44 
49 {
50 public:
52 
53  virtual ~ActionFactory();
54 
55  MooseApp & app() { return _app; }
56 
57  void reg(std::shared_ptr<RegistryEntryBase> obj);
58 
65  FileLineInfo getLineInfo(const std::string & name, const std::string & task) const;
66 
67  std::string getTaskName(const std::string & action);
68 
69  std::shared_ptr<Action>
70  create(const std::string & action, const std::string & action_name, InputParameters & parameters);
71 
72  InputParameters getValidParams(const std::string & name);
73 
74  struct BuildInfo
75  {
76  std::shared_ptr<RegistryEntryBase> _obj_pointer;
77  std::string _task;
78  };
79 
81  typedef std::multimap<std::string, BuildInfo>::iterator iterator;
82  typedef std::multimap<std::string, BuildInfo>::const_iterator const_iterator;
83 
84  iterator begin();
85  const_iterator begin() const;
86 
87  iterator end();
88  const_iterator end() const;
89 
91  std::pair<std::multimap<std::string, std::string>::const_iterator,
92  std::multimap<std::string, std::string>::const_iterator>
93  getActionsByTask(const std::string & task) const;
94 
95  std::set<std::string> getTasksByAction(const std::string & action) const;
96 
100  bool isRegisteredTask(const std::string & task) const { return _tasks.count(task); }
101 
108  const InputParameters * currentlyConstructing() const;
109 
110 private:
111  template <class T>
112  static std::shared_ptr<Action> buildAction(const InputParameters & parameters)
113  {
114  return std::make_shared<T>(parameters);
115  }
116 
118 
119  std::multimap<std::string, BuildInfo> _name_to_build_info;
120 
122  std::multimap<std::string, std::string> _task_to_action_map;
123 
125  std::set<std::pair<std::string, std::string>> _current_objs;
126 
128  std::set<std::string> _tasks;
129 
133  std::vector<const InputParameters *> _currently_constructing;
134 };
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:94
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > getActionsByTask(const std::string &task) const
Returns begin and end iterators in a multimap from tasks to actions names.
std::set< std::string > getTasksByAction(const std::string &action) const
void reg(std::shared_ptr< RegistryEntryBase > obj)
Definition: ActionFactory.C:22
iterator end()
Base class for MOOSE-based applications.
Definition: MooseApp.h:103
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
FileLineInfo getLineInfo(const std::string &name, const std::string &task) const
Gets file and line information where an action was registered.
virtual ~ActionFactory()
Definition: ActionFactory.C:19
std::set< std::string > _tasks
The registered tasks.
static std::shared_ptr< Action > buildAction(const InputParameters &parameters)
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
Definition: ActionFactory.C:40
std::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
Definition: ActionFactory.h:81
MooseApp & _app
FileLineInfoMap _name_to_line
std::shared_ptr< RegistryEntryBase > _obj_pointer
Definition: ActionFactory.h:76
iterator begin()
ActionFactory(MooseApp &app)
Definition: ActionFactory.C:17
bool isRegisteredTask(const std::string &task) const
Whether or not a task with the name task is registered.
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 ...
Specialized factory for generic Action System objects.
Definition: ActionFactory.h:48
std::multimap< std::string, BuildInfo >::const_iterator const_iterator
Definition: ActionFactory.h:82
std::vector< const InputParameters * > _currently_constructing
The object&#39;s parameters that are currently being constructed (if any).
Holds file and line information.
Definition: FileLineInfo.h:18
std::multimap< std::string, BuildInfo > _name_to_build_info
std::string getTaskName(const std::string &action)
std::multimap< std::string, std::string > _task_to_action_map
const InputParameters * currentlyConstructing() const
MooseApp & app()
Definition: ActionFactory.h:55
A mapping between a series of keys to a FileLineInfo.
Definition: FileLineInfo.h:40