LCOV - code coverage report
Current view: top level - include/reporters - ReporterName.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 1f9d31 Lines: 5 5 100.0 %
Date: 2025-09-02 20:01:20 Functions: 5 5 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             : #pragma once
      10             : 
      11             : #include <iostream>
      12             : #include "MooseTypes.h"
      13             : 
      14             : /**
      15             :  * The Reporter system is comprised of objects that can contain any number of data values. This
      16             :  * class is a wrapper that severs two main purposes.
      17             :  *
      18             :  * 1. It provides a single "name" for accessing the data. When developing the Reporter system the
      19             :  *    original implementation required this object to serve as a key in a std::unordered_map. That
      20             :  *    is no longer the case, but those items remain in case that changes again in the future.
      21             :  * 2. Provide a means for defining special Parser syntax to allow for a single input parameter
      22             :  *    to define both the object and value name. This is the primary reason for this class, please
      23             :  *    refer to Parser.C for the specialization.
      24             :  *
      25             :  * Examples:
      26             :  *   ReporterName("object", "data");
      27             :  *   ReporterName("object/data");
      28             :  *
      29             :  */
      30             : class ReporterName
      31             : {
      32             : public:
      33             :   ReporterName(const std::string & object_name, const std::string & value_name);
      34             :   ReporterName(const std::string & object_and_value_name);
      35             :   ReporterName(const char * combined_name);
      36      292769 :   ReporterName(){}; // empty constructor for InputParameters
      37             : 
      38             :   /**
      39             :    * Determines if the inputted string is convertible to a ReporterName.
      40             :    *
      41             :    * @param object_and_value_name The string to determine convertibility
      42             :    * @return true Inputted string has a "/"
      43             :    * @return false Inputted string does not have a "/"
      44             :    */
      45             :   static bool isValidName(const std::string & object_and_value_name);
      46             : 
      47             :   /**
      48             :    * Return the object name that produces the Reporter value
      49             :    */
      50             :   const std::string & getObjectName() const;
      51             : 
      52             :   /**
      53             :    * Return the data name for the Reporter value.
      54             :    */
      55             :   const std::string & getValueName() const;
      56             : 
      57             :   /**
      58             :    * Return the name of the object and data as object_name/data_name
      59             :    */
      60             :   const std::string getCombinedName() const;
      61             : 
      62             :   /// The prefix for reporter data in the restartable system
      63             :   static const std::string REPORTER_RESTARTABLE_DATA_PREFIX;
      64             : 
      65             :   /**
      66             :    * Return the name used for registration of this Reporter in the restartable data system.
      67             :    */
      68             :   std::string getRestartableName() const;
      69             : 
      70             :   /**
      71             :    * std::string operator allows this object to behave as a std::sting object
      72             :    */
      73             :   operator std::string() const;
      74             : 
      75             :   /**
      76             :    * Compare with another object or string
      77             :    */
      78             :   bool operator==(const ReporterName & rhs) const;
      79             :   bool operator==(const std::string & combined_name) const;
      80             : 
      81             :   /**
      82             :    * Less than operator
      83             :    */
      84             :   bool operator<(const ReporterName & rhs) const;
      85             : 
      86             :   /**
      87             :    * Converts the special type to a usable name for error reporting
      88             :    */
      89             :   std::string specialTypeToName() const;
      90             : 
      91             :   /**
      92             :    * @returns True if this ReporterName represents a Postprocessor
      93             :    */
      94      859148 :   bool isPostprocessor() const { return _special_type == SpecialType::POSTPROCESSOR; }
      95             :   /**
      96             :    * @returns True if this ReporterName represents a VectorPostprocessor
      97             :    */
      98      216767 :   bool isVectorPostprocessor() const { return _special_type == SpecialType::VECTORPOSTPROCESSOR; }
      99             : 
     100             :   /**
     101             :    * Sets the special type to a Postprocessor.
     102             :    *
     103             :    * See ReporterData::declareReporterValue.
     104             :    */
     105     1695601 :   void setIsPostprocessor() { _special_type = SpecialType::POSTPROCESSOR; }
     106             :   /**
     107             :    * Sets the special type to a VectorPostprocessor.
     108             :    *
     109             :    * See ReporterData::declareReporterValue.
     110             :    */
     111       23097 :   void setIsVectorPostprocessor() { _special_type = SpecialType::VECTORPOSTPROCESSOR; }
     112             : 
     113             :   /**
     114             :    * Whether or not the ReporterName is empty, similar to std::string::empty()
     115             :    */
     116             :   bool empty() const { return _object_name.empty() || _value_name.empty(); }
     117             : 
     118             : private:
     119             :   /**
     120             :    * Enum for storing a "special" type for this Reporter.
     121             :    * This is used to designate Reporters that represent Postprocessors
     122             :    * and VectorPostprocessors in output and error handling.
     123             :    */
     124             :   enum class SpecialType
     125             :   {
     126             :     ANY = 0,
     127             :     POSTPROCESSOR = 1,
     128             :     VECTORPOSTPROCESSOR = 2
     129             :   };
     130             : 
     131             :   /// The "special" type for this Reporter, used for identifying Postprocesors and VectorPostprocessors.
     132             :   ReporterName::SpecialType _special_type = ReporterName::SpecialType::ANY;
     133             : 
     134             :   /// The object name
     135             :   std::string _object_name;
     136             :   /// The value name
     137             :   std::string _value_name;
     138             : };
     139             : 
     140             : /**
     141             :  * A ReporterName that represents a Postprocessor.
     142             :  */
     143             : class PostprocessorReporterName : public ReporterName
     144             : {
     145             : public:
     146             :   PostprocessorReporterName(const PostprocessorName & name);
     147             : };
     148             : 
     149             : /**
     150             :  * A ReporterName that represents a VectorPostprocessor.
     151             :  */
     152             : class VectorPostprocessorReporterName : public ReporterName
     153             : {
     154             : public:
     155             :   VectorPostprocessorReporterName(const VectorPostprocessorName & name,
     156             :                                   const std::string & vector_name);
     157             : };
     158             : 
     159             : // This with the operator== allow this to be used as a key in a std::unordered_map
     160             : namespace std
     161             : {
     162             : template <>
     163             : struct hash<ReporterName>
     164             : {
     165             :   size_t operator()(const ReporterName & other) const { return hash<string>{}(other); }
     166             : };
     167             : }
     168             : 
     169             : // Support << output
     170             : std::ostream & operator<<(std::ostream & os, const ReporterName & state);

Generated by: LCOV version 1.14