www.mooseframework.org
MooseObjectName.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 MooseObjectName::MooseObjectName(const std::string & tag,
18  const std::string & name,
19  const std::string & separator)
20  : _tag(tag), _name(name), _combined(tag + name), _separator(separator)
21 {
22  check();
23 }
24 
25 MooseObjectName::MooseObjectName(std::string name) : _separator("::")
26 {
27  // Tags may be separated by a :: or the last /
28  std::size_t idx0 = name.find("::");
29  std::size_t idx1 = name.rfind("/");
30 
31  // Case when :: is found
32  if (idx0 != std::string::npos)
33  {
34  _tag = name.substr(0, idx0);
35  _name = name.erase(0, idx0 + 2);
36  }
37 
38  // Case when a / is found
39  else if (idx1 != std::string::npos)
40  {
41  _tag = name.substr(0, idx1);
42  _name = name.erase(0, idx1 + 1);
43  _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  _name = name;
49 
50  check();
51  _combined = _tag + _name;
52 }
53 
54 MooseObjectName::MooseObjectName() : _separator("/") {}
55 
57  : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator)
58 {
59 }
60 
61 bool
63 {
64  if ((_name == rhs._name || _name == "*" || rhs._name == "*") &&
65  (_tag == rhs._tag || _tag == "*" || rhs._tag == "*"))
66  {
67  return true;
68  }
69  return false;
70 }
71 
72 bool
74 {
75  return !(*this == rhs);
76 }
77 
78 bool
80 {
81  return (_combined < rhs._combined);
82 }
83 
84 std::ostream &
85 operator<<(std::ostream & stream, const MooseObjectName & obj)
86 {
87  if (obj._tag.empty())
88  return stream << obj._name;
89  else
90  return stream << obj._tag << obj._separator << obj._name;
91 }
92 
93 void
95 {
96  if (_name.empty())
97  mooseError("The supplied name cannot be empty, to allow for any name to be supplied use the "
98  "'*' character.");
99  if (_tag.empty())
100  mooseError("The supplied tag cannot be empty, to allow for any tag to be supplied use the '*' "
101  "character.");
102 }
std::string name(const ElemQuality q)
const std::string & name() const
Return the name.
std::string _combined
std::string _tag
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::string _name
virtual void check()
Check that the name and tag are supplied correctly.
bool operator<(const MooseObjectName &rhs) const
bool operator!=(const MooseObjectName &rhs) const
std::ostream & operator<<(std::ostream &stream, const MooseObjectName &obj)
bool operator==(const MooseObjectName &rhs) const
Comparison operators.
MooseObjectName()
A constructor for use by MooseObjectParameterName.
std::string _separator
A class for storing the names of MooseObject by tag and object name.