Line data Source code
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 57816 : MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {} 15 : 16 258172827 : MooseEnumItem::MooseEnumItem(const std::string & name, const int & id) 17 258172827 : : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id) 18 : { 19 258172827 : } 20 : 21 1803851616 : MooseEnumItem::MooseEnumItem(const MooseEnumItem & other) 22 1803851616 : : _raw_name(other._raw_name), _name(other._name), _id(other._id) 23 : { 24 1803851616 : } 25 : 26 : MooseEnumItem & 27 96465320 : MooseEnumItem::operator=(const MooseEnumItem & other) 28 : { 29 96465320 : _raw_name = other._raw_name; 30 96465320 : _name = other._name; 31 96465320 : _id = other._id; 32 96465320 : return *this; 33 : } 34 : 35 : bool 36 850146 : MooseEnumItem::operator==(const char * value) const 37 : { 38 850146 : std::string name(MooseUtils::toUpper(value)); 39 1700292 : return _name == name; 40 850146 : } 41 : 42 : bool 43 0 : MooseEnumItem::operator!=(const char * value) const 44 : { 45 0 : std::string name(MooseUtils::toUpper(value)); 46 0 : return _name != name; 47 0 : } 48 : 49 : bool 50 179054170 : MooseEnumItem::operator==(const std::string & value) const 51 : { 52 179054170 : std::string name(MooseUtils::toUpper(value)); 53 358108340 : return _name == name; 54 179054170 : } 55 : 56 : bool 57 0 : MooseEnumItem::operator!=(const std::string & value) const 58 : { 59 0 : std::string name(MooseUtils::toUpper(value)); 60 0 : return _name != name; 61 0 : } 62 : 63 : bool 64 290076125 : MooseEnumItem::operator==(const MooseEnumItem & item) const 65 : { 66 290076125 : return _id == item.id() && _name == MooseUtils::toUpper(item.name()); 67 : } 68 : 69 : bool 70 13488086 : MooseEnumItem::operator!=(const MooseEnumItem & item) const 71 : { 72 13488086 : return _id != item.id() && _name != MooseUtils::toUpper(item.name()); 73 : } 74 : 75 : std::ostream & 76 6675984 : operator<<(std::ostream & out, const MooseEnumItem & item) 77 : { 78 6675984 : out << item.rawName(); 79 6675984 : return out; 80 : } 81 : 82 : void 83 2 : MooseEnumItem::setID(const int & id) 84 : { 85 2 : if (_id != INVALID_ID) 86 1 : mooseError("The ID of a MooseEnumItem can not be changed if it is valid, the item ", 87 1 : _name, 88 : " has a valid id of ", 89 1 : _id, 90 : "."); 91 1 : _id = id; 92 1 : } 93 : 94 : const int MooseEnumItem::INVALID_ID = std::numeric_limits<int>::min();