www.mooseframework.org
Public Member Functions | Static Public Attributes | Private Attributes | Friends | List of all members
MooseEnumItem Class Reference

Class for containing MooseEnum item information. More...

#include <MooseEnumItem.h>

Public Member Functions

 MooseEnumItem (const std::string &name, const int &id=INVALID_ID)
 
 ~MooseEnumItem ()=default
 
 MooseEnumItem (const MooseEnumItem &other)
 
 MooseEnumItem (MooseEnumItem &&)=default
 
MooseEnumItemoperator= (const MooseEnumItem &other)
 
MooseEnumItemoperator= (MooseEnumItem &&)=default
 
bool operator< (const MooseEnumItem &other) const
 Less than operator. More...
 
void setID (const int &id)
 Method to change the ID of the item, but only if it is an INVALID_ID. More...
 
const int & id () const
 Return the numeric, name, or raw name. More...
 
const std::string & name () const
 
const std::string & rawName () const
 
 operator int () const
 Operator to allow this class to be used directly as a string for int. More...
 
 operator std::string () const
 
bool operator== (const char *value) const
 Comparison operators. More...
 
bool operator!= (const char *value) const
 
bool operator== (const std::string &value) const
 
bool operator!= (const std::string &value) const
 
bool operator== (int value) const
 
bool operator!= (int value) const
 
bool operator== (unsigned short value) const
 
bool operator!= (unsigned short value) const
 
bool operator== (const MooseEnumItem &) const
 
bool operator!= (const MooseEnumItem &) const
 

Static Public Attributes

static const int INVALID_ID = std::numeric_limits<int>::min()
 

Private Attributes

std::string _raw_name
 The name as provided in constructor. More...
 
std::string _name
 Upper case name. More...
 
int _id
 The numeric value for item. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const MooseEnumItem &item)
 ostream operator for string printing. More...
 

Detailed Description

Class for containing MooseEnum item information.

Definition at line 22 of file MooseEnumItem.h.

Constructor & Destructor Documentation

◆ MooseEnumItem() [1/3]

MooseEnumItem::MooseEnumItem ( const std::string &  name,
const int &  id = INVALID_ID 
)

Definition at line 14 of file MooseEnumItem.C.

16 {
17 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:96
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:112

◆ ~MooseEnumItem()

MooseEnumItem::~MooseEnumItem ( )
default

◆ MooseEnumItem() [2/3]

MooseEnumItem::MooseEnumItem ( const MooseEnumItem other)

Definition at line 19 of file MooseEnumItem.C.

20  : _raw_name(other._raw_name), _name(other._name), _id(other._id)
21 {
22 }
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:96

◆ MooseEnumItem() [3/3]

MooseEnumItem::MooseEnumItem ( MooseEnumItem &&  )
default

Member Function Documentation

◆ id()

const int& MooseEnumItem::id ( ) const
inline

◆ name()

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

◆ operator int()

MooseEnumItem::operator int ( ) const
inline

Operator to allow this class to be used directly as a string for int.

Definition at line 46 of file MooseEnumItem.h.

46 { return _id; }
int _id
The numeric value for item.

◆ operator std::string()

MooseEnumItem::operator std::string ( ) const
inline

Definition at line 47 of file MooseEnumItem.h.

47 { return _name; }
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator!=() [1/5]

bool MooseEnumItem::operator!= ( const char *  value) const

Definition at line 41 of file MooseEnumItem.C.

42 {
43  std::string name(MooseUtils::toUpper(value));
44  return _name != name;
45 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator!=() [2/5]

bool MooseEnumItem::operator!= ( const std::string &  value) const

Definition at line 55 of file MooseEnumItem.C.

56 {
57  std::string name(MooseUtils::toUpper(value));
58  return _name != name;
59 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator!=() [3/5]

bool MooseEnumItem::operator!= ( int  value) const
inline

Definition at line 63 of file MooseEnumItem.h.

63 { return _id != value; }
int _id
The numeric value for item.

◆ operator!=() [4/5]

bool MooseEnumItem::operator!= ( unsigned short  value) const
inline

Definition at line 66 of file MooseEnumItem.h.

66 { return _id != value; }
int _id
The numeric value for item.

◆ operator!=() [5/5]

bool MooseEnumItem::operator!= ( const MooseEnumItem item) const

Definition at line 68 of file MooseEnumItem.C.

69 {
70  return _id != item.id() && _name != MooseUtils::toUpper(item.name());
71 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:37

◆ operator<()

bool MooseEnumItem::operator< ( const MooseEnumItem other) const
inline

Less than operator.

This is required for this class to work in maps and sets.

Definition at line 75 of file MooseEnumItem.h.

76  {
77  return _id != other._id ? _id < other._id : _name < other._name;
78  }
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator=() [1/2]

MooseEnumItem & MooseEnumItem::operator= ( const MooseEnumItem other)

Definition at line 25 of file MooseEnumItem.C.

26 {
27  _raw_name = other._raw_name;
28  _name = other._name;
29  _id = other._id;
30  return *this;
31 }
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:96

◆ operator=() [2/2]

MooseEnumItem& MooseEnumItem::operator= ( MooseEnumItem &&  )
default

◆ operator==() [1/5]

bool MooseEnumItem::operator== ( const char *  value) const

Comparison operators.

The comparison operators using the char * and string are case sensitive.

Definition at line 34 of file MooseEnumItem.C.

35 {
36  std::string name(MooseUtils::toUpper(value));
37  return _name == name;
38 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator==() [2/5]

bool MooseEnumItem::operator== ( const std::string &  value) const

Definition at line 48 of file MooseEnumItem.C.

49 {
50  std::string name(MooseUtils::toUpper(value));
51  return _name == name;
52 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99

◆ operator==() [3/5]

bool MooseEnumItem::operator== ( int  value) const
inline

Definition at line 62 of file MooseEnumItem.h.

62 { return _id == value; }
int _id
The numeric value for item.

◆ operator==() [4/5]

bool MooseEnumItem::operator== ( unsigned short  value) const
inline

Definition at line 65 of file MooseEnumItem.h.

65 { return _id == value; }
int _id
The numeric value for item.

◆ operator==() [5/5]

bool MooseEnumItem::operator== ( const MooseEnumItem item) const

Definition at line 62 of file MooseEnumItem.C.

63 {
64  return _id == item.id() && _name == MooseUtils::toUpper(item.name());
65 }
const std::string & name() const
Definition: MooseEnumItem.h:38
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:696
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:99
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:37

◆ rawName()

const std::string& MooseEnumItem::rawName ( ) const
inline

Definition at line 39 of file MooseEnumItem.h.

Referenced by MooseEnum::operator std::string(), and operator<<().

39 { return _raw_name; }
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:96

◆ setID()

void MooseEnumItem::setID ( const int &  id)

Method to change the ID of the item, but only if it is an INVALID_ID.

An error is produced if the ID is valid and this method is called.

This is needed to allow ExecFlagType objects to be created without an ID being provided, the ID is assigned when ExecFlagEnum::addAvailableFlags is called.

Definition at line 81 of file MooseEnumItem.C.

Referenced by MooseApp::addExecFlag().

82 {
83  if (_id != INVALID_ID)
84  mooseError("The ID of a MooseEnumItem can not be changed if it is valid, the item ",
85  _name,
86  " has a valid id of ",
87  _id,
88  ".");
89  _id = id;
90 }
int _id
The numeric value for item.
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
Upper case name.
Definition: MooseEnumItem.h:99
static const int INVALID_ID
Definition: MooseEnumItem.h:25
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:37

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const MooseEnumItem item 
)
friend

ostream operator for string printing.

Definition at line 74 of file MooseEnumItem.C.

75 {
76  out << item.rawName();
77  return out;
78 }
const std::string & rawName() const
Definition: MooseEnumItem.h:39

Member Data Documentation

◆ _id

int MooseEnumItem::_id
private

The numeric value for item.

Definition at line 102 of file MooseEnumItem.h.

Referenced by id(), operator int(), operator!=(), operator<(), operator=(), operator==(), and setID().

◆ _name

std::string MooseEnumItem::_name
private

Upper case name.

Definition at line 99 of file MooseEnumItem.h.

Referenced by name(), operator std::string(), operator!=(), operator<(), operator=(), operator==(), and setID().

◆ _raw_name

std::string MooseEnumItem::_raw_name
private

The name as provided in constructor.

Definition at line 96 of file MooseEnumItem.h.

Referenced by operator=(), and rawName().

◆ INVALID_ID

const int MooseEnumItem::INVALID_ID = std::numeric_limits<int>::min()
static

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