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 
15 // Forward declarations
16 class MooseApp;
17 
22 {
23 public:
24  static const int INVALID_ID;
25  MooseEnumItem(const std::string & name, const int & id = INVALID_ID);
26  ~MooseEnumItem() = default;
27  MooseEnumItem(const MooseEnumItem & other);
28  MooseEnumItem(MooseEnumItem && /*other*/) = default;
29  MooseEnumItem & operator=(const MooseEnumItem & other);
30  MooseEnumItem & operator=(MooseEnumItem && /*other*/) = default;
31 
33 
36  const int & id() const { return _id; }
37  const std::string & name() const { return _name; }
38  const std::string & rawName() const { return _raw_name; }
40 
42 
45  operator int() const { return _id; }
46  operator std::string() const { return _name; }
48 
50 
55  bool operator==(const char * value) const;
56  bool operator!=(const char * value) const;
57 
58  bool operator==(const std::string & value) const;
59  bool operator!=(const std::string & value) const;
60 
61  bool operator==(int value) const { return _id == value; }
62  bool operator!=(int value) const { return _id != value; }
63 
64  bool operator==(unsigned short value) const { return _id == value; }
65  bool operator!=(unsigned short value) const { return _id != value; }
66 
67  bool operator==(const MooseEnumItem &) const;
68  bool operator!=(const MooseEnumItem &) const;
70 
74  bool operator<(const MooseEnumItem & other) const
75  {
76  return _id != other._id ? _id < other._id : _name < other._name;
77  }
78 
82  friend std::ostream & operator<<(std::ostream & out, const MooseEnumItem & item);
83 
91  void setID(const int & id);
92 
93 private:
95  std::string _raw_name;
96 
98  std::string _name;
99 
101  int _id;
102 };
103 
void setID(const int &id)
Method to change the ID of the item, but only if it is an INVALID_ID.
Definition: MooseEnumItem.C:81
friend std::ostream & operator<<(std::ostream &out, const MooseEnumItem &item)
ostream operator for string printing.
Definition: MooseEnumItem.C:74
const std::string & name() const
Definition: MooseEnumItem.h:37
int _id
The numeric value for item.
std::string _name
Upper case name.
Definition: MooseEnumItem.h:98
static const int INVALID_ID
Definition: MooseEnumItem.h:24
bool operator!=(int value) const
Definition: MooseEnumItem.h:62
MooseEnumItem & operator=(const MooseEnumItem &other)
Definition: MooseEnumItem.C:25
std::string _raw_name
The name as provided in constructor.
Definition: MooseEnumItem.h:95
Base class for MOOSE-based applications.
Definition: MooseApp.h:59
bool operator==(const char *value) const
Comparison operators.
Definition: MooseEnumItem.C:34
bool operator<(const MooseEnumItem &other) const
Less than operator.
Definition: MooseEnumItem.h:74
bool operator==(unsigned short value) const
Definition: MooseEnumItem.h:64
const std::string & rawName() const
Definition: MooseEnumItem.h:38
bool operator!=(const char *value) const
Definition: MooseEnumItem.C:41
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:36
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
~MooseEnumItem()=default
MooseEnumItem(const std::string &name, const int &id=INVALID_ID)
Definition: MooseEnumItem.C:14
bool operator==(int value) const
Definition: MooseEnumItem.h:61
bool operator!=(unsigned short value) const
Definition: MooseEnumItem.h:65