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 "MooseObjectName.h" 12 : #include "MooseError.h" 13 : 14 : // STL includes 15 : #include <iostream> 16 : 17 9470349 : MooseObjectName::MooseObjectName(const std::string & tag, 18 : const std::string & name, 19 9470349 : const std::string & separator) 20 9470349 : : _tag(tag), _name(name), _combined(tag + name), _separator(separator) 21 : { 22 9470349 : check(); 23 9470361 : } 24 : 25 3969292 : MooseObjectName::MooseObjectName(std::string name) : _separator("::") 26 : { 27 : // Tags may be separated by a :: or the last / 28 1984646 : std::size_t idx0 = name.find("::"); 29 1984646 : std::size_t idx1 = name.rfind("/"); 30 : 31 : // Case when :: is found 32 1984646 : if (idx0 != std::string::npos) 33 : { 34 1981654 : _tag = name.substr(0, idx0); 35 1981654 : _name = name.erase(0, idx0 + 2); 36 : } 37 : 38 : // Case when a / is found 39 2992 : else if (idx1 != std::string::npos) 40 : { 41 2990 : _tag = name.substr(0, idx1); 42 2990 : _name = name.erase(0, idx1 + 1); 43 2990 : _separator = "/"; 44 : } 45 : 46 : // If you get here, just use the supplied name without a tag (this will produce an error in check) 47 : else 48 2 : _name = name; 49 : 50 1984646 : check(); 51 1984644 : _combined = _tag + _name; 52 1984652 : } 53 : 54 10941 : MooseObjectName::MooseObjectName() : _separator("/") {} 55 : 56 21252448 : MooseObjectName::MooseObjectName(const MooseObjectName & rhs) 57 21252448 : : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator) 58 : { 59 21252448 : } 60 : 61 : bool 62 1911645 : MooseObjectName::operator==(const MooseObjectName & rhs) const 63 : { 64 2457471 : if ((_name == rhs._name || _name == "*" || rhs._name == "*") && 65 545826 : (_tag == rhs._tag || _tag == "*" || rhs._tag == "*")) 66 : { 67 188665 : return true; 68 : } 69 1722980 : return false; 70 : } 71 : 72 : bool 73 24 : MooseObjectName::operator!=(const MooseObjectName & rhs) const 74 : { 75 24 : return !(*this == rhs); 76 : } 77 : 78 : bool 79 96855296 : MooseObjectName::operator<(const MooseObjectName & rhs) const 80 : { 81 96855296 : return (_combined < rhs._combined); 82 : } 83 : 84 : std::ostream & 85 5589703 : operator<<(std::ostream & stream, const MooseObjectName & obj) 86 : { 87 5589703 : if (obj._tag.empty()) 88 0 : return stream << obj._name; 89 : else 90 5589703 : return stream << obj._tag << obj._separator << obj._name; 91 : } 92 : 93 : void 94 11454995 : MooseObjectName::check() 95 : { 96 11454995 : if (_name.empty()) 97 2 : mooseError("The supplied name cannot be empty, to allow for any name to be supplied use the " 98 : "'*' character."); 99 11454993 : if (_tag.empty()) 100 4 : mooseError("The supplied tag cannot be empty, to allow for any tag to be supplied use the '*' " 101 : "character."); 102 11454989 : }