This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It should be initialized with a comma-separated list of strings which become the enum values. More...
#include <MultiMooseEnum.h>
Public Member Functions | |
MultiMooseEnum (std::string names, std::string default_names="", 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... | |
MultiMooseEnum (const MultiMooseEnum &other_enum) | |
Copy Constructor. More... | |
MultiMooseEnum & | operator= (const MultiMooseEnum &other_enum)=default |
Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used. More... | |
const std::string & | operator[] (unsigned int i) const |
Indexing operator Operator to retrieve an item from the MultiMooseEnum. More... | |
unsigned int | get (unsigned int i) const |
Indexing operator Operator to retrieve an item from the MultiMooseEnum. More... | |
template<typename T > | |
std::vector< T > | getEnum () const |
get the current values cast to a vector of enum type T More... | |
void | clear () |
Clear the MultiMooseEnum. More... | |
unsigned int | size () const |
Return the number of active items in the MultiMooseEnum. More... | |
virtual bool | isValid () const override |
IsValid. 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... | |
bool | operator== (const MultiMooseEnum &value) const |
Comparison operators for comparing with character constants, MultiMooseEnums or integer values. More... | |
bool | operator!= (const MultiMooseEnum &value) const |
bool | contains (const std::string &value) const |
Contains methods for seeing if a value is in the MultiMooseEnum. More... | |
bool | contains (int value) const |
bool | contains (unsigned short value) const |
bool | contains (const MultiMooseEnum &value) const |
bool | contains (const MooseEnumItem &value) const |
MultiMooseEnum & | operator= (const std::string &names) |
Assignment operators. More... | |
MultiMooseEnum & | operator= (const std::vector< std::string > &names) |
MultiMooseEnum & | operator= (const std::set< std::string > &names) |
void | erase (const std::string &names) |
Un-assign a value. More... | |
void | erase (const std::vector< std::string > &names) |
void | erase (const std::set< std::string > &names) |
void | push_back (const std::string &names) |
Insert operators Operator to insert (push_back) values into the enum. More... | |
void | push_back (const std::vector< std::string > &names) |
void | push_back (const std::set< std::string > &names) |
void | push_back (const MultiMooseEnum &other_enum) |
MooseEnumIterator | begin () const |
Returns a begin/end iterator to all of the items in the enum. More... | |
MooseEnumIterator | end () const |
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 any of the current values are deprecated when called. More... | |
template<typename InputIterator > | |
MultiMooseEnum & | assign (InputIterator first, InputIterator last, bool append) |
Helper method for all inserts and assignment operators. More... | |
template<typename InputIterator > | |
void | remove (InputIterator first, InputIterator last) |
Helper method for un-assigning enumeration values. More... | |
void | setCurrentItems (const std::vector< MooseEnumItem > ¤t) |
Set the current items. More... | |
MultiMooseEnum () | |
Protected constructor for use by libmesh::Parameters. More... | |
MultiMooseEnum (const MooseEnumBase &other_enum) | |
Protected constructor that can accept a MooseEnumBase for ::withOptionsFrom() 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::vector< MooseEnumItem > | _current |
The current id. More... | |
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... | |
Friends | |
class | libMesh::Parameters |
std::ostream & | operator<< (std::ostream &out, const MultiMooseEnum &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 comma-separated 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. 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 38 of file MultiMooseEnum.h.
MultiMooseEnum::MultiMooseEnum | ( | std::string | names, |
std::string | default_names = "" , |
||
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_names | - 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 MultiMooseEnum.C.
MultiMooseEnum::MultiMooseEnum | ( | const MultiMooseEnum & | other_enum | ) |
Copy Constructor.
other_enum | - The other enumeration to copy state from |
Definition at line 30 of file MultiMooseEnum.C.
|
protected |
Protected constructor for use by libmesh::Parameters.
Private constuctor for use by libmesh::Parameters.
Definition at line 38 of file MultiMooseEnum.C.
|
protected |
Protected constructor that can accept a MooseEnumBase for ::withOptionsFrom()
other_enum | - MooseEnumBase type to copy names and out-of-range data from |
Definition at line 40 of file MultiMooseEnum.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(), 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().
|
protected |
Helper method for all inserts and assignment operators.
Definition at line 193 of file MultiMooseEnum.C.
Referenced by operator=(), and push_back().
|
inline |
Returns a begin/end iterator to all of the items in the enum.
Items will always be capitalized.
Definition at line 149 of file MultiMooseEnum.h.
Referenced by FunctorADConverterTempl< T >::FunctorADConverterTempl(), FunctorSmootherTempl< T >::FunctorSmootherTempl(), GenericFunctorGradientMaterialTempl< is_ad >::GenericFunctorGradientMaterialTempl(), GenericFunctorMaterialTempl< is_ad >::GenericFunctorMaterialTempl(), GenericVectorFunctorMaterialTempl< is_ad >::GenericVectorFunctorMaterialTempl(), ParsedFunctorMaterialTempl< is_ad >::ParsedFunctorMaterialTempl(), PiecewiseByBlockFunctorMaterialTempl< T >::PiecewiseByBlockFunctorMaterialTempl(), push_back(), and VectorMagnitudeFunctorMaterialTempl< is_ad >::VectorMagnitudeFunctorMaterialTempl().
|
protectedinherited |
Check and warn deprecated values.
Definition at line 136 of file MooseEnumBase.C.
|
overrideprotectedvirtual |
Check whether any of the current values are deprecated when called.
Implements MooseEnumBase.
Definition at line 250 of file MultiMooseEnum.C.
Referenced by assign(), and ExecFlagEnum::operator+=().
void MultiMooseEnum::clear | ( | ) |
Clear the MultiMooseEnum.
Definition at line 238 of file MultiMooseEnum.C.
Referenced by assign(), AdvancedOutput::initExecutionTypes(), ExecFlagEnum::operator=(), and SetupInterface::SetupInterface().
bool MultiMooseEnum::contains | ( | const std::string & | value | ) | const |
Contains methods for seeing if a value is in the MultiMooseEnum.
Definition at line 61 of file MultiMooseEnum.C.
Referenced by FEProblemBase::addTransfer(), AdvancedOutput::addValidParams(), MultiAppVariableValueSamplePostprocessorTransfer::cacheElemToPostprocessorData(), ChangeOverFixedPointPostprocessor::ChangeOverFixedPointPostprocessor(), ChangeOverTimePostprocessor::ChangeOverTimePostprocessor(), contains(), IterationInfo::declareHelper(), MeshInfo::declareHelper(), EigenExecutionerBase::init(), MultiAppReporterTransfer::initialSetup(), IntegralPreservingFunctionIC::initialSetup(), MultiAppVariableValueSamplePostprocessorTransfer::initialSetup(), Console::initialSetup(), EigenExecutionerBase::inversePowerIteration(), MultiAppReporterTransfer::MultiAppReporterTransfer(), MultiAppVariableValueSamplePostprocessorTransfer::MultiAppVariableValueSamplePostprocessorTransfer(), operator==(), Console::output(), JSONOutput::outputReporters(), Console::outputSystemInformation(), XMLOutput::outputVectorPostprocessors(), MeshInfo::possiblyAddSidesetInfo(), MeshInfo::possiblyAddSubdomainInfo(), EigenExecutionerBase::postExecute(), Moose::PetscSupport::processPetscFlags(), Moose::PetscSupport::processPetscPairs(), ExecFlagEnum::removeAvailableFlags(), MultiAppVariableValueSamplePostprocessorTransfer::setupPostprocessorCommunication(), PerfGraphOutput::shouldOutput(), Output::shouldOutput(), FEProblemBase::shouldPrintExecution(), ElementReporter::shouldStore(), NodalReporter::shouldStore(), and GeneralReporter::shouldStore().
bool MultiMooseEnum::contains | ( | int | value | ) | const |
Definition at line 70 of file MultiMooseEnum.C.
bool MultiMooseEnum::contains | ( | unsigned short | value | ) | const |
Definition at line 79 of file MultiMooseEnum.C.
bool MultiMooseEnum::contains | ( | const MultiMooseEnum & | value | ) | const |
Definition at line 88 of file MultiMooseEnum.C.
bool MultiMooseEnum::contains | ( | const MooseEnumItem & | value | ) | const |
Definition at line 97 of file MultiMooseEnum.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.
|
inline |
Definition at line 150 of file MultiMooseEnum.h.
Referenced by FunctorADConverterTempl< T >::FunctorADConverterTempl(), FunctorSmootherTempl< T >::FunctorSmootherTempl(), GenericFunctorGradientMaterialTempl< is_ad >::GenericFunctorGradientMaterialTempl(), GenericFunctorMaterialTempl< is_ad >::GenericFunctorMaterialTempl(), GenericVectorFunctorMaterialTempl< is_ad >::GenericVectorFunctorMaterialTempl(), ParsedFunctorMaterialTempl< is_ad >::ParsedFunctorMaterialTempl(), PiecewiseByBlockFunctorMaterialTempl< T >::PiecewiseByBlockFunctorMaterialTempl(), push_back(), and VectorMagnitudeFunctorMaterialTempl< is_ad >::VectorMagnitudeFunctorMaterialTempl().
void MultiMooseEnum::erase | ( | const std::string & | names | ) |
Un-assign a value.
names | - a string, set, or vector giving the name to erase from the enumeration values |
Definition at line 126 of file MultiMooseEnum.C.
Referenced by Console::Console(), Moose::PetscSupport::disableLinearConvergedReason(), and Moose::PetscSupport::disableNonlinearConvergedReason().
void MultiMooseEnum::erase | ( | const std::vector< std::string > & | names | ) |
Definition at line 134 of file MultiMooseEnum.C.
void MultiMooseEnum::erase | ( | const std::set< std::string > & | names | ) |
Definition at line 140 of file MultiMooseEnum.C.
|
inherited |
Locate an item.
Definition at line 206 of file MooseEnumBase.C.
Referenced by MooseEnumBase::addDocumentation(), MooseEnumBase::addEnumerationItem(), ExecFlagEnum::appendCurrent(), MooseEnum::assign(), assign(), MooseEnumBase::deprecate(), MooseEnum::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.
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
i | index |
Definition at line 182 of file MultiMooseEnum.C.
Referenced by PiecewiseMulticonstant::sample(), Moose::Builder::setScalarParameter(), and Transfer::Transfer().
std::vector< T > MultiMooseEnum::getEnum | ( | ) | const |
get the current values cast to a vector of enum type T
Definition at line 214 of file MultiMooseEnum.h.
|
inherited |
Method for returning a vector of ids for this instance.
Definition at line 165 of file MooseEnumBase.C.
Referenced by MooseEnum::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(), MooseEnum::assign(), 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 MooseEnum::assign(), assign(), AdvancedOutput::enableOutputTypes(), MooseEnum::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 167 of file MultiMooseEnum.h.
Referenced by IterationInfo::declareHelper(), MeshInfo::declareHelper(), MeshInfo::possiblyAddSidesetInfo(), and MeshInfo::possiblyAddSubdomainInfo().
|
inlineinherited |
Return the complete set of available flags.
Definition at line 93 of file MooseEnumBase.h.
Referenced by MooseEnum::assign(), CreateExecutionerAction::setupAutoPreconditioning(), and ReadExecutorParamsAction::setupAutoPreconditioning().
bool MultiMooseEnum::operator!= | ( | const MultiMooseEnum & | value | ) | const |
Definition at line 55 of file MultiMooseEnum.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.
|
default |
Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used.
MultiMooseEnum & MultiMooseEnum::operator= | ( | const std::string & | names | ) |
Assignment operators.
names | - a string, set, or vector representing one of the enumeration values. |
Definition at line 106 of file MultiMooseEnum.C.
MultiMooseEnum & MultiMooseEnum::operator= | ( | const std::vector< std::string > & | names | ) |
Definition at line 114 of file MultiMooseEnum.C.
MultiMooseEnum & MultiMooseEnum::operator= | ( | const std::set< std::string > & | names | ) |
Definition at line 120 of file MultiMooseEnum.C.
bool MultiMooseEnum::operator== | ( | const MultiMooseEnum & | value | ) | const |
Comparison operators for comparing with character constants, MultiMooseEnums or integer values.
value | - RHS value to compare against |
Definition at line 43 of file MultiMooseEnum.C.
const std::string & MultiMooseEnum::operator[] | ( | unsigned int | i | ) | const |
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
The reference may not be used to change the item.
i | index |
Definition at line 172 of file MultiMooseEnum.C.
void MultiMooseEnum::push_back | ( | const std::string & | names | ) |
Insert operators Operator to insert (push_back) values into the enum.
Existing values are preserved and duplicates are stored.
names | - a string, set, or vector representing one of the enumeration values. |
Definition at line 146 of file MultiMooseEnum.C.
Referenced by Console::Console(), MultiAppTransfer::MultiAppTransfer(), Output::Output(), PetscOutput::PetscOutput(), Moose::PetscSupport::processPetscFlags(), and Split::setup().
void MultiMooseEnum::push_back | ( | const std::vector< std::string > & | names | ) |
Definition at line 154 of file MultiMooseEnum.C.
void MultiMooseEnum::push_back | ( | const std::set< std::string > & | names | ) |
Definition at line 160 of file MultiMooseEnum.C.
void MultiMooseEnum::push_back | ( | const MultiMooseEnum & | other_enum | ) |
Definition at line 166 of file MultiMooseEnum.C.
|
protected |
Helper method for un-assigning enumeration values.
Definition at line 225 of file MultiMooseEnum.C.
|
protected |
Set the current items.
unsigned int MultiMooseEnum::size | ( | ) | const |
Return the number of active items in the MultiMooseEnum.
Definition at line 244 of file MultiMooseEnum.C.
Referenced by SubProblem::doingPRefinement(), Moose::LibtorchArtificialNeuralNet::forward(), InterfaceKernelTempl< T >::InterfaceKernelTempl(), Moose::LibtorchArtificialNeuralNet::LibtorchArtificialNeuralNet(), MultiAppPostprocessorToAuxScalarTransfer::MultiAppPostprocessorToAuxScalarTransfer(), MultiAppPostprocessorTransfer::MultiAppPostprocessorTransfer(), MultiAppReporterTransfer::MultiAppReporterTransfer(), MultiAppScalarToAuxScalarTransfer::MultiAppScalarToAuxScalarTransfer(), MultiAppVariableValueSamplePostprocessorTransfer::MultiAppVariableValueSamplePostprocessorTransfer(), MultiAppVariableValueSampleTransfer::MultiAppVariableValueSampleTransfer(), MultiAppVectorPostprocessorTransfer::MultiAppVectorPostprocessorTransfer(), operator==(), PiecewiseMulticonstant::PiecewiseMulticonstant(), RefineSidesetGenerator::RefineSidesetGenerator(), MooseMesh::setCoordSystem(), SidesetInfoVectorPostprocessor::SidesetInfoVectorPostprocessor(), and Transfer::Transfer().
|
friend |
Definition at line 171 of file MultiMooseEnum.h.
|
friend |
Operator for printing to iostreams.
Definition at line 257 of file MultiMooseEnum.C.
|
protectedinherited |
Flag to enable enumeration items not previously defined.
Definition at line 163 of file MooseEnumBase.h.
Referenced by MooseEnum::assign(), assign(), MooseEnumBase::isOutOfRangeAllowed(), and MooseEnum::operator==().
|
protected |
The current id.
Definition at line 198 of file MultiMooseEnum.h.
Referenced by ExecFlagEnum::appendCurrent(), assign(), begin(), checkDeprecated(), clear(), contains(), end(), get(), getEnum(), isValid(), operator<<(), operator[](), remove(), and size().
|
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(), MooseEnum::assign(), assign(), ReporterProducerEnum::clear(), MooseEnumBase::deprecate(), MooseEnumBase::find(), MooseEnumBase::getIDs(), MooseEnumBase::getNames(), MooseEnumBase::getNextValidID(), MooseEnumBase::getRawNames(), ExecFlagEnum::items(), MooseEnumBase::items(), MooseEnum::operator==(), and ExecFlagEnum::removeAvailableFlags().