https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
13const std::string ReporterName::REPORTER_RESTARTABLE_DATA_PREFIX = "ReporterData";
14
15ReporterName::ReporterName(const std::string & object_name, const std::string & value_name)
16 : _object_name(object_name), _value_name(value_name)
17{
18}
19
20ReporterName::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
32ReporterName::ReporterName(const char * combined_name) : ReporterName(std::string(combined_name)) {}
33
34bool
35ReporterName::isValidName(const std::string & combined_name)
36{
37 return combined_name.rfind("/") != std::string::npos;
38}
39
40const std::string &
42{
43 return _object_name;
44}
45
46const std::string &
48{
49 return _value_name;
50}
51
52const std::string
54{
55 return _object_name + "/" + _value_name;
56}
57
58std::string
63
64ReporterName::operator std::string() const { return getCombinedName(); }
65
66bool
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
74bool
75ReporterName::operator==(const std::string & combined_name) const
76{
77 return getCombinedName() == combined_name;
78}
79
80bool
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
88std::string
90{
91 if (isPostprocessor())
92 return "Postprocessor";
94 return "VectorPostprocessor";
95 return "Reporter";
96}
97
98std::ostream &
99operator<<(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}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
std::ostream & operator<<(std::ostream &os, const ReporterName &state)
PostprocessorReporterName(const PostprocessorName &name)
The Reporter system is comprised of objects that can contain any number of data values.
std::string specialTypeToName() const
Converts the special type to a usable name for error reporting.
static bool isValidName(const std::string &object_and_value_name)
Determines if the inputted string is convertible to a ReporterName.
void setIsVectorPostprocessor()
Sets the special type to a VectorPostprocessor.
std::string getRestartableName() const
Return the name used for registration of this Reporter in the restartable data system.
bool operator<(const ReporterName &rhs) const
Less than operator.
bool isPostprocessor() const
bool operator==(const ReporterName &rhs) const
Compare with another object or string.
bool isVectorPostprocessor() const
const std::string & getObjectName() const
Return the object name that produces the Reporter value.
const std::string getCombinedName() const
Return the name of the object and data as object_name/data_name.
void setIsPostprocessor()
Sets the special type to a Postprocessor.
const std::string & getValueName() const
Return the data name for the Reporter value.
static const std::string REPORTER_RESTARTABLE_DATA_PREFIX
The prefix for reporter data in the restartable system.
std::string _object_name
The object name.
std::string _value_name
The value name.
VectorPostprocessorReporterName(const VectorPostprocessorName &name, const std::string &vector_name)