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 303500 : MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {} 15 : 16 323734849 : MooseEnumItem::MooseEnumItem(const std::string & name, const int & id) 17 647469698 : : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id) 18 : { 19 323734849 : } 20 : 21 1981140068 : MooseEnumItem::MooseEnumItem(const MooseEnumItem & other) 22 1981140068 : : _raw_name(other._raw_name), _name(other._name), _id(other._id) 23 : { 24 1981140068 : } 25 : 26 : MooseEnumItem & 27 131123525 : MooseEnumItem::operator=(const MooseEnumItem & other) 28 : { 29 131123525 : _raw_name = other._raw_name; 30 131123525 : _name = other._name; 31 131123525 : _id = other._id; 32 131123525 : return *this; 33 : } 34 : 35 : bool 36 871550 : MooseEnumItem::operator==(const char * value) const 37 : { 38 871550 : std::string name(MooseUtils::toUpper(value)); 39 1743100 : return _name == name; 40 871550 : } 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 183141386 : MooseEnumItem::operator==(const std::string & value) const 51 : { 52 183141386 : std::string name(MooseUtils::toUpper(value)); 53 366282772 : return _name == name; 54 183141386 : } 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 297145978 : MooseEnumItem::operator==(const MooseEnumItem & item) const 65 : { 66 297145978 : return _id == item.id() && _name == MooseUtils::toUpper(item.name()); 67 : } 68 : 69 : bool 70 13910238 : MooseEnumItem::operator!=(const MooseEnumItem & item) const 71 : { 72 13910238 : return _id != item.id() && _name != MooseUtils::toUpper(item.name()); 73 : } 74 : 75 : std::ostream & 76 8023767 : operator<<(std::ostream & out, const MooseEnumItem & item) 77 : { 78 8023767 : out << item.rawName(); 79 8023767 : return out; 80 : } 81 : 82 : void 83 4 : MooseEnumItem::setID(const int & id) 84 : { 85 4 : if (_id != INVALID_ID) 86 2 : mooseError("The ID of a MooseEnumItem can not be changed if it is valid, the item ", 87 2 : _name, 88 : " has a valid id of ", 89 2 : _id, 90 : "."); 91 2 : _id = id; 92 2 : } 93 : 94 : const int MooseEnumItem::INVALID_ID = std::numeric_limits<int>::min();