www.mooseframework.org
MooseObjectName.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "MooseObjectName.h"
17 #include "MooseError.h"
18 
19 // STL includes
20 #include <iostream>
21 
22 MooseObjectName::MooseObjectName(const std::string & tag,
23  const std::string & name,
24  const std::string & separator)
25  : _tag(tag), _name(name), _combined(tag + name), _separator(separator)
26 {
27  check();
28 }
29 
31 {
32  // Tags may be separated by a :: or the last /
33  std::size_t idx0 = name.find("::");
34  std::size_t idx1 = name.rfind("/");
35 
36  // Case when :: is found
37  if (idx0 != std::string::npos)
38  {
39  _tag = name.substr(0, idx0);
40  _name = name.erase(0, idx0 + 2);
41  }
42 
43  // Case when a / is found
44  else if (idx1 != std::string::npos)
45  {
46  _tag = name.substr(0, idx1);
47  _name = name.erase(0, idx1 + 1);
48  _separator = "/";
49  }
50 
51  // If you get here, just use the supplied name without a tag (this will produce an error in check)
52  else
53  _name = name;
54 
55  check();
56  _combined = _tag + _name;
57 }
58 
60 
62  : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator)
63 {
64 }
65 
66 bool
68 {
69  if ((_name == rhs._name || _name == "*" || rhs._name == "*") &&
70  (_tag == rhs._tag || _tag == "*" || rhs._tag == "*"))
71  {
72  return true;
73  }
74  return false;
75 }
76 
77 bool
79 {
80  return !(*this == rhs);
81 }
82 
83 bool
85 {
86  return (_combined < rhs._combined);
87 }
88 
89 std::ostream &
90 operator<<(std::ostream & stream, const MooseObjectName & obj)
91 {
92  if (obj._tag.empty())
93  return stream << obj._name;
94  else
95  return stream << obj._tag << obj._separator << obj._name;
96 }
97 
98 void
100 {
101  if (_name.empty())
102  mooseError("The supplied name cannot be empty, to allow for any name to be supplied use the "
103  "'*' character.");
104  if (_tag.empty())
105  mooseError("The supplied tag cannot be empty, to allow for any tag to be supplied use the '*' "
106  "character.");
107 }
bool operator<(const MooseObjectName &rhs) const
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:182
const std::string & name() const
Return the name.
std::string _name
virtual void check()
Check that the name and tag are supplied correctly.
MooseObjectName()
A constructor for use by MooseObjectParameterName.
bool operator!=(const MooseObjectName &rhs) const
std::string _separator
friend std::ostream & operator<<(std::ostream &stream, const MooseObjectName &obj)
Allows this to be used with std:: cout.
bool operator==(const MooseObjectName &rhs) const
Comparison operators.
A class for storing the names of MooseObject by tag and object name.