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...
 
 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 46 of file MooseObjectName.h.

Constructor & Destructor Documentation

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 22 of file MooseObjectName.C.

25  : _tag(tag), _name(name), _combined(tag + name), _separator(separator)
26 {
27  check();
28 }
std::string _combined
std::string _tag
const std::string & name() const
Return the name.
std::string _name
const std::string & tag() const
Return the tag.
virtual void check()
Check that the name and tag are supplied correctly.
std::string _separator
MooseObjectName::MooseObjectName ( std::string  name)

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

Definition at line 30 of file MooseObjectName.C.

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

Copy constructor.

Definition at line 61 of file MooseObjectName.C.

62  : _tag(rhs._tag), _name(rhs._name), _combined(rhs._combined), _separator(rhs._separator)
63 {
64 }
std::string _combined
std::string _tag
std::string _name
std::string _separator
MooseObjectName::MooseObjectName ( )
protected

A constructor for use by MooseObjectParameterName.

Definition at line 59 of file MooseObjectName.C.

Referenced by tag().

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

Member Function Documentation

void MooseObjectName::check ( )
protectedvirtual

Check that the name and tag are supplied correctly.

Reimplemented in MooseObjectParameterName.

Definition at line 99 of file MooseObjectName.C.

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

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 }
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
std::string _name
const std::string& MooseObjectName::name ( ) const
inline

Return the name.

Definition at line 71 of file MooseObjectName.h.

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

71 { return _name; }
std::string _name
bool MooseObjectName::operator!= ( const MooseObjectName rhs) const

Definition at line 78 of file MooseObjectName.C.

Referenced by MooseObjectParameterName::operator!=(), and tag().

79 {
80  return !(*this == rhs);
81 }
bool MooseObjectName::operator< ( const MooseObjectName rhs) const

Definition at line 84 of file MooseObjectName.C.

Referenced by tag().

85 {
86  return (_combined < rhs._combined);
87 }
std::string _combined
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 67 of file MooseObjectName.C.

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

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 }
std::string _tag
std::string _name
const std::string& MooseObjectName::tag ( ) const
inline

Return the tag.

Definition at line 76 of file MooseObjectName.h.

76 { return _tag; }
std::string _tag

Friends And Related Function Documentation

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

Allows this to be used with std:: cout.

Definition at line 90 of file MooseObjectName.C.

Referenced by tag().

91 {
92  if (obj._tag.empty())
93  return stream << obj._name;
94  else
95  return stream << obj._tag << obj._separator << obj._name;
96 }
std::string _tag
std::string _name
std::string _separator

Member Data Documentation

std::string MooseObjectName::_combined
protected
std::string MooseObjectName::_name
protected
std::string MooseObjectName::_separator
protected
std::string MooseObjectName::_tag
protected

Storage for the various name components

Definition at line 102 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: