LCOV - code coverage report
Current view: top level - include/base - Capabilities.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 4 4 100.0 %
Date: 2026-05-29 20:35:17 Functions: 4 4 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 "CapabilityRegistry.h"
      13             : 
      14             : #include "nlohmann/json_fwd.h"
      15             : 
      16             : #ifdef MOOSE_UNIT_TEST
      17             : // forward declare unit tests
      18             : #include "gtest/gtest.h"
      19             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, augment);
      20             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, augmentParseError);
      21             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, check);
      22             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, dump);
      23             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, isInstallationType);
      24             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, mooseAppCheckCapabilities);
      25             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, mooseAppCheckRequiredCapabilities);
      26             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, mooseAppIsRelocated);
      27             : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, mooseAppisInTree);
      28             : class GTEST_TEST_CLASS_NAME_(RegistryTest, addDataFilePath);
      29             : class GTEST_TEST_CLASS_NAME_(RegistryTest, addMissingDataFilePath);
      30             : class CapabilitiesTest;
      31             : class DataFileUtilsTest;
      32             : class RegistryTest;
      33             : #endif
      34             : 
      35             : class AppFactory;
      36             : class Registry;
      37             : class MooseApp;
      38             : 
      39             : namespace Moose::internal
      40             : {
      41             : 
      42             : /**
      43             :  * Holds the public (to MooseApp) facing CapabilityRegistry for storing and checking capabilities.
      44             :  *
      45             :  * A capability can refer to an optional library or optional functionality. Capabilities
      46             :  * can either be registered as boolean values (present or not), an integer quantity (like
      47             :  * the AD backing store size), a string (like the compiler used to build the executable),
      48             :  * or a version number (numbers separated by dots, e.g. the petsc version).
      49             :  */
      50             : class Capabilities : public CapabilityRegistry
      51             : {
      52             : public:
      53             :   /// Passkey for get()
      54             :   class GetCapabilitiesPassKey
      55             :   {
      56             :     friend AppFactory;
      57             :     friend MooseApp;
      58             :     friend Registry;
      59             : #ifdef MOOSE_UNIT_TEST
      60             :     friend class ::CapabilitiesTest;
      61             :     friend class ::DataFileUtilsTest;
      62             :     friend class ::RegistryTest;
      63             :     FRIEND_TEST(::CapabilitiesTest, augment);
      64             :     FRIEND_TEST(::CapabilitiesTest, augmentParseError);
      65             :     FRIEND_TEST(::CapabilitiesTest, check);
      66             :     FRIEND_TEST(::CapabilitiesTest, dump);
      67             :     FRIEND_TEST(::CapabilitiesTest, isInstallationType);
      68             :     FRIEND_TEST(::CapabilitiesTest, mooseAppCheckCapabilities);
      69             :     FRIEND_TEST(::CapabilitiesTest, mooseAppCheckRequiredCapabilities);
      70             :     FRIEND_TEST(::RegistryTest, addDataFilePath);
      71             :     FRIEND_TEST(::RegistryTest, addMissingDataFilePath);
      72             : #endif
      73      636506 :     GetCapabilitiesPassKey() {}
      74             :     GetCapabilitiesPassKey(const GetCapabilitiesPassKey &) {}
      75             :   };
      76             : 
      77             :   /**
      78             :    * Get the singleton Capabilities.
      79             :    *
      80             :    * Only accessible through MooseApp and AppFactory. Addition
      81             :    * of capabilities should be done through the
      82             :    * MooseApp::add[Bool,Int,String]capability() method.
      83             :    */
      84             :   static Capabilities & getCapabilities(const GetCapabilitiesPassKey);
      85             : 
      86             :   /// create a JSON dump of the capabilities registry
      87             :   std::string dump() const;
      88             : 
      89             :   /// Passkey for augment()
      90             :   class AugmentPassKey
      91             :   {
      92             :     friend MooseApp;
      93             : #ifdef MOOSE_UNIT_TEST
      94             :     FRIEND_TEST(::CapabilitiesTest, augment);
      95             :     FRIEND_TEST(::CapabilitiesTest, augmentParseError);
      96             : #endif
      97         389 :     AugmentPassKey() {}
      98             :     AugmentPassKey(const AugmentPassKey &) {}
      99             :   };
     100             : 
     101             :   /**
     102             :    * Augment the capabilities with the given input capabilities.
     103             :    *
     104             :    * This is used when loading additional capabilities at run time
     105             :    * from the TestHarness and thus is only allowed to be used by
     106             :    * the MooseApp.
     107             :    */
     108             :   void augment(const nlohmann::json & input, const AugmentPassKey);
     109             : 
     110             :   ///@{ Don't allow creation through copy/move construction or assignment
     111             :   Capabilities(Capabilities const &) = delete;
     112             :   Capabilities & operator=(Capabilities const &) = delete;
     113             : 
     114             :   Capabilities(Capabilities &&) = delete;
     115             :   Capabilities & operator=(Capabilities &&) = delete;
     116             :   ///@}
     117             : 
     118             :   /**
     119             :    * @return Whether or not the application is relocated
     120             :    */
     121          18 :   bool isRelocated() const { return isInstallationType("relocated"); }
     122             : 
     123             :   /**
     124             :    * @return Whether or not the application is in-tree
     125             :    */
     126          18 :   bool isInTree() const { return isInstallationType("in_tree"); }
     127             : 
     128             : private:
     129             : #ifdef MOOSE_UNIT_TEST
     130             :   friend class ::CapabilitiesTest;
     131             :   friend class ::DataFileUtilsTest;
     132             :   friend class ::RegistryTest;
     133             :   FRIEND_TEST(::CapabilitiesTest, isInstallationType);
     134             :   FRIEND_TEST(::CapabilitiesTest, mooseAppIsRelocated);
     135             :   FRIEND_TEST(::CapabilitiesTest, mooseAppisInTree);
     136             : #endif
     137             : 
     138             :   /**
     139             :    * Helper for isRelocated() and isInTree()
     140             :    */
     141             :   bool isInstallationType(const std::string & installation_type) const;
     142             : 
     143             :   /**
     144             :    * Register the MOOSE capabilities.
     145             :    *
     146             :    * Called during the construction of the registry.
     147             :    *
     148             :    * Putting this here enforces that only capabilities that
     149             :    * represent context _before_ the app is constructed
     150             :    * can be added.
     151             :    */
     152             :   void registerMooseCapabilities();
     153             : 
     154             :   // Private constructor for singleton pattern
     155             :   Capabilities();
     156             : };
     157             : 
     158             : } // namespace Moose::internal

Generated by: LCOV version 1.14