www.mooseframework.org
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
MooseEnum Class Reference

This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It should be initialized with a space-delimited list of strings which become the enum values. More...

#include <MooseEnum.h>

Inheritance diagram for MooseEnum:
[legend]

Public Types

enum  CompareMode { CompareMode::COMPARE_NAME, CompareMode::COMPARE_ID, CompareMode::COMPARE_BOTH }
 Enum item for controlling comparison in the compareCurrent method. More...
 

Public Member Functions

 MooseEnum (std::string names, std::string default_name="", bool allow_out_of_range=false)
 Constructor that takes a list of enumeration values, and a separate string to set a default for this instance. More...
 
 MooseEnum (const MooseEnum &other_enum)
 Copy Constructor for use when creating vectors of MooseEnums. More...
 
MooseEnumoperator= (const MooseEnum &other_enum)=default
 Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used. More...
 
virtual ~MooseEnum ()=default
 
 operator int () const
 Cast operators to make this object behave as value_types and std::string these methods can be used so that this class behaves more like a normal value_type enumeration. More...
 
 operator std::string () const
 
bool operator== (const char *value) const
 Comparison operators for comparing with character constants, MooseEnums or integer values. More...
 
bool operator!= (const char *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 MooseEnum &value) const
 
bool operator!= (const MooseEnum &value) const
 
bool compareCurrent (const MooseEnum &other, CompareMode mode=CompareMode::COMPARE_NAME) const
 Method for comparing currently set values between MooseEnum. More...
 
virtual bool isValid () const override
 IsValid. More...
 
template<typename T >
getEnum () const
 get the current value cast to the enum type T More...
 
virtual void deprecate (const std::string &name, const std::string &raw_name="")
 Deprecates various options in the MOOSE enum. More...
 
std::vector< std::string > getNames () const
 Method for returning a vector of all valid enumeration names for this instance. More...
 
std::string getRawNames () const
 Method for returning the raw name strings for this instance. More...
 
std::vector< intgetIDs () const
 Method for returning a vector of ids for this instance. More...
 
bool isOutOfRangeAllowed () const
 isOutOfRangeAllowed More...
 
const std::set< MooseEnumItem > & items () const
 Return the complete set of available flags. More...
 
void addDocumentation (const std::string &name, const std::string &doc)
 Add an item documentation string. More...
 
const std::map< MooseEnumItem, std::string > & getItemDocumentation () const
 Get the map containing each item's documentation string. More...
 
int getNextValidID () const
 Compute the next valid ID. More...
 
MooseEnumBaseoperator+= (const std::string &name)
 Adds an enumeration item from name. More...
 
MooseEnumBaseoperator+= (const std::initializer_list< std::string > &names)
 Adds enumeration items from a list of names. More...
 
MooseEnumoperator= (const std::string &name)
 Assignment operators/methods. More...
 
MooseEnumoperator= (int value)
 
MooseEnumoperator= (const MooseEnumItem &item)
 
void assign (const std::string &name)
 
void assign (int value)
 
void assign (const MooseEnumItem &item)
 
std::set< MooseEnumItem >::const_iterator find (const MooseEnumItem &other) const
 Locate an item. More...
 
std::set< MooseEnumItem >::const_iterator find (const std::string &name) const
 
std::set< MooseEnumItem >::const_iterator find (int id) const
 

Protected Member Functions

virtual void checkDeprecated () const override
 Check whether the current value is deprecated when called. More...
 
 MooseEnum ()
 Constructor for use by libmesh::Parameters and ReporterMode. More...
 
void checkDeprecated (const MooseEnumItem &item) const
 Check and warn deprecated values. More...
 
void addEnumerationNames (const std::string &names)
 Methods to add possible enumeration value to the enum. More...
 
const MooseEnumItemaddEnumerationName (const std::string &raw_name)
 
const MooseEnumItemaddEnumerationName (const std::string &name, const int &value)
 
const MooseEnumItemaddEnumerationItem (const MooseEnumItem &item)
 

Protected Attributes

std::set< MooseEnumItem_items
 Storage for the assigned items. More...
 
std::map< MooseEnumItem, MooseEnumItem_deprecated_items
 The map of deprecated names and optional replacements. More...
 
bool _allow_out_of_range
 Flag to enable enumeration items not previously defined. More...
 
std::map< MooseEnumItem, std::string > _item_documentation
 The map of items and their respective documentation strings. More...
 

Private Attributes

MooseEnumItem _current
 The current id. More...
 

Friends

class libMesh::Parameters
 
std::ostream & operator<< (std::ostream &out, const MooseEnum &obj)
 Operator for printing to iostreams. More...
 

Detailed Description

This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It should be initialized with a space-delimited list of strings which become the enum values.

You may also optionally supply numeric ints for one or more values similar to a C++ enum. This is done with the "=" sign (no spaces). It can be used any place where an integer (switch statements), const char* or std::string is expected. In addition the InputParameters system has full support for this Enum type

Definition at line 31 of file MooseEnum.h.

Member Enumeration Documentation

◆ CompareMode

Enum item for controlling comparison in the compareCurrent method.

Enumerator
COMPARE_NAME 
COMPARE_ID 
COMPARE_BOTH 

Definition at line 37 of file MooseEnum.h.

38  {
39  COMPARE_NAME,
40  COMPARE_ID,
41  COMPARE_BOTH
42  };

Constructor & Destructor Documentation

◆ MooseEnum() [1/3]

MooseEnum::MooseEnum ( std::string  names,
std::string  default_name = "",
bool  allow_out_of_range = false 
)

Constructor that takes a list of enumeration values, and a separate string to set a default for this instance.

Parameters
names- a list of names for this enumeration
default_name- the default value for this enumeration instance
allow_out_of_range- determines whether this enumeration will accept values outside of it's range of defined values.

Definition at line 22 of file MooseEnum.C.

23  : MooseEnumBase(names, allow_out_of_range), _current("", MooseEnumItem::INVALID_ID)
24 {
25  *this = default_name;
26 }
static const int INVALID_ID
Definition: MooseEnumItem.h:21
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144

◆ MooseEnum() [2/3]

MooseEnum::MooseEnum ( const MooseEnum other_enum)

Copy Constructor for use when creating vectors of MooseEnums.

Parameters
other_enum- The other enumeration to copy state from

Definition at line 28 of file MooseEnum.C.

29  : MooseEnumBase(other_enum), _current(other_enum._current)
30 {
31 }
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144

◆ ~MooseEnum()

virtual MooseEnum::~MooseEnum ( )
virtualdefault

◆ MooseEnum() [3/3]

MooseEnum::MooseEnum ( )
protected

Constructor for use by libmesh::Parameters and ReporterMode.

Private constuctor for use by libmesh::Parameters.

Definition at line 36 of file MooseEnum.C.

static const int INVALID_ID
Definition: MooseEnumItem.h:21
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144

Member Function Documentation

◆ addDocumentation()

void MooseEnumBase::addDocumentation ( const std::string &  name,
const std::string &  doc 
)
inherited

Add an item documentation string.

Definition at line 175 of file MooseEnumBase.C.

Referenced by PseudoTimestep::validParams(), and ReferenceResidualProblem::validParams().

176 {
177  auto it = find(name);
178  if (it == _items.end())
179  mooseError("Item '", name, "' not found in addDocumentation.");
180  _item_documentation[*it] = doc;
181 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
std::map< MooseEnumItem, std::string > _item_documentation
The map of items and their respective documentation strings.
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.

◆ addEnumerationItem()

const MooseEnumItem & MooseEnumBase::addEnumerationItem ( const MooseEnumItem item)
protectedinherited

Definition at line 117 of file MooseEnumBase.C.

Referenced by ExecFlagEnum::addAvailableFlags(), MooseEnumBase::addEnumerationName(), MultiMooseEnum::assign(), and ReporterProducerEnum::insert().

118 {
119  const auto & item_it = find(item);
120  if (item_it != _items.end()) // do nothing for identical insertions
121  return *item_it;
122 
123  if (find(item.id()) != _items.end())
124  mooseError("The supplied id ",
125  item.id(),
126  " already exists in the enumeration, cannot not add '",
127  item,
128  "'.");
129  if (find(item.name()) != _items.end())
130  mooseError("The name '", item.name(), "' already exists in the enumeration.");
131 
132  return *_items.insert(item).first;
133 }
const std::string & name() const
Definition: MooseEnumItem.h:35
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
std::set< MooseEnumItem > _items
Storage for the assigned items.
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.

◆ addEnumerationName() [1/2]

const MooseEnumItem & MooseEnumBase::addEnumerationName ( const std::string &  raw_name)
protectedinherited

Definition at line 73 of file MooseEnumBase.C.

Referenced by MooseEnumBase::addEnumerationNames(), and MooseEnumBase::operator+=().

74 {
75  // Make sure the option is not malformed
76  if (raw_name.find_first_of('=') == 0 || raw_name.find_last_of('=') == raw_name.length() - 1)
77  mooseError("You cannot place whitespace around the '=' character in MooseEnumBase");
78 
79  // Split on equals sign
80  std::vector<std::string> name_value;
81  MooseUtils::tokenize(MooseUtils::trim(raw_name), name_value, 1, "=");
82 
83  // There should be one or two items in the name_value
84  if (name_value.size() < 1 || name_value.size() > 2)
85  mooseError("Invalid option supplied in MooseEnumBase: ", raw_name);
86 
87  // Remove un-wanted space around string
88  name_value[0] = MooseUtils::trim(name_value[0]);
89 
90  // See if there is a value supplied for this option
91  // strtol allows for proper conversions of both int and hex strings
92  int value;
93  if (name_value.size() == 2)
94  value = std::strtol(name_value[1].c_str(), NULL, 0);
95  else
97 
98  return addEnumerationName(name_value[0], value);
99 }
int getNextValidID() const
Compute the next valid ID.
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:779
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const MooseEnumItem & addEnumerationName(const std::string &raw_name)
Definition: MooseEnumBase.C:73
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:214

◆ addEnumerationName() [2/2]

const MooseEnumItem & MooseEnumBase::addEnumerationName ( const std::string &  name,
const int value 
)
protectedinherited

Definition at line 111 of file MooseEnumBase.C.

112 {
113  return addEnumerationItem(MooseEnumItem(name, value));
114 }
const MooseEnumItem & addEnumerationItem(const MooseEnumItem &item)
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ addEnumerationNames()

void MooseEnumBase::addEnumerationNames ( const std::string &  names)
protectedinherited

Methods to add possible enumeration value to the enum.

The MooseEnum/MultiMooseEnum are not designed to be modified, with respect to the list of possible values. However, this is not the case for the ExecFlagEnum which is a special type of MultiMooseEnum for managing the "execute_on" flags. These methods are used by ExecFlagEnum to allow users to modify the available execute flags for their object.

Definition at line 64 of file MooseEnumBase.C.

Referenced by MooseEnumBase::MooseEnumBase().

65 {
66  std::vector<std::string> elements;
67  MooseUtils::tokenize(names, elements, 1, " ");
68  for (const std::string & raw_name : elements)
69  addEnumerationName(raw_name);
70 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:779
const MooseEnumItem & addEnumerationName(const std::string &raw_name)
Definition: MooseEnumBase.C:73

◆ assign() [1/3]

void MooseEnum::assign ( const std::string &  name)

Definition at line 60 of file MooseEnum.C.

Referenced by ReporterContextBase::init(), and operator=().

61 {
62  if (name == "")
63  {
65  return;
66  }
67 
68  std::set<MooseEnumItem>::const_iterator iter = find(name);
69  if (iter == _items.end())
70  {
71  if (!_allow_out_of_range) // Are out of range values allowed?
72  mooseError("Invalid option \"",
73  name,
74  "\" in MooseEnum. Valid options (not case-sensitive) are \"",
75  getRawNames(),
76  "\".");
77  else
78  {
80  _items.insert(_current);
81  }
82  }
83  else
84  _current = *iter;
85 
87 }
int getNextValidID() const
Compute the next valid ID.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
static const int INVALID_ID
Definition: MooseEnumItem.h:21
virtual void checkDeprecated() const override
Check whether the current value is deprecated when called.
Definition: MooseEnum.C:202
std::string getRawNames() const
Method for returning the raw name strings for this instance.
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
bool _allow_out_of_range
Flag to enable enumeration items not previously defined.

◆ assign() [2/3]

void MooseEnum::assign ( int  value)

Definition at line 90 of file MooseEnum.C.

91 {
92  if (value == MooseEnumItem::INVALID_ID)
93  {
95  return;
96  }
97 
98  std::set<MooseEnumItem>::const_iterator iter = find(value);
99  if (iter == _items.end())
100  mooseError("Invalid id \"",
101  value,
102  "\" in MooseEnum. Valid ids are \"",
104  "\".");
105  else
106  _current = *iter;
107 
108  checkDeprecated();
109 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
static const int INVALID_ID
Definition: MooseEnumItem.h:21
virtual void checkDeprecated() const override
Check whether the current value is deprecated when called.
Definition: MooseEnum.C:202
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
std::vector< int > getIDs() const
Method for returning a vector of ids for this instance.
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.

◆ assign() [3/3]

void MooseEnum::assign ( const MooseEnumItem item)

Definition at line 112 of file MooseEnum.C.

113 {
114  std::set<MooseEnumItem>::const_iterator iter = find(item);
115  if (iter == _items.end())
116  mooseError("Invalid item \"",
117  item,
118  "\" in MooseEnum. Valid ids are \"",
120  "\".");
121  else
122  _current = *iter;
123 
124  checkDeprecated();
125 }
const std::set< MooseEnumItem > & items() const
Return the complete set of available flags.
Definition: MooseEnumBase.h:93
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
virtual void checkDeprecated() const override
Check whether the current value is deprecated when called.
Definition: MooseEnum.C:202
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.

◆ checkDeprecated() [1/2]

void MooseEnum::checkDeprecated ( ) const
overrideprotectedvirtual

Check whether the current value is deprecated when called.

Implements MooseEnumBase.

Definition at line 202 of file MooseEnum.C.

Referenced by assign().

203 {
205 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.

◆ checkDeprecated() [2/2]

void MooseEnumBase::checkDeprecated ( const MooseEnumItem item) const
protectedinherited

Check and warn deprecated values.

Definition at line 136 of file MooseEnumBase.C.

137 {
138  std::map<MooseEnumItem, MooseEnumItem>::const_iterator it = _deprecated_items.find(item);
139  if (it != _deprecated_items.end())
140  {
141  if (it->second.name().empty())
142  mooseWarning(item.name() + " is deprecated");
143  else
144  mooseWarning(item.name() + " is deprecated, consider using " + it->second.name());
145  }
146 }
const std::string & name() const
Definition: MooseEnumItem.h:35
std::map< MooseEnumItem, MooseEnumItem > _deprecated_items
The map of deprecated names and optional replacements.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:296

◆ compareCurrent()

bool MooseEnum::compareCurrent ( const MooseEnum other,
CompareMode  mode = CompareMode::COMPARE_NAME 
) const

Method for comparing currently set values between MooseEnum.

Definition at line 171 of file MooseEnum.C.

172 {
173  switch (mode)
174  {
176  return (_current.id() == other._current.id()) && (_current.name() == other._current.name());
178  return _current.name() == other._current.name();
180  return _current.id() == other._current.id();
181  }
182  return false;
183 }
const std::string & name() const
Definition: MooseEnumItem.h:35
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34

◆ deprecate()

void MooseEnumBase::deprecate ( const std::string &  name,
const std::string &  raw_name = "" 
)
virtualinherited

Deprecates various options in the MOOSE enum.

For each deprecated option, you may supply an optional new option that will be used in a message telling the user which new option replaces the old one.

Definition at line 45 of file MooseEnumBase.C.

46 {
47  std::set<MooseEnumItem>::const_iterator deprecated = find(name);
48  if (deprecated == _items.end())
49  mooseError("Cannot deprecate the enum item ", name, ", is not an available value.");
50 
51  std::set<MooseEnumItem>::const_iterator replaced = find(raw_name);
52  if (replaced == _items.end())
53  mooseError("Cannot deprecate the enum item ",
54  name,
55  ", since the replaced item ",
56  raw_name,
57  " it is not an available value.");
58 
59  _deprecated_items.emplace(std::make_pair(*deprecated, *replaced));
61 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
std::map< MooseEnumItem, MooseEnumItem > _deprecated_items
The map of deprecated names and optional replacements.
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.

◆ find() [1/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const MooseEnumItem other) const
inherited

Locate an item.

Definition at line 206 of file MooseEnumBase.C.

Referenced by MooseEnumBase::addDocumentation(), MooseEnumBase::addEnumerationItem(), ExecFlagEnum::appendCurrent(), assign(), MultiMooseEnum::assign(), MooseEnumBase::deprecate(), operator==(), moose::internal::ExecFlagRegistry::registerFlag(), ExecFlagEnum::removeAvailableFlags(), CreateExecutionerAction::setupAutoPreconditioning(), and ReadExecutorParamsAction::setupAutoPreconditioning().

207 {
208  const auto upper = MooseUtils::toUpper(other.name());
209  return std::find_if(_items.begin(),
210  _items.end(),
211  [&other, &upper](MooseEnumItem const & item)
212  { return item.id() == other.id() && item.name() == upper; });
213 }
const std::string & name() const
Definition: MooseEnumItem.h:35
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:1037
std::set< MooseEnumItem > _items
Storage for the assigned items.
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

◆ find() [2/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const std::string &  name) const
inherited

Definition at line 190 of file MooseEnumBase.C.

191 {
192  std::string upper = MooseUtils::toUpper(name);
193  return std::find_if(_items.begin(),
194  _items.end(),
195  [&upper](MooseEnumItem const & item) { return item.name() == upper; });
196 }
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:1037
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ find() [3/3]

std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( int  id) const
inherited

Definition at line 199 of file MooseEnumBase.C.

200 {
201  return std::find_if(
202  _items.begin(), _items.end(), [&id](MooseEnumItem const & item) { return item.id() == id; });
203 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ getEnum()

template<typename T >
T MooseEnum::getEnum ( ) const

get the current value cast to the enum type T

Definition at line 149 of file MooseEnum.h.

150 {
151 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
152  static_assert(std::is_enum<T>::value == true,
153  "The type requested from MooseEnum::getEnum must be an enum type!\n\n");
154 #endif
155  return static_cast<T>(_current.id());
156 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34

◆ getIDs()

std::vector< int > MooseEnumBase::getIDs ( ) const
inherited

Method for returning a vector of ids for this instance.

Returns
a vector of ints containing the possible ids for this enumeration

Definition at line 165 of file MooseEnumBase.C.

Referenced by assign().

166 {
167  std::vector<int> out;
168  out.reserve(_items.size());
169  for (const auto & item : _items)
170  out.push_back(item.id());
171  return out;
172 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
OStreamProxy out

◆ getItemDocumentation()

const std::map< MooseEnumItem, std::string > & MooseEnumBase::getItemDocumentation ( ) const
inherited

Get the map containing each item's documentation string.

Definition at line 184 of file MooseEnumBase.C.

185 {
186  return _item_documentation;
187 }
std::map< MooseEnumItem, std::string > _item_documentation
The map of items and their respective documentation strings.

◆ getNames()

std::vector< std::string > MooseEnumBase::getNames ( ) const
inherited

Method for returning a vector of all valid enumeration names for this instance.

Returns
a vector of names

Definition at line 149 of file MooseEnumBase.C.

Referenced by ExecFlagEnum::getDocString().

150 {
151  std::vector<std::string> out;
152  out.reserve(_items.size());
153  for (const auto & item : _items)
154  out.push_back(item.name());
155  return out;
156 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
OStreamProxy out

◆ getNextValidID()

int MooseEnumBase::getNextValidID ( ) const
inherited

Compute the next valid ID.

Definition at line 102 of file MooseEnumBase.C.

Referenced by MooseEnumBase::addEnumerationName(), assign(), MultiMooseEnum::assign(), and moose::internal::ExecFlagRegistry::registerFlag().

103 {
104  int value = -1; // Use -1 so if no values exist the first will be zero
105  for (const auto & item : _items)
106  value = std::max(value, item.id());
107  return ++value;
108 }
auto max(const L &left, const R &right)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::set< MooseEnumItem > _items
Storage for the assigned items.

◆ getRawNames()

std::string MooseEnumBase::getRawNames ( ) const
inherited

Method for returning the raw name strings for this instance.

Returns
a space separated list of names

Definition at line 159 of file MooseEnumBase.C.

Referenced by assign(), MultiMooseEnum::assign(), AdvancedOutput::enableOutputTypes(), operator==(), PiecewiseConstant::validParams(), LeastSquaresFit::validParams(), and ComparisonPostprocessor::validParams().

160 {
161  return Moose::stringify(_items, " ");
162 }
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
std::set< MooseEnumItem > _items
Storage for the assigned items.

◆ isOutOfRangeAllowed()

bool MooseEnumBase::isOutOfRangeAllowed ( ) const
inlineinherited

isOutOfRangeAllowed

Returns
- a Boolean indicating whether enum names out of range are allowed

Definition at line 88 of file MooseEnumBase.h.

88 { return _allow_out_of_range; }
bool _allow_out_of_range
Flag to enable enumeration items not previously defined.

◆ isValid()

virtual bool MooseEnum::isValid ( ) const
inlineoverridevirtual

IsValid.

Returns
- a Boolean indicating whether this Enumeration has been set

Implements MooseEnumBase.

Definition at line 116 of file MooseEnum.h.

Referenced by MultiAppPostprocessorTransfer::MultiAppPostprocessorTransfer().

116 { return _current.id() > MooseEnumItem::INVALID_ID; }
static const int INVALID_ID
Definition: MooseEnumItem.h:21
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34

◆ items()

const std::set<MooseEnumItem>& MooseEnumBase::items ( ) const
inlineinherited

Return the complete set of available flags.

Definition at line 93 of file MooseEnumBase.h.

Referenced by assign(), CreateExecutionerAction::setupAutoPreconditioning(), and ReadExecutorParamsAction::setupAutoPreconditioning().

93 { return _items; }
std::set< MooseEnumItem > _items
Storage for the assigned items.

◆ operator int()

MooseEnum::operator int ( ) const
inline

Cast operators to make this object behave as value_types and std::string these methods can be used so that this class behaves more like a normal value_type enumeration.

Definition at line 72 of file MooseEnum.h.

72 { return _current.id(); }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const int & id() const
Return the numeric, name, or raw name.
Definition: MooseEnumItem.h:34

◆ operator std::string()

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

Definition at line 73 of file MooseEnum.h.

73 { return _current.rawName(); }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const std::string & rawName() const
Definition: MooseEnumItem.h:36

◆ operator!=() [1/4]

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

Definition at line 141 of file MooseEnum.C.

142 {
143  return !(*this == name);
144 }
std::string name(const ElemQuality q)

◆ operator!=() [2/4]

bool MooseEnum::operator!= ( int  value) const

Definition at line 153 of file MooseEnum.C.

154 {
155  return value != _current;
156 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ operator!=() [3/4]

bool MooseEnum::operator!= ( unsigned short  value) const

Definition at line 165 of file MooseEnum.C.

166 {
167  return value != _current;
168 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ operator!=() [4/4]

bool MooseEnum::operator!= ( const MooseEnum value) const

Definition at line 194 of file MooseEnum.C.

195 {
196  mooseDeprecated("This method will be removed because the meaning is not well defined, please use "
197  "the 'compareCurrent' method instead.");
198  return value._current.name() != _current.name();
199 }
const std::string & name() const
Definition: MooseEnumItem.h:35
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:313

◆ operator+=() [1/2]

MooseEnumBase & MooseEnumBase::operator+= ( const std::string &  name)
inherited

Adds an enumeration item from name.

Definition at line 216 of file MooseEnumBase.C.

217 {
218  addEnumerationName(name);
219  checkDeprecated();
220  return *this;
221 }
const MooseEnumItem & addEnumerationName(const std::string &raw_name)
Definition: MooseEnumBase.C:73
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.

◆ operator+=() [2/2]

MooseEnumBase & MooseEnumBase::operator+= ( const std::initializer_list< std::string > &  names)
inherited

Adds enumeration items from a list of names.

Definition at line 224 of file MooseEnumBase.C.

225 {
226  for (const auto & name : names)
227  *this += name;
228  return *this;
229 }
std::string name(const ElemQuality q)

◆ operator=() [1/4]

MooseEnum& MooseEnum::operator= ( const MooseEnum other_enum)
default

Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used.

◆ operator=() [2/4]

MooseEnum & MooseEnum::operator= ( const std::string &  name)

Assignment operators/methods.

Parameters
name/int- a string or int representing one of the enumeration values.
Returns
A reference to this object for chaining

Definition at line 39 of file MooseEnum.C.

40 {
41  assign(name);
42  return *this;
43 }
void assign(const std::string &name)
Definition: MooseEnum.C:60

◆ operator=() [3/4]

MooseEnum & MooseEnum::operator= ( int  value)

Definition at line 46 of file MooseEnum.C.

47 {
48  assign(value);
49  return *this;
50 }
void assign(const std::string &name)
Definition: MooseEnum.C:60

◆ operator=() [4/4]

MooseEnum & MooseEnum::operator= ( const MooseEnumItem item)

Definition at line 53 of file MooseEnum.C.

54 {
55  assign(item);
56  return *this;
57 }
void assign(const std::string &name)
Definition: MooseEnum.C:60

◆ operator==() [1/4]

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

Comparison operators for comparing with character constants, MooseEnums or integer values.

Parameters
value- RHS value to compare against
Returns
bool - the truth value for the comparison

Definition at line 128 of file MooseEnum.C.

129 {
130  std::string upper(MooseUtils::toUpper(name));
131 
132  mooseAssert(_allow_out_of_range || find(upper) != _items.end(),
133  "Invalid string comparison \"" + upper +
134  "\" in MooseEnum. Valid options (not case-sensitive) are \"" + getRawNames() +
135  "\".");
136 
137  return _current == upper;
138 }
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:1037
std::string getRawNames() const
Method for returning the raw name strings for this instance.
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::set< MooseEnumItem >::const_iterator find(const MooseEnumItem &other) const
Locate an item.
bool _allow_out_of_range
Flag to enable enumeration items not previously defined.

◆ operator==() [2/4]

bool MooseEnum::operator== ( int  value) const

Definition at line 147 of file MooseEnum.C.

148 {
149  return value == _current;
150 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ operator==() [3/4]

bool MooseEnum::operator== ( unsigned short  value) const

Definition at line 159 of file MooseEnum.C.

160 {
161  return value == _current;
162 }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ operator==() [4/4]

bool MooseEnum::operator== ( const MooseEnum value) const

Definition at line 186 of file MooseEnum.C.

187 {
188  mooseDeprecated("This method will be removed because the meaning is not well defined, please use "
189  "the 'compareCurrent' method instead.");
190  return value._current.name() == _current.name();
191 }
const std::string & name() const
Definition: MooseEnumItem.h:35
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:313

Friends And Related Function Documentation

◆ libMesh::Parameters

friend class libMesh::Parameters
friend

Definition at line 120 of file MooseEnum.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const MooseEnum obj 
)
friend

Operator for printing to iostreams.

Definition at line 123 of file MooseEnum.h.

124  {
125  out << obj._current.rawName();
126  return out;
127  }
MooseEnumItem _current
The current id.
Definition: MooseEnum.h:144
const std::string & rawName() const
Definition: MooseEnumItem.h:36
OStreamProxy out

Member Data Documentation

◆ _allow_out_of_range

bool MooseEnumBase::_allow_out_of_range
protectedinherited

Flag to enable enumeration items not previously defined.

Definition at line 163 of file MooseEnumBase.h.

Referenced by assign(), MultiMooseEnum::assign(), MooseEnumBase::isOutOfRangeAllowed(), and operator==().

◆ _current

MooseEnumItem MooseEnum::_current
private

◆ _deprecated_items

std::map<MooseEnumItem, MooseEnumItem> MooseEnumBase::_deprecated_items
protectedinherited

The map of deprecated names and optional replacements.

Definition at line 160 of file MooseEnumBase.h.

Referenced by MooseEnumBase::checkDeprecated(), and MooseEnumBase::deprecate().

◆ _item_documentation

std::map<MooseEnumItem, std::string> MooseEnumBase::_item_documentation
protectedinherited

The map of items and their respective documentation strings.

Definition at line 166 of file MooseEnumBase.h.

Referenced by MooseEnumBase::addDocumentation(), and MooseEnumBase::getItemDocumentation().

◆ _items

std::set<MooseEnumItem> MooseEnumBase::_items
protectedinherited

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