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 298700 : MooseEnumItem::MooseEnumItem() : _raw_name("INVALID"), _name("INVALID"), _id(INVALID_ID) {} 15 : 16 318494249 : MooseEnumItem::MooseEnumItem(const std::string & name, const int & id) 17 636988498 : : _raw_name(MooseUtils::trim(name)), _name(MooseUtils::toUpper(_raw_name)), _id(id) 18 : { 19 318494249 : } 20 : 21 1940444344 : MooseEnumItem::MooseEnumItem(const MooseEnumItem & other) 22 1940444344 : : _raw_name(other._raw_name), _name(other._name), _id(other._id) 23 : { 24 1940444344 : } 25 : 26 : MooseEnumItem & 27 129200661 : MooseEnumItem::operator=(const MooseEnumItem & other) 28 : { 29 129200661 : _raw_name = other._raw_name; 30 129200661 : _name = other._name; 31 129200661 : _id = other._id; 32 129200661 : return *this; 33 : } 34 : 35 : bool 36 868760 : MooseEnumItem::operator==(const char * value) const 37 : { 38 868760 : std::string name(MooseUtils::toUpper(value)); 39 1737520 : return _name == name; 40 868760 : } 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 182517797 : MooseEnumItem::operator==(const std::string & value) const 51 : { 52 182517797 : std::string name(MooseUtils::toUpper(value)); 53 365035594 : return _name == name; 54 182517797 : } 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 295938900 : MooseEnumItem::operator==(const MooseEnumItem & item) const 65 : { 66 295938900 : return _id == item.id() && _name == MooseUtils::toUpper(item.name()); 67 : } 68 : 69 : bool 70 13843794 : MooseEnumItem::operator!=(const MooseEnumItem & item) const 71 : { 72 13843794 : return _id != item.id() && _name != MooseUtils::toUpper(item.name()); 73 : } 74 : 75 : std::ostream & 76 7624834 : operator<<(std::ostream & out, const MooseEnumItem & item) 77 : { 78 7624834 : out << item.rawName(); 79 7624834 : 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();