www.mooseframework.org
Public Member Functions | Protected Member Functions | Friends | List of all members
MooseObjectName Class Reference

A class for storing the names of MooseObject by tag and object name. More...

#include <MooseObjectName.h>

Inheritance diagram for MooseObjectName:
[legend]

Public Member Functions

 MooseObjectName (const std::string &tag, const std::string &name, const std::string &separator=std::string("/"))
 Construct the name object. More...
 
virtual ~MooseObjectName ()=default
 This class requires a virtual (but default) desctructor since it has virtual functions. More...
 
 MooseObjectName (std::string name)
 Build an object given a raw parameter name (e.g., from an input file parameter) More...
 
 MooseObjectName (const MooseObjectName &rhs)
 Copy constructor. More...
 
const std::string & name () const
 Return the name. More...
 
const std::string & tag () const
 Return the tag. More...
 
bool operator== (const MooseObjectName &rhs) const
 Comparison operators. More...
 
bool operator!= (const MooseObjectName &rhs) const
 
bool operator< (const MooseObjectName &rhs) const
 

Protected Member Functions

 MooseObjectName ()
 A constructor for use by MooseObjectParameterName. More...
 
virtual void check ()
 Check that the name and tag are supplied correctly. More...
 

Protected Attributes

std::string _tag
 
std::string _name
 
std::string _combined
 
std::string _separator
 

Friends

std::ostream & operator<< (std::ostream &stream, const MooseObjectName &obj)
 Allows this to be used with std:: cout. More...
 

Detailed Description

A class for storing the names of MooseObject by tag and object name.

This class is used by the Control logic system, allowing for multiple tags to be applied to many different MooseObjects.

There are multiple ways to create an MooseObjectName object, the best being to input the tag and object name as separate inputs. However, this is not always practically if the supplied name is coming from an input file. Therefore, you can use the following single string methods.

MooseObjectName(foo::bar) -> tag="foo", name="bar" MooseObjectName(foo/bar) -> tag="foo", name="bar" MooseObjectName(foo/foo/bar) -> tag="foo/foo", name="bar"

This class also allows for glob style '*' to be used to allow for fuzzy comparisons to be performed.

MooseObjectName name1("*", "bar"); MooseObjectName name2("foo", "bar"); name1 == name2 (True)

MooseObjectName name3("foo", "*"); MooseObjectName name4("foo", "bar"); name3 == name4 (True)

Definition at line 41 of file MooseObjectName.h.

Constructor & Destructor Documentation

◆ MooseObjectName() [1/4]

MooseObjectName::MooseObjectName ( const std::string &  tag,
const std::string &  name,
const std::string &  separator = std::string("/") 
)

Construct the name object.

Parameters
tagThe tag to apply the object
nameThe name of the object

Definition at line 17 of file MooseObjectName.C.

20  : _tag(tag), _name(name), _combined(tag + name), _separator(separator)
21 {
22  check();
23 }
const std::string & name() const
Return the name.
std::string _combined
std::string _tag
std::string _name
virtual void check()
Check that the name and tag are supplied correctly.
std::string _separator
const std::string & tag() const
Return the tag.

◆ ~MooseObjectName()

virtual MooseObjectName::~MooseObjectName ( )
virtualdefault

This class requires a virtual (but default) desctructor since it has virtual functions.

◆ MooseObjectName() [2/4]

MooseObjectName::MooseObjectName ( std::string  name)

Build an object given a raw parameter name (e.g., from an input file parameter)

Definition at line 25 of file MooseObjectName.C.

25  : _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 }
const std::string & name() const
Return the name.
std::string _combined
std::string _tag
std::string _name
virtual void check()
Check that the name and tag are supplied correctly.
std::string _separator

◆ MooseObjectName() [3/4]

MooseObjectName::MooseObjectName ( const MooseObjectName rhs)

Copy constructor.

Definition at line 56 of file MooseObjectName.C.

57  : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator)
58 {
59 }
std::string _combined
std::string _tag
std::string _name
std::string _separator

◆ MooseObjectName() [4/4]

MooseObjectName::MooseObjectName ( )
protected

A constructor for use by MooseObjectParameterName.

Definition at line 54 of file MooseObjectName.C.

54 : _separator("/") {}
std::string _separator

Member Function Documentation

◆ check()

void MooseObjectName::check ( )
protectedvirtual

Check that the name and tag are supplied correctly.

Reimplemented in MooseObjectParameterName.

Definition at line 94 of file MooseObjectName.C.

Referenced by MooseObjectParameterName::check(), and MooseObjectName().

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 _tag
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::string _name

◆ name()

const std::string& MooseObjectName::name ( ) const
inline

Return the name.

Definition at line 72 of file MooseObjectName.h.

Referenced by MooseObjectName(), and MooseObjectParameterName::MooseObjectParameterName().

72 { return _name; }
std::string _name

◆ operator!=()

bool MooseObjectName::operator!= ( const MooseObjectName rhs) const

Definition at line 73 of file MooseObjectName.C.

Referenced by MooseObjectParameterName::operator!=().

74 {
75  return !(*this == rhs);
76 }

◆ operator<()

bool MooseObjectName::operator< ( const MooseObjectName rhs) const

Definition at line 79 of file MooseObjectName.C.

80 {
81  return (_combined < rhs._combined);
82 }
std::string _combined

◆ operator==()

bool MooseObjectName::operator== ( const MooseObjectName rhs) const

Comparison operators.

The less than operator is required so this container can work in std::map.

See also
InputParameterWarehouse

Definition at line 62 of file MooseObjectName.C.

Referenced by MooseObjectParameterName::operator==().

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 }
std::string _tag
std::string _name

◆ tag()

const std::string& MooseObjectName::tag ( ) const
inline

Return the tag.

Definition at line 77 of file MooseObjectName.h.

77 { return _tag; }
std::string _tag

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const MooseObjectName obj 
)
friend

Allows this to be used with std:: cout.

Definition at line 85 of file MooseObjectName.C.

86 {
87  if (obj._tag.empty())
88  return stream << obj._name;
89  else
90  return stream << obj._tag << obj._separator << obj._name;
91 }
std::string _tag
std::string _name
std::string _separator

Member Data Documentation

◆ _combined

std::string MooseObjectName::_combined
protected

◆ _name

std::string MooseObjectName::_name
protected

◆ _separator

std::string MooseObjectName::_separator
protected

◆ _tag

std::string MooseObjectName::_tag
protected

Storage for the various name components

Definition at line 103 of file MooseObjectName.h.

Referenced by check(), MooseObjectName(), MooseObjectParameterName::MooseObjectParameterName(), operator<<(), operator==(), and tag().


The documentation for this class was generated from the following files: