https://mooseframework.inl.gov
ReporterName.C
Go to the documentation of this file.
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 #include "ReporterName.h"
11 #include "MooseError.h"
12 
13 const std::string ReporterName::REPORTER_RESTARTABLE_DATA_PREFIX = "ReporterData";
14 
15 ReporterName::ReporterName(const std::string & object_name, const std::string & value_name)
16  : _object_name(object_name), _value_name(value_name)
17 {
18 }
19 
20 ReporterName::ReporterName(const std::string & combined_name)
21 {
22  std::size_t idx = combined_name.rfind("/");
23  if (idx != std::string::npos)
24  {
25  _object_name = combined_name.substr(0, idx);
26  _value_name = combined_name.substr(idx + 1);
27  }
28  else
29  mooseError("Invalid combined Reporter name: ", combined_name);
30 }
31 
32 ReporterName::ReporterName(const char * combined_name) : ReporterName(std::string(combined_name)) {}
33 
34 const std::string &
36 {
37  return _object_name;
38 }
39 
40 const std::string &
42 {
43  return _value_name;
44 }
45 
46 const std::string
48 {
49  return _object_name + "/" + _value_name;
50 }
51 
52 std::string
54 {
56 }
57 
58 ReporterName::operator std::string() const { return getCombinedName(); }
59 
60 bool
62 {
63  // Note here that we do not check if _special_type is the same. This is because
64  // we want to store reporter names as a single name regardless of the type
65  return _object_name == rhs._object_name && _value_name == rhs._value_name;
66 }
67 
68 bool
69 ReporterName::operator==(const std::string & combined_name) const
70 {
71  return getCombinedName() == combined_name;
72 }
73 
74 bool
76 {
77  // Note here that we do not sort by _special_type. This is because
78  // we want to store reporter names as a single name regardless of the type
79  return getCombinedName() < rhs.getCombinedName();
80 }
81 
82 std::string
84 {
85  if (isPostprocessor())
86  return "Postprocessor";
88  return "VectorPostprocessor";
89  return "Reporter";
90 }
91 
92 std::ostream &
93 operator<<(std::ostream & os, const ReporterName & state)
94 {
95  os << state.getCombinedName();
96  return os;
97 }
98 
100  : ReporterName(name, "value")
101 {
103 }
104 
106  const VectorPostprocessorName & name, const std::string & vector_name)
107  : ReporterName(name, vector_name)
108 {
110 }
std::string name(const ElemQuality q)
bool isVectorPostprocessor() const
Definition: ReporterName.h:89
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
PostprocessorReporterName(const PostprocessorName &name)
Definition: ReporterName.C:99
VectorPostprocessorReporterName(const VectorPostprocessorName &name, const std::string &vector_name)
Definition: ReporterName.C:105
static const std::string REPORTER_RESTARTABLE_DATA_PREFIX
The prefix for reporter data in the restartable system.
Definition: ReporterName.h:54
std::ostream & operator<<(std::ostream &os, const ReporterName &state)
Definition: ReporterName.C:93
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:33
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.
Definition: ReporterName.C:47
bool operator<(const ReporterName &rhs) const
Less than operator.
Definition: ReporterName.C:75
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
Definition: ReporterName.C:83
bool operator==(const ReporterName &rhs) const
Compare with another object or string.
Definition: ReporterName.C:61
std::string _value_name
The value name.
Definition: ReporterName.h:128
std::string _object_name
The object name.
Definition: ReporterName.h:126
bool isPostprocessor() const
Definition: ReporterName.h:85
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
Definition: ReporterName.C:35
void setIsPostprocessor()
Sets the special type to a Postprocessor.
Definition: ReporterName.h:96
void setIsVectorPostprocessor()
Sets the special type to a VectorPostprocessor.
Definition: ReporterName.h:102
std::string getRestartableName() const
Return the name used for registration of this Reporter in the restartable data system.
Definition: ReporterName.C:53
const std::string & getValueName() const
Return the data name for the Reporter value.
Definition: ReporterName.C:41
The Reporter system is comprised of objects that can contain any number of data values.
Definition: ReporterName.h:30
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)