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 292368 : ReporterName(){}; // empty constructor for InputParameters 37 : 38 : /** 39 : * Return the object name that produces the Reporter value 40 : */ 41 : const std::string & getObjectName() const; 42 : 43 : /** 44 : * Return the data name for the Reporter value. 45 : */ 46 : const std::string & getValueName() const; 47 : 48 : /** 49 : * Return the name of the object and data as object_name/data_name 50 : */ 51 : const std::string getCombinedName() const; 52 : 53 : /// The prefix for reporter data in the restartable system 54 : static const std::string REPORTER_RESTARTABLE_DATA_PREFIX; 55 : 56 : /** 57 : * Return the name used for registration of this Reporter in the restartable data system. 58 : */ 59 : std::string getRestartableName() const; 60 : 61 : /** 62 : * std::string operator allows this object to behave as a std::sting object 63 : */ 64 : operator std::string() const; 65 : 66 : /** 67 : * Compare with another object or string 68 : */ 69 : bool operator==(const ReporterName & rhs) const; 70 : bool operator==(const std::string & combined_name) const; 71 : 72 : /** 73 : * Less than operator 74 : */ 75 : bool operator<(const ReporterName & rhs) const; 76 : 77 : /** 78 : * Converts the special type to a usable name for error reporting 79 : */ 80 : std::string specialTypeToName() const; 81 : 82 : /** 83 : * @returns True if this ReporterName represents a Postprocessor 84 : */ 85 785803 : bool isPostprocessor() const { return _special_type == SpecialType::POSTPROCESSOR; } 86 : /** 87 : * @returns True if this ReporterName represents a VectorPostprocessor 88 : */ 89 197972 : bool isVectorPostprocessor() const { return _special_type == SpecialType::VECTORPOSTPROCESSOR; } 90 : 91 : /** 92 : * Sets the special type to a Postprocessor. 93 : * 94 : * See ReporterData::declareReporterValue. 95 : */ 96 1172062 : void setIsPostprocessor() { _special_type = SpecialType::POSTPROCESSOR; } 97 : /** 98 : * Sets the special type to a VectorPostprocessor. 99 : * 100 : * See ReporterData::declareReporterValue. 101 : */ 102 21419 : void setIsVectorPostprocessor() { _special_type = SpecialType::VECTORPOSTPROCESSOR; } 103 : 104 : /** 105 : * Whether or not the ReporterName is empty, similar to std::string::empty() 106 : */ 107 : bool empty() const { return _object_name.empty() || _value_name.empty(); } 108 : 109 : private: 110 : /** 111 : * Enum for storing a "special" type for this Reporter. 112 : * This is used to designate Reporters that represent Postprocessors 113 : * and VectorPostprocessors in output and error handling. 114 : */ 115 : enum class SpecialType 116 : { 117 : ANY = 0, 118 : POSTPROCESSOR = 1, 119 : VECTORPOSTPROCESSOR = 2 120 : }; 121 : 122 : /// The "special" type for this Reporter, used for identifying Postprocesors and VectorPostprocessors. 123 : ReporterName::SpecialType _special_type = ReporterName::SpecialType::ANY; 124 : 125 : /// The object name 126 : std::string _object_name; 127 : /// The value name 128 : std::string _value_name; 129 : }; 130 : 131 : /** 132 : * A ReporterName that represents a Postprocessor. 133 : */ 134 : class PostprocessorReporterName : public ReporterName 135 : { 136 : public: 137 : PostprocessorReporterName(const PostprocessorName & name); 138 : }; 139 : 140 : /** 141 : * A ReporterName that represents a VectorPostprocessor. 142 : */ 143 : class VectorPostprocessorReporterName : public ReporterName 144 : { 145 : public: 146 : VectorPostprocessorReporterName(const VectorPostprocessorName & name, 147 : const std::string & vector_name); 148 : }; 149 : 150 : // This with the operator== allow this to be used as a key in a std::unordered_map 151 : namespace std 152 : { 153 : template <> 154 : struct hash<ReporterName> 155 : { 156 : size_t operator()(const ReporterName & other) const { return hash<string>{}(other); } 157 : }; 158 : } 159 : 160 : // Support << output 161 : std::ostream & operator<<(std::ostream & os, const ReporterName & state);