LCOV - code coverage report
Current view: top level - include/actions - ActionFactory.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 1 1 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : /**
      21             :  * Macros
      22             :  */
      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             : 
      47             : /**
      48             :  * Specialized factory for generic Action System objects
      49             :  */
      50             : class ActionFactory
      51             : {
      52             : public:
      53             :   ActionFactory(MooseApp & app);
      54             : 
      55             :   virtual ~ActionFactory();
      56             : 
      57             :   MooseApp & app() { return _app; }
      58             : 
      59             :   void reg(std::shared_ptr<RegistryEntryBase> obj);
      60             : 
      61             :   /**
      62             :    * Gets file and line information where an action was registered.
      63             :    * @param name Action name
      64             :    * @param task task name
      65             :    * @return A FileLineInfo associated with the name/task pair
      66             :    */
      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             : 
      82             :   /// Typedef for registered Action iterator
      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             :   /// Returns begin and end iterators in a multimap from tasks to actions names
      93             :   std::pair<std::multimap<std::string, std::string>::const_iterator,
      94             :             std::multimap<std::string, std::string>::const_iterator>
      95             :   getActionsByTask(const std::string & task) const;
      96             : 
      97             :   std::set<std::string> getTasksByAction(const std::string & action) const;
      98             : 
      99             :   /**
     100             :    * Whether or not a task with the name \p task is registered.
     101             :    */
     102      163599 :   bool isRegisteredTask(const std::string & task) const { return _tasks.count(task); }
     103             : 
     104             :   /**
     105             :    * @return The InputParameters for the object that is currently being constructed,
     106             :    * if any.
     107             :    *
     108             :    * Can be used to ensure that all Actions are created using the ActionFactory
     109             :    */
     110             :   const InputParameters * currentlyConstructing() const;
     111             : 
     112             : private:
     113             :   template <class T>
     114             :   static std::shared_ptr<Action> buildAction(const InputParameters & parameters)
     115             :   {
     116             :     return std::make_shared<T>(parameters);
     117             :   }
     118             : 
     119             :   MooseApp & _app;
     120             : 
     121             :   std::multimap<std::string, BuildInfo> _name_to_build_info;
     122             : 
     123             :   FileLineInfoMap _name_to_line;
     124             :   std::multimap<std::string, std::string> _task_to_action_map;
     125             : 
     126             :   /// set<objectname, task> used to track if an object previously added is being added again
     127             :   std::set<std::pair<std::string, std::string>> _current_objs;
     128             : 
     129             :   /// The registered tasks
     130             :   std::set<std::string> _tasks;
     131             : 
     132             :   /// The object's parameters that are currently being constructed (if any).
     133             :   /// This is a vector because we create within create, thus the last entry is the
     134             :   /// one that is being constructed at the moment
     135             :   std::vector<const InputParameters *> _currently_constructing;
     136             : };

Generated by: LCOV version 1.14