www.mooseframework.org
MooseEnumItem.h
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 #pragma once
11 
12 // STL includes
13 #include <string>
14 
19 {
20 public:
21  static const int INVALID_ID;
22  MooseEnumItem();
23  MooseEnumItem(const std::string & name, const int & id = INVALID_ID);
24  ~MooseEnumItem() = default;
25  MooseEnumItem(const MooseEnumItem & other);
26  MooseEnumItem(MooseEnumItem && /*other*/) = default;
27  MooseEnumItem & operator=(const MooseEnumItem & other);
28  MooseEnumItem & operator=(MooseEnumItem && /*other*/) = default;
29 
31 
34  const int & id() const { return _id; }
35  const std::string & name() const { return _name; }
36  const std::string & rawName() const { return _raw_name; }
38 
40 
43  operator int() const { return _id; }
44  operator std::string() const { return _name; }
46 
48 
53  bool operator==(const char * value) const;
54  bool operator!=(const char * value) const;
55 
56  bool operator==(const std::string & value) const;
57  bool operator!=(const std::string & value) const;
58 
59  bool operator==(int value) const { return _id == value; }
60  bool operator!=(int value) const { return _id != value; }
61 
62  bool operator==(unsigned short value) const { return _id == value; }
63  bool operator!=(unsigned short value) const { return _id != value; }
64 
65  bool operator==(const MooseEnumItem &) const;
66  bool operator!=(const MooseEnumItem &) const;
68 
72  bool operator<(const MooseEnumItem & other) const
73  {
74  return _id != other._id ? _id < other._id : _name < other._name;
75  }
76 
80  friend std::ostream & operator<<(std::ostream & out, const MooseEnumItem & item);
81 
89  void setID(const int & id);
90 
91 private:
93  std::string _raw_name;
94 
96  std::string _name;
97 
99  int _id;
100 };
void setID(const int &id)
Method to change the ID of the item, but only if it is an INVALID_ID.
Definition: MooseEnumItem.C:83
friend std::ostream & operator<<(std::ostream &out, const MooseEnumItem &item)
ostream operator for string printing.
Definition: MooseEnumItem.C:76
const std::string & name() const
Definition: MooseEnumItem.h:35
int _id
The numeric value for item.
Definition: MooseEnumItem.h:99
std::string _name
Upper case name.
Definition: MooseEnumItem.h:96
static const int INVALID_ID
Definition: MooseEnumItem.h:21
bool operator!=(int value) const
Definition: MooseEnumItem.h:60
MooseEnumItem & operator=(const MooseEnumItem &other)
Definition: MooseEnumItem.C:27
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:93
bool operator==(const char *value) const
Comparison operators.
Definition: MooseEnumItem.C:36
bool operator<(const MooseEnumItem &other) const
Less than operator.
Definition: MooseEnumItem.h:72
bool operator==(unsigned short value) const
Definition: MooseEnumItem.h:62
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::string & rawName() const
Definition: MooseEnumItem.h:36
bool operator!=(const char *value) const
Definition: MooseEnumItem.C:43
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
~MooseEnumItem()=default
bool operator==(int value) const
Definition: MooseEnumItem.h:59
void ErrorVector unsigned int
bool operator!=(unsigned short value) const
Definition: MooseEnumItem.h:63