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 bool
35 ReporterName::isValidName(const std::string & combined_name)
36 {
37  return combined_name.rfind("/") != std::string::npos;
38 }
39 
40 const std::string &
42 {
43  return _object_name;
44 }
45 
46 const std::string &
48 {
49  return _value_name;
50 }
51 
52 const std::string
54 {
55  return _object_name + "/" + _value_name;
56 }
57 
58 std::string
60 {
62 }
63 
64 ReporterName::operator std::string() const { return getCombinedName(); }
65 
66 bool
68 {
69  // Note here that we do not check if _special_type is the same. This is because
70  // we want to store reporter names as a single name regardless of the type
71  return _object_name == rhs._object_name && _value_name == rhs._value_name;
72 }
73 
74 bool
75 ReporterName::operator==(const std::string & combined_name) const
76 {
77  return getCombinedName() == combined_name;
78 }
79 
80 bool
82 {
83  // Note here that we do not sort by _special_type. This is because
84  // we want to store reporter names as a single name regardless of the type
85  return getCombinedName() < rhs.getCombinedName();
86 }
87 
88 std::string
90 {
91  if (isPostprocessor())
92  return "Postprocessor";
94  return "VectorPostprocessor";
95  return "Reporter";
96 }
97 
98 std::ostream &
99 operator<<(std::ostream & os, const ReporterName & state)
100 {
101  os << state.getCombinedName();
102  return os;
103 }
104 
106  : ReporterName(name, "value")
107 {
109 }
110 
112  const VectorPostprocessorName & name, const std::string & vector_name)
113  : ReporterName(name, vector_name)
114 {
116 }
std::string name(const ElemQuality q)
bool isVectorPostprocessor() const
Definition: ReporterName.h:98
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:105
VectorPostprocessorReporterName(const VectorPostprocessorName &name, const std::string &vector_name)
Definition: ReporterName.C:111
static const std::string REPORTER_RESTARTABLE_DATA_PREFIX
The prefix for reporter data in the restartable system.
Definition: ReporterName.h:63
std::ostream & operator<<(std::ostream &os, const ReporterName &state)
Definition: ReporterName.C:99
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:53
bool operator<(const ReporterName &rhs) const
Less than operator.
Definition: ReporterName.C:81
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
Definition: ReporterName.C:89
bool operator==(const ReporterName &rhs) const
Compare with another object or string.
Definition: ReporterName.C:67
std::string _value_name
The value name.
Definition: ReporterName.h:137
std::string _object_name
The object name.
Definition: ReporterName.h:135
bool isPostprocessor() const
Definition: ReporterName.h:94
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
Definition: ReporterName.C:41
static bool isValidName(const std::string &object_and_value_name)
Determines if the inputted string is convertible to a ReporterName.
Definition: ReporterName.C:35
void setIsPostprocessor()
Sets the special type to a Postprocessor.
Definition: ReporterName.h:105
void setIsVectorPostprocessor()
Sets the special type to a VectorPostprocessor.
Definition: ReporterName.h:111
std::string getRestartableName() const
Return the name used for registration of this Reporter in the restartable data system.
Definition: ReporterName.C:59
const std::string & getValueName() const
Return the data name for the Reporter value.
Definition: ReporterName.C:47
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)