www.mooseframework.org
ActionFactory.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 stringifyName(name) #name
24 
25 #define registerSyntax(action, action_syntax) \
26  syntax.registerActionSyntax(action, action_syntax, "", __FILE__, __LINE__)
27 #define registerSyntaxTask(action, action_syntax, task) \
28  syntax.registerActionSyntax(action, action_syntax, task, __FILE__, __LINE__)
29 #define registerDeprecatedSyntax(action, action_syntax, message) \
30  syntax.registerActionSyntax(action, action_syntax, "", __FILE__, __LINE__); \
31  syntax.deprecateActionSyntax(action_syntax, message)
32 #define registerDeprecatedSyntaxTask(action, action_syntax, task, message) \
33  syntax.registerActionSyntax(action, action_syntax, task, __FILE__, __LINE__); \
34  syntax.deprecateActionSyntax(action_syntax, message)
35 #define registerTask(name, is_required) syntax.registerTaskName(name, is_required)
36 #define registerMooseObjectTask(name, moose_system, is_required) \
37  syntax.registerTaskName(name, stringifyName(moose_system), is_required)
38 #define appendMooseObjectTask(name, moose_system) \
39  syntax.appendTaskName(name, stringifyName(moose_system), false)
40 #define appendDeprecatedMooseObjectTask(name, moose_system) \
41  syntax.appendTaskName(name, stringifyName(moose_system), true)
42 #define addTaskDependency(action, depends_on) syntax.addDependency(action, depends_on)
43 
44 // Forward Declaration
45 class MooseApp;
46 
51 {
52 public:
54 
55  virtual ~ActionFactory();
56 
57  MooseApp & app() { return _app; }
58 
59  void reg(std::shared_ptr<RegistryEntryBase> obj);
60 
67  FileLineInfo getLineInfo(const std::string & name, const std::string & task) const;
68 
69  std::string getTaskName(const std::string & action);
70 
71  std::shared_ptr<Action>
72  create(const std::string & action, const std::string & action_name, InputParameters & parameters);
73 
74  InputParameters getValidParams(const std::string & name);
75 
76  struct BuildInfo
77  {
78  std::shared_ptr<RegistryEntryBase> _obj_pointer;
79  std::string _task;
80  };
81 
83  typedef std::multimap<std::string, BuildInfo>::iterator iterator;
84  typedef std::multimap<std::string, BuildInfo>::const_iterator const_iterator;
85 
86  iterator begin();
87  const_iterator begin() const;
88 
89  iterator end();
90  const_iterator end() const;
91 
92  std::pair<std::multimap<std::string, std::string>::const_iterator,
93  std::multimap<std::string, std::string>::const_iterator>
94  getActionsByTask(const std::string & task) const;
95 
96  std::set<std::string> getTasksByAction(const std::string & action) const;
97 
101  bool isRegisteredTask(const std::string & task) const { return _tasks.count(task); }
102 
109  const InputParameters * currentlyConstructing() const;
110 
111 private:
112  template <class T>
113  static std::shared_ptr<Action> buildAction(const InputParameters & parameters)
114  {
115  return std::make_shared<T>(parameters);
116  }
117 
119 
120  std::multimap<std::string, BuildInfo> _name_to_build_info;
121 
123  std::multimap<std::string, std::string> _task_to_action_map;
124 
126  std::set<std::pair<std::string, std::string>> _current_objs;
127 
129  std::set<std::string> _tasks;
130 
134  std::vector<const InputParameters *> _currently_constructing;
135 };
InputParameters getValidParams(const std::string &name)
Definition: ActionFactory.C:92
std::pair< std::multimap< std::string, std::string >::const_iterator, std::multimap< std::string, std::string >::const_iterator > getActionsByTask(const std::string &task) const
std::set< std::string > getTasksByAction(const std::string &action) const
void reg(std::shared_ptr< RegistryEntryBase > obj)
Definition: ActionFactory.C:21
iterator end()
Base class for MOOSE-based applications.
Definition: MooseApp.h:73
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:18
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:39
std::multimap< std::string, BuildInfo >::iterator iterator
Typedef for registered Action iterator.
Definition: ActionFactory.h:83
MooseApp & _app
FileLineInfoMap _name_to_line
std::shared_ptr< RegistryEntryBase > _obj_pointer
Definition: ActionFactory.h:78
iterator begin()
ActionFactory(MooseApp &app)
Definition: ActionFactory.C:16
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:50
std::multimap< std::string, BuildInfo >::const_iterator const_iterator
Definition: ActionFactory.h:84
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:57
A mapping between a series of keys to a FileLineInfo.
Definition: FileLineInfo.h:40