https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
14MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {}
15
16MooseEnumItem::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
35bool
36MooseEnumItem::operator==(const char * value) const
37{
38 std::string name(MooseUtils::toUpper(value));
39 return _name == name;
40}
41
42bool
43MooseEnumItem::operator!=(const char * value) const
44{
45 std::string name(MooseUtils::toUpper(value));
46 return _name != name;
47}
48
49bool
50MooseEnumItem::operator==(const std::string & value) const
51{
52 std::string name(MooseUtils::toUpper(value));
53 return _name == name;
54}
55
56bool
57MooseEnumItem::operator!=(const std::string & value) const
58{
59 std::string name(MooseUtils::toUpper(value));
60 return _name != name;
61}
62
63bool
65{
66 return _id == item.id() && _name == MooseUtils::toUpper(item.name());
67}
68
69bool
71{
72 return _id != item.id() && _name != MooseUtils::toUpper(item.name());
73}
74
75std::ostream &
76operator<<(std::ostream & out, const MooseEnumItem & item)
77{
78 out << item.rawName();
79 return out;
80}
81
82void
83MooseEnumItem::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
94const int MooseEnumItem::INVALID_ID = std::numeric_limits<int>::min();
std::ostream & operator<<(std::ostream &out, const MooseEnumItem &item)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Class for containing MooseEnum item information.
MooseEnumItem & operator=(const MooseEnumItem &other)
std::string _name
Upper case name.
const std::string & name() const
const int & id() const
Return the numeric, name, or raw name.
bool operator!=(const char *value) const
void setID(const int &id)
Method to change the ID of the item, but only if it is an INVALID_ID.
int _id
The numeric value for item.
bool operator==(const char *value) const
Comparison operators.
std::string _raw_name
The name as provided in constructor.
const std::string & rawName() const
static const int INVALID_ID
std::string toUpper(std::string name)
Convert supplied string to upper case.