www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
MultiMooseEnum 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 comma-separated list of strings which become the enum values. More...

#include <MultiMooseEnum.h>

Inheritance diagram for MultiMooseEnum:
[legend]

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...
 
MultiMooseEnumoperator= (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< 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...
 
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
 
MultiMooseEnumoperator= (const std::string &names)
 Assignment operators. More...
 
MultiMooseEnumoperator= (const std::vector< std::string > &names)
 
MultiMooseEnumoperator= (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 >
MultiMooseEnumassign (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 > &current)
 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 MooseEnumItemaddEnumerationName (const std::string &raw_name)
 
const MooseEnumItemaddEnumerationName (const std::string &name, const int &value)
 
const MooseEnumItemaddEnumerationItem (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...
 

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 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.

Constructor & Destructor Documentation

◆ MultiMooseEnum() [1/4]

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.

Parameters
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.

25  : MooseEnumBase(names, allow_out_of_range)
26 {
27  *this = default_names;
28 }
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42

◆ MultiMooseEnum() [2/4]

MultiMooseEnum::MultiMooseEnum ( const MultiMooseEnum other_enum)

Copy Constructor.

Parameters
other_enum- The other enumeration to copy state from

Definition at line 30 of file MultiMooseEnum.C.

31  : MooseEnumBase(other_enum), _current(other_enum._current)
32 {
33 }
std::vector< MooseEnumItem > _current
The current id.
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42

◆ MultiMooseEnum() [3/4]

MultiMooseEnum::MultiMooseEnum ( )
protected

Protected constructor for use by libmesh::Parameters.

Private constuctor for use by libmesh::Parameters.

Definition at line 38 of file MultiMooseEnum.C.

38 {}

◆ MultiMooseEnum() [4/4]

MultiMooseEnum::MultiMooseEnum ( const MooseEnumBase other_enum)
protected

Protected constructor that can accept a MooseEnumBase for ::withOptionsFrom()

Parameters
other_enum- MooseEnumBase type to copy names and out-of-range data from

Definition at line 40 of file MultiMooseEnum.C.

40 : MooseEnumBase(other_enum) {}
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42

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(), 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()

template<typename InputIterator >
MultiMooseEnum & MultiMooseEnum::assign ( InputIterator  first,
InputIterator  last,
bool  append 
)
protected

Helper method for all inserts and assignment operators.

Definition at line 193 of file MultiMooseEnum.C.

Referenced by operator=(), and push_back().

194 {
195  if (!append)
196  clear();
197 
198  for (InputIterator it = first; it != last; ++it)
199  {
200  const auto iter = find(*it);
201  if (iter == _items.end())
202  {
203  if (!_allow_out_of_range) // Are out of range values allowed?
204  mooseError("Invalid option \"",
205  *it,
206  "\" in MultiMooseEnum. Valid options (not case-sensitive) are \"",
207  getRawNames(),
208  "\".");
209  else
210  {
211  MooseEnumItem created(*it, getNextValidID());
212  addEnumerationItem(created);
213  _current.push_back(created);
214  }
215  }
216  else
217  _current.push_back(*iter);
218  }
219  checkDeprecated();
220  return *this;
221 }
int getNextValidID() const
Compute the next valid ID.
virtual void checkDeprecated() const override
Check whether any of the current values are deprecated when called.
std::vector< MooseEnumItem > _current
The current id.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
std::string getRawNames() const
Method for returning the raw name strings for this instance.
const MooseEnumItem & addEnumerationItem(const MooseEnumItem &item)
void clear()
Clear the MultiMooseEnum.
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.

◆ begin()

MooseEnumIterator MultiMooseEnum::begin ( ) const
inline

◆ checkDeprecated() [1/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

◆ checkDeprecated() [2/2]

void MultiMooseEnum::checkDeprecated ( ) const
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+=().

251 {
252  for (const auto & item : _current)
254 }
std::vector< MooseEnumItem > _current
The current id.
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.

◆ clear()

void MultiMooseEnum::clear ( )

Clear the MultiMooseEnum.

Definition at line 238 of file MultiMooseEnum.C.

Referenced by assign(), AdvancedOutput::initExecutionTypes(), ExecFlagEnum::operator=(), and SetupInterface::SetupInterface().

239 {
240  _current.clear();
241 }
std::vector< MooseEnumItem > _current
The current id.

◆ contains() [1/5]

bool MultiMooseEnum::contains ( const std::string &  value) const

Contains methods for seeing if a value is in the MultiMooseEnum.

Returns
bool - the truth value indicating whether the value is present

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().

62 {
63  return std::find_if(_current.begin(),
64  _current.end(),
65  [&value](const MooseEnumItem & item)
66  { return item == value; }) != _current.end();
67 }
std::vector< MooseEnumItem > _current
The current id.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ contains() [2/5]

bool MultiMooseEnum::contains ( int  value) const

Definition at line 70 of file MultiMooseEnum.C.

71 {
72  return std::find_if(_current.begin(),
73  _current.end(),
74  [&value](const MooseEnumItem & item)
75  { return item == value; }) != _current.end();
76 }
std::vector< MooseEnumItem > _current
The current id.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ contains() [3/5]

bool MultiMooseEnum::contains ( unsigned short  value) const

Definition at line 79 of file MultiMooseEnum.C.

80 {
81  return std::find_if(_current.begin(),
82  _current.end(),
83  [&value](const MooseEnumItem & item)
84  { return item == value; }) != _current.end();
85 }
std::vector< MooseEnumItem > _current
The current id.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ contains() [4/5]

bool MultiMooseEnum::contains ( const MultiMooseEnum value) const

Definition at line 88 of file MultiMooseEnum.C.

89 {
90  for (const auto & item : value._current)
91  if (!contains(item))
92  return false;
93  return true;
94 }
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ contains() [5/5]

bool MultiMooseEnum::contains ( const MooseEnumItem value) const

Definition at line 97 of file MultiMooseEnum.C.

98 {
99  return std::find_if(_current.begin(),
100  _current.end(),
101  [&value](const MooseEnumItem & item)
102  { return item == value; }) != _current.end();
103 }
std::vector< MooseEnumItem > _current
The current id.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ 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.

◆ end()

MooseEnumIterator MultiMooseEnum::end ( ) const
inline

◆ erase() [1/3]

void MultiMooseEnum::erase ( const std::string &  names)

Un-assign a value.

Parameters
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().

127 {
128  std::vector<std::string> names_vector;
129  MooseUtils::tokenize(names, names_vector, 1, " ");
130  remove(names_vector.begin(), names_vector.end());
131 }
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

◆ erase() [2/3]

void MultiMooseEnum::erase ( const std::vector< std::string > &  names)

Definition at line 134 of file MultiMooseEnum.C.

135 {
136  remove(names.begin(), names.end());
137 }

◆ erase() [3/3]

void MultiMooseEnum::erase ( const std::set< std::string > &  names)

Definition at line 140 of file MultiMooseEnum.C.

141 {
142  remove(names.begin(), names.end());
143 }

◆ 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(), MooseEnum::assign(), assign(), MooseEnumBase::deprecate(), MooseEnum::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

◆ get()

unsigned int MultiMooseEnum::get ( unsigned int  i) const

Indexing operator Operator to retrieve an item from the MultiMooseEnum.

Parameters
iindex
Returns
the id of the MooseEnumItem at the supplied index

Definition at line 182 of file MultiMooseEnum.C.

Referenced by PiecewiseMulticonstant::sample(), Moose::Builder::setScalarParameter(), and Transfer::Transfer().

183 {
184  mooseAssert(i < _current.size(),
185  "Access out of bounds in MultiMooseEnum (i: " << i << " size: " << _current.size()
186  << ")");
187 
188  return _current[i].id();
189 }
std::vector< MooseEnumItem > _current
The current id.

◆ getEnum()

template<typename T >
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.

215 {
216 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
217  static_assert(std::is_enum<T>::value == true,
218  "The type requested from MooseEnum::getEnum must be an enum type!\n\n");
219 #endif
220  std::vector<T> enum_vec;
221  for (const auto & current : _current)
222  enum_vec.push_back(static_cast<T>(current.id()));
223  return enum_vec;
224 }
std::vector< MooseEnumItem > _current
The current id.

◆ 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 MooseEnum::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(), MooseEnum::assign(), 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 MooseEnum::assign(), assign(), AdvancedOutput::enableOutputTypes(), MooseEnum::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 MultiMooseEnum::isValid ( ) const
inlineoverridevirtual

IsValid.

Returns
- a Boolean indicating whether this Enumeration has been set

Implements MooseEnumBase.

Definition at line 167 of file MultiMooseEnum.h.

Referenced by IterationInfo::declareHelper(), MeshInfo::declareHelper(), MeshInfo::possiblyAddSidesetInfo(), and MeshInfo::possiblyAddSubdomainInfo().

167 { return !_current.empty(); }
std::vector< MooseEnumItem > _current
The current id.

◆ 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 MooseEnum::assign(), CreateExecutionerAction::setupAutoPreconditioning(), and ReadExecutorParamsAction::setupAutoPreconditioning().

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

◆ operator!=()

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

Definition at line 55 of file MultiMooseEnum.C.

56 {
57  return !(*this == value);
58 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ 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]

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

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

◆ operator=() [2/4]

MultiMooseEnum & MultiMooseEnum::operator= ( const std::string &  names)

Assignment operators.

Parameters
names- a string, set, or vector representing one of the enumeration values.
Returns
A reference to this object for chaining

Definition at line 106 of file MultiMooseEnum.C.

107 {
108  std::vector<std::string> names_vector;
109  MooseUtils::tokenize(names, names_vector, 1, " ");
110  return assign(names_vector.begin(), names_vector.end(), false);
111 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.
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

◆ operator=() [3/4]

MultiMooseEnum & MultiMooseEnum::operator= ( const std::vector< std::string > &  names)

Definition at line 114 of file MultiMooseEnum.C.

115 {
116  return assign(names.begin(), names.end(), false);
117 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.

◆ operator=() [4/4]

MultiMooseEnum & MultiMooseEnum::operator= ( const std::set< std::string > &  names)

Definition at line 120 of file MultiMooseEnum.C.

121 {
122  return assign(names.begin(), names.end(), false);
123 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.

◆ operator==()

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

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

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

Definition at line 43 of file MultiMooseEnum.C.

44 {
45  // Not the same if the lengths are different
46  if (value.size() != size())
47  return false;
48 
49  // Return false if this enum does not contain an item from the other, since they are the same
50  // size at this point if this is true then they are equal.
51  return contains(value);
52 }
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
bool contains(const std::string &value) const
Contains methods for seeing if a value is in the MultiMooseEnum.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ operator[]()

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.

Parameters
iindex
Returns
a read/read-write reference to the item as a string.

Definition at line 172 of file MultiMooseEnum.C.

173 {
174  mooseAssert(i < _current.size(),
175  "Access out of bounds in MultiMooseEnum (i: " << i << " size: " << _current.size()
176  << ")");
177 
178  return _current[i].rawName();
179 }
std::vector< MooseEnumItem > _current
The current id.

◆ push_back() [1/4]

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.

Parameters
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().

147 {
148  std::vector<std::string> names_vector;
149  MooseUtils::tokenize(names, names_vector, 1, " ");
150  assign(names_vector.begin(), names_vector.end(), true);
151 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.
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

◆ push_back() [2/4]

void MultiMooseEnum::push_back ( const std::vector< std::string > &  names)

Definition at line 154 of file MultiMooseEnum.C.

155 {
156  assign(names.begin(), names.end(), true);
157 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.

◆ push_back() [3/4]

void MultiMooseEnum::push_back ( const std::set< std::string > &  names)

Definition at line 160 of file MultiMooseEnum.C.

161 {
162  assign(names.begin(), names.end(), true);
163 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.

◆ push_back() [4/4]

void MultiMooseEnum::push_back ( const MultiMooseEnum other_enum)

Definition at line 166 of file MultiMooseEnum.C.

167 {
168  assign(other_enum.begin(), other_enum.end(), true);
169 }
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the items in the enum.
MooseEnumIterator end() const

◆ remove()

template<typename InputIterator >
void MultiMooseEnum::remove ( InputIterator  first,
InputIterator  last 
)
protected

Helper method for un-assigning enumeration values.

Definition at line 225 of file MultiMooseEnum.C.

226 {
227  // Create a new list of enumerations by striping out the supplied values
228  for (InputIterator it = first; it != last; ++it)
229  {
230  std::vector<MooseEnumItem>::iterator iter = std::find_if(
231  _current.begin(), _current.end(), [it](const MooseEnumItem & item) { return item == *it; });
232  if (iter != _current.end())
233  _current.erase(iter);
234  }
235 }
std::vector< MooseEnumItem > _current
The current id.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18

◆ setCurrentItems()

void MultiMooseEnum::setCurrentItems ( const std::vector< MooseEnumItem > &  current)
protected

Set the current items.

◆ size()

unsigned int MultiMooseEnum::size ( ) const

Friends And Related Function Documentation

◆ libMesh::Parameters

friend class libMesh::Parameters
friend

Definition at line 171 of file MultiMooseEnum.h.

◆ operator<<

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

Operator for printing to iostreams.

Definition at line 257 of file MultiMooseEnum.C.

258 {
259  out << Moose::stringify(obj._current, " ");
260  return out;
261 }
std::vector< MooseEnumItem > _current
The current id.
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
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 MooseEnum::assign(), assign(), MooseEnumBase::isOutOfRangeAllowed(), and MooseEnum::operator==().

◆ _current

std::vector<MooseEnumItem> MultiMooseEnum::_current
protected

◆ _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: