LCOV - code coverage report
Current view: top level - include/reporters - ReporterMode.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 6 6 100.0 %
Date: 2026-05-29 20:35:17 Functions: 3 3 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 "MooseEnum.h"
      12             : 
      13             : /**
      14             :  * Reporter producer/consumer modes
      15             :  *
      16             :  * @see Reporter, ReporterState, ReporterContext
      17             :  *
      18             :  * This is used to define the "mode" in which the value is being produced or consumed. The default
      19             :  * for both the producer and consumer is ROOT. This means that it is assumed that the
      20             :  * correct/complete value of the Reporter value exists on the root processor.
      21             :  *
      22             :  * On the producer side, it is the responsibility of the Reporter object to perform the necessary
      23             :  * operations to compute the value in the specified mode. The ReporterContext objects are helpers
      24             :  * for the producer to get the value in the desired mode.
      25             :  *
      26             :  * On the consumer side, if needed the data supplied will be converted to the correct mode
      27             :  * automatically if needed and  possible. If the producer mode is not compatible with
      28             :  * the consumer mode, then an error is produced. The base ReporterContext handles the automatic
      29             :  * operations and error handling.
      30             :  *
      31             :  * The UNSET is used as the default to allow the ReporterContext objects to set the value
      32             :  * programmatically and error if it is set to something wrong by the user.
      33             :  */
      34             : class ReporterMode;
      35             : extern const ReporterMode REPORTER_MODE_UNSET;
      36             : extern const ReporterMode REPORTER_MODE_ROOT;
      37             : extern const ReporterMode REPORTER_MODE_REPLICATED;
      38             : extern const ReporterMode REPORTER_MODE_DISTRIBUTED;
      39             : 
      40             : /**
      41             :  * MooseEnumItem that automatically creates the ID and doesn't allow the ID to be assigned
      42             :  *
      43             :  * This protects user from hitting an ID collision when creating custom modes.
      44             :  */
      45             : class ReporterMode : public MooseEnumItem
      46             : {
      47             : public:
      48             :   ReporterMode(const std::string & key);
      49             : 
      50             : private:
      51             :   // Automatically incremented in construction
      52             :   static int ID_COUNTER;
      53             : };
      54             : 
      55             : /**
      56             :  * MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is
      57             :  * being produced. The available items indicate how it can be produced and the current item is
      58             :  * how the value is being produced.
      59             :  *
      60             :  * @see ReporterContext.h
      61             :  */
      62             : class ReporterProducerEnum : public MooseEnum
      63             : {
      64             : public:
      65             :   ReporterProducerEnum();
      66             : 
      67             :   /// Clear all available items (i.e., create an empty MooseEnum)
      68             :   void clear();
      69             : 
      70             :   ///@{
      71             :   /// Add possible items to the enumeration.
      72             :   template <typename... Args>
      73             :   void insert(const ReporterMode & mode, Args... modes);
      74             :   void insert(const ReporterMode & mode);
      75             :   ///@}
      76             : };
      77             : 
      78             : inline bool
      79       69538 : operator==(const ReporterProducerEnum & producer_mode, const ReporterMode & mode)
      80             : {
      81       69538 :   return static_cast<int>(producer_mode) == static_cast<int>(mode);
      82             : }
      83             : 
      84             : inline bool
      85             : operator==(const ReporterMode & mode, const ReporterProducerEnum & producer_mode)
      86             : {
      87             :   return producer_mode == mode;
      88             : }
      89             : 
      90             : inline bool
      91             : operator!=(const ReporterProducerEnum & producer_mode, const ReporterMode & mode)
      92             : {
      93             :   return !(producer_mode == mode);
      94             : }
      95             : 
      96             : inline bool
      97             : operator!=(const ReporterMode & mode, const ReporterProducerEnum & producer_mode)
      98             : {
      99             :   return !(mode == producer_mode);
     100             : }
     101             : 
     102             : template <typename... Args>
     103             : void
     104      163522 : ReporterProducerEnum::insert(const ReporterMode & mode, Args... modes)
     105             : {
     106      163522 :   insert(mode);
     107      163522 :   insert(modes...);
     108      163522 : }

Generated by: LCOV version 1.14