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 301100 : MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {} 15 : 16 321101242 : MooseEnumItem::MooseEnumItem(const std::string & name, const int & id) 17 642202484 : : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id) 18 : { 19 321101242 : } 20 : 21 1965477138 : MooseEnumItem::MooseEnumItem(const MooseEnumItem & other) 22 1965477138 : : _raw_name(other._raw_name), _name(other._name), _id(other._id) 23 : { 24 1965477138 : } 25 : 26 : MooseEnumItem & 27 130097820 : MooseEnumItem::operator=(const MooseEnumItem & other) 28 : { 29 130097820 : _raw_name = other._raw_name; 30 130097820 : _name = other._name; 31 130097820 : _id = other._id; 32 130097820 : return *this; 33 : } 34 : 35 : bool 36 869510 : MooseEnumItem::operator==(const char * value) const 37 : { 38 869510 : std::string name(MooseUtils::toUpper(value)); 39 1739020 : return _name == name; 40 869510 : } 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 182788716 : MooseEnumItem::operator==(const std::string & value) const 51 : { 52 182788716 : std::string name(MooseUtils::toUpper(value)); 53 365577432 : return _name == name; 54 182788716 : } 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 296427475 : MooseEnumItem::operator==(const MooseEnumItem & item) const 65 : { 66 296427475 : return _id == item.id() && _name == MooseUtils::toUpper(item.name()); 67 : } 68 : 69 : bool 70 13870800 : MooseEnumItem::operator!=(const MooseEnumItem & item) const 71 : { 72 13870800 : return _id != item.id() && _name != MooseUtils::toUpper(item.name()); 73 : } 74 : 75 : std::ostream & 76 7951232 : operator<<(std::ostream & out, const MooseEnumItem & item) 77 : { 78 7951232 : out << item.rawName(); 79 7951232 : 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();