LCOV - code coverage report
Current view: top level - include/actions - ActionFactory.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31730 (e8b711) with base e0c998 Lines: 1 1 100.0 %
Date: 2025-10-29 16:49:47 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 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             : 
      45             : /**
      46             :  * Specialized factory for generic Action System objects
      47             :  */
      48             : class ActionFactory
      49             : {
      50             : public:
      51             :   ActionFactory(MooseApp & app);
      52             : 
      53             :   virtual ~ActionFactory();
      54             : 
      55             :   MooseApp & app() { return _app; }
      56             : 
      57             :   void reg(std::shared_ptr<RegistryEntryBase> obj);
      58             : 
      59             :   /**
      60             :    * Gets file and line information where an action was registered.
      61             :    * @param name Action name
      62             :    * @param task task name
      63             :    * @return A FileLineInfo associated with the name/task pair
      64             :    */
      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             : 
      80             :   /// Typedef for registered Action iterator
      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             : 
      90             :   /// Returns begin and end iterators in a multimap from tasks to actions names
      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             : 
      97             :   /**
      98             :    * Whether or not a task with the name \p task is registered.
      99             :    */
     100      220757 :   bool isRegisteredTask(const std::string & task) const { return _tasks.count(task); }
     101             : 
     102             :   /**
     103             :    * @return The InputParameters for the object that is currently being constructed,
     104             :    * if any.
     105             :    *
     106             :    * Can be used to ensure that all Actions are created using the ActionFactory
     107             :    */
     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             : 
     117             :   MooseApp & _app;
     118             : 
     119             :   std::multimap<std::string, BuildInfo> _name_to_build_info;
     120             : 
     121             :   FileLineInfoMap _name_to_line;
     122             :   std::multimap<std::string, std::string> _task_to_action_map;
     123             : 
     124             :   /// set<objectname, task> used to track if an object previously added is being added again
     125             :   std::set<std::pair<std::string, std::string>> _current_objs;
     126             : 
     127             :   /// The registered tasks
     128             :   std::set<std::string> _tasks;
     129             : 
     130             :   /// The object's parameters that are currently being constructed (if any).
     131             :   /// This is a vector because we create within create, thus the last entry is the
     132             :   /// one that is being constructed at the moment
     133             :   std::vector<const InputParameters *> _currently_constructing;
     134             : };

Generated by: LCOV version 1.14