https://mooseframework.inl.gov
MooseEnumItem.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 // MOOSE includes
11 #include "MooseEnumItem.h"
12 #include "MooseUtils.h"
13 
14 MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {}
15 
16 MooseEnumItem::MooseEnumItem(const std::string & name, const int & id)
17  : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id)
18 {
19 }
20 
22  : _raw_name(other._raw_name), _name(other._name), _id(other._id)
23 {
24 }
25 
28 {
29  _raw_name = other._raw_name;
30  _name = other._name;
31  _id = other._id;
32  return *this;
33 }
34 
35 bool
36 MooseEnumItem::operator==(const char * value) const
37 {
38  std::string name(MooseUtils::toUpper(value));
39  return _name == name;
40 }
41 
42 bool
43 MooseEnumItem::operator!=(const char * value) const
44 {
45  std::string name(MooseUtils::toUpper(value));
46  return _name != name;
47 }
48 
49 bool
50 MooseEnumItem::operator==(const std::string & value) const
51 {
52  std::string name(MooseUtils::toUpper(value));
53  return _name == name;
54 }
55 
56 bool
57 MooseEnumItem::operator!=(const std::string & value) const
58 {
59  std::string name(MooseUtils::toUpper(value));
60  return _name != name;
61 }
62 
63 bool
65 {
66  return _id == item.id() && _name == MooseUtils::toUpper(item.name());
67 }
68 
69 bool
71 {
72  return _id != item.id() && _name != MooseUtils::toUpper(item.name());
73 }
74 
75 std::ostream &
76 operator<<(std::ostream & out, const MooseEnumItem & item)
77 {
78  out << item.rawName();
79  return out;
80 }
81 
82 void
83 MooseEnumItem::setID(const int & id)
84 {
85  if (_id != INVALID_ID)
86  mooseError("The ID of a MooseEnumItem can not be changed if it is valid, the item ",
87  _name,
88  " has a valid id of ",
89  _id,
90  ".");
91  _id = id;
92 }
93 
std::string name(const ElemQuality q)
void setID(const int &id)
Method to change the ID of the item, but only if it is an INVALID_ID.
Definition: MooseEnumItem.C:83
const std::string & name() const
Definition: MooseEnumItem.h:35
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
int _id
The numeric value for item.
Definition: MooseEnumItem.h:99
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _name
Upper case name.
Definition: MooseEnumItem.h:96
static const int INVALID_ID
Definition: MooseEnumItem.h:21
MooseEnumItem & operator=(const MooseEnumItem &other)
Definition: MooseEnumItem.C:27
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:93
bool operator==(const char *value) const
Comparison operators.
Definition: MooseEnumItem.C:36
std::ostream & operator<<(std::ostream &out, const MooseEnumItem &item)
Definition: MooseEnumItem.C:76
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
const std::string & rawName() const
Definition: MooseEnumItem.h:36
bool operator!=(const char *value) const
Definition: MooseEnumItem.C:43
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
OStreamProxy out
auto min(const L &left, const R &right)