LCOV - code coverage report
Current view: top level - include/utils - SolutionInvalidityRegistry.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 12 12 100.0 %
Date: 2025-07-17 01:28:37 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 "GeneralRegistry.h"
      13             : #include "MooseTypes.h"
      14             : #include "MooseHashing.h"
      15             : 
      16             : #include <mutex>
      17             : 
      18             : // Forward Declarations
      19             : class SolutionInvalidity;
      20             : void dataStore(std::ostream &, SolutionInvalidity &, void *);
      21             : 
      22             : namespace moose::internal
      23             : {
      24             : class SolutionInvalidityRegistry;
      25             : 
      26             : /**
      27             :  * Get the global SolutionInvalidityRegistry singleton.
      28             :  */
      29             : SolutionInvalidityRegistry & getSolutionInvalidityRegistry();
      30             : 
      31             : /**
      32             :  * Helper class that stores the name associated with an invalid solution
      33             :  */
      34             : class SolutionInvalidityName
      35             : {
      36             : public:
      37        5915 :   SolutionInvalidityName(const std::string & object_type, const std::string & message)
      38        5915 :     : object_type(object_type), message(message)
      39             :   {
      40        5915 :   }
      41             : 
      42       10518 :   bool operator==(const SolutionInvalidityName & other) const
      43             :   {
      44       10518 :     return object_type == other.object_type && message == other.message;
      45             :   }
      46             : 
      47             :   /// The type of the object
      48             :   std::string object_type;
      49             :   /// The invalid message
      50             :   std::string message;
      51             : };
      52             : 
      53             : /**
      54             :  * Helper class that hash the name associated with an invalid solution
      55             :  */
      56             : struct SoltionInvalidityNameHash
      57             : {
      58       11011 :   inline size_t operator()(const SolutionInvalidityName & name) const
      59             :   {
      60       11011 :     size_t seed = 0;
      61       11011 :     Moose::hash_combine(seed, name.object_type, name.message);
      62       11011 :     return seed;
      63             :   }
      64             : };
      65             : 
      66             : std::ostream & operator<<(std::ostream & os, const SolutionInvalidityName & name);
      67             : 
      68             : /**
      69             :  * Helper class that stores the info associated with an invalid solution
      70             :  */
      71             : class SolutionInvalidityInfo : public SolutionInvalidityName
      72             : {
      73             : public:
      74         312 :   SolutionInvalidityInfo(const std::string & object_type,
      75             :                          const std::string & message,
      76             :                          const InvalidSolutionID id,
      77             :                          const bool warning)
      78         312 :     : SolutionInvalidityName(object_type, message), id(id), warning(warning)
      79             :   {
      80         312 :   }
      81             : 
      82             :   /// The solution ID
      83             :   InvalidSolutionID id;
      84             :   /// Whether or not this is a warning
      85             :   bool warning;
      86             : };
      87             : 
      88             : /**
      89             :  * The place where all sections with solution invalid warnings will be stored
      90             :  */
      91             : class SolutionInvalidityRegistry : public GeneralRegistry<SolutionInvalidityName,
      92             :                                                           SolutionInvalidityInfo,
      93             :                                                           SoltionInvalidityNameHash>
      94             : {
      95             : public:
      96             :   /**
      97             :    * Call to register an invalid calculation
      98             :    *
      99             :    * @param object_type The type of the object doing the registration
     100             :    * @param message The description of the solution invalid warning
     101             :    * @param warning Whether or not it is a warning
     102             :    * @return The registered ID
     103             :    */
     104             :   InvalidSolutionID registerInvalidity(const std::string & object_type,
     105             :                                        const std::string & message,
     106             :                                        const bool warning);
     107             : 
     108             : private:
     109             :   SolutionInvalidityRegistry();
     110             : 
     111             :   /// So it can be constructed
     112             :   friend SolutionInvalidityRegistry & getSolutionInvalidityRegistry();
     113             :   /// This is only here so that SolutionInvalidity can access readSectionInfo
     114             :   friend SolutionInvalidity;
     115             : };
     116             : }

Generated by: LCOV version 1.14