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>
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... | |
MooseEnum & | operator= (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 > | |
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< int > | getIDs () 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... | |
MooseEnumBase & | operator+= (const std::string &name) |
Adds an enumeration item from name. More... | |
MooseEnumBase & | operator+= (const std::initializer_list< std::string > &names) |
Adds enumeration items from a list of names. More... | |
MooseEnum & | operator= (const std::string &name) |
Assignment operators/methods. More... | |
MooseEnum & | operator= (int value) |
MooseEnum & | operator= (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 MooseEnumItem & | addEnumerationName (const std::string &raw_name) |
const MooseEnumItem & | addEnumerationName (const std::string &name, const int &value) |
const MooseEnumItem & | addEnumerationItem (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... | |
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.
|
strong |
Enum item for controlling comparison in the compareCurrent method.
Enumerator | |
---|---|
COMPARE_NAME | |
COMPARE_ID | |
COMPARE_BOTH |
Definition at line 37 of file MooseEnum.h.
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.
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.
MooseEnum::MooseEnum | ( | const MooseEnum & | other_enum | ) |
Copy Constructor for use when creating vectors of MooseEnums.
other_enum | - The other enumeration to copy state from |
Definition at line 28 of file MooseEnum.C.
|
virtualdefault |
|
protected |
Constructor for use by libmesh::Parameters and ReporterMode.
Private constuctor for use by libmesh::Parameters.
Definition at line 36 of file MooseEnum.C.
|
inherited |
Add an item documentation string.
Definition at line 175 of file MooseEnumBase.C.
Referenced by PseudoTimestep::validParams(), and ReferenceResidualProblem::validParams().
|
protectedinherited |
Definition at line 117 of file MooseEnumBase.C.
Referenced by ExecFlagEnum::addAvailableFlags(), MooseEnumBase::addEnumerationName(), MultiMooseEnum::assign(), and ReporterProducerEnum::insert().
|
protectedinherited |
Definition at line 73 of file MooseEnumBase.C.
Referenced by MooseEnumBase::addEnumerationNames(), and MooseEnumBase::operator+=().
|
protectedinherited |
Definition at line 111 of file MooseEnumBase.C.
|
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().
void MooseEnum::assign | ( | const std::string & | name | ) |
Definition at line 60 of file MooseEnum.C.
Referenced by ReporterContextBase::init(), and operator=().
Definition at line 90 of file MooseEnum.C.
void MooseEnum::assign | ( | const MooseEnumItem & | item | ) |
Definition at line 112 of file MooseEnum.C.
|
overrideprotectedvirtual |
Check whether the current value is deprecated when called.
Implements MooseEnumBase.
Definition at line 202 of file MooseEnum.C.
Referenced by assign().
|
protectedinherited |
Check and warn deprecated values.
Definition at line 136 of file MooseEnumBase.C.
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.
|
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.
|
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().
|
inherited |
Definition at line 190 of file MooseEnumBase.C.
|
inherited |
Definition at line 199 of file MooseEnumBase.C.
T MooseEnum::getEnum | ( | ) | const |
get the current value cast to the enum type T
Definition at line 149 of file MooseEnum.h.
|
inherited |
Method for returning a vector of ids for this instance.
Definition at line 165 of file MooseEnumBase.C.
Referenced by assign().
|
inherited |
Get the map containing each item's documentation string.
Definition at line 184 of file MooseEnumBase.C.
|
inherited |
Method for returning a vector of all valid enumeration names for this instance.
Definition at line 149 of file MooseEnumBase.C.
Referenced by ExecFlagEnum::getDocString().
|
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().
|
inherited |
Method for returning the raw name strings for this instance.
Definition at line 159 of file MooseEnumBase.C.
Referenced by assign(), MultiMooseEnum::assign(), AdvancedOutput::enableOutputTypes(), operator==(), PiecewiseConstant::validParams(), LeastSquaresFit::validParams(), and ComparisonPostprocessor::validParams().
|
inlineinherited |
isOutOfRangeAllowed
Definition at line 88 of file MooseEnumBase.h.
|
inlineoverridevirtual |
IsValid.
Implements MooseEnumBase.
Definition at line 116 of file MooseEnum.h.
Referenced by MultiAppPostprocessorTransfer::MultiAppPostprocessorTransfer().
|
inlineinherited |
Return the complete set of available flags.
Definition at line 93 of file MooseEnumBase.h.
Referenced by assign(), CreateExecutionerAction::setupAutoPreconditioning(), and ReadExecutorParamsAction::setupAutoPreconditioning().
|
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.
|
inline |
Definition at line 73 of file MooseEnum.h.
bool MooseEnum::operator!= | ( | const char * | value | ) | const |
Definition at line 141 of file MooseEnum.C.
bool MooseEnum::operator!= | ( | int | value | ) | const |
Definition at line 153 of file MooseEnum.C.
bool MooseEnum::operator!= | ( | unsigned short | value | ) | const |
Definition at line 165 of file MooseEnum.C.
bool MooseEnum::operator!= | ( | const MooseEnum & | value | ) | const |
Definition at line 194 of file MooseEnum.C.
|
inherited |
Adds an enumeration item from name.
Definition at line 216 of file MooseEnumBase.C.
|
inherited |
Adds enumeration items from a list of names.
Definition at line 224 of file MooseEnumBase.C.
Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used.
MooseEnum & MooseEnum::operator= | ( | const std::string & | name | ) |
Assignment operators/methods.
name/int | - a string or int representing one of the enumeration values. |
Definition at line 39 of file MooseEnum.C.
Definition at line 46 of file MooseEnum.C.
MooseEnum & MooseEnum::operator= | ( | const MooseEnumItem & | item | ) |
Definition at line 53 of file MooseEnum.C.
bool MooseEnum::operator== | ( | const char * | value | ) | const |
Comparison operators for comparing with character constants, MooseEnums or integer values.
value | - RHS value to compare against |
Definition at line 128 of file MooseEnum.C.
bool MooseEnum::operator== | ( | int | value | ) | const |
Definition at line 147 of file MooseEnum.C.
bool MooseEnum::operator== | ( | unsigned short | value | ) | const |
Definition at line 159 of file MooseEnum.C.
bool MooseEnum::operator== | ( | const MooseEnum & | value | ) | const |
Definition at line 186 of file MooseEnum.C.
|
friend |
Definition at line 120 of file MooseEnum.h.
|
friend |
|
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==().
|
private |
The current id.
Definition at line 144 of file MooseEnum.h.
Referenced by assign(), checkDeprecated(), compareCurrent(), getEnum(), isValid(), operator int(), operator std::string(), operator!=(), and operator==().
|
protectedinherited |
The map of deprecated names and optional replacements.
Definition at line 160 of file MooseEnumBase.h.
Referenced by MooseEnumBase::checkDeprecated(), and MooseEnumBase::deprecate().
|
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().
|
protectedinherited |
Storage for the assigned items.
Definition at line 157 of file MooseEnumBase.h.
Referenced by MooseEnumBase::addDocumentation(), MooseEnumBase::addEnumerationItem(), ExecFlagEnum::appendCurrent(), assign(), MultiMooseEnum::assign(), ReporterProducerEnum::clear(), MooseEnumBase::deprecate(), MooseEnumBase::find(), MooseEnumBase::getIDs(), MooseEnumBase::getNames(), MooseEnumBase::getNextValidID(), MooseEnumBase::getRawNames(), ExecFlagEnum::items(), MooseEnumBase::items(), operator==(), and ExecFlagEnum::removeAvailableFlags().