www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
MooseEnumBase Class Referenceabstract

The base class for both the MooseEnum and MultiMooseEnum classes. More...

#include <MooseEnumBase.h>

Inheritance diagram for MooseEnumBase:
[legend]

Public Member Functions

 MooseEnumBase (std::string 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...
 
 MooseEnumBase (const MooseEnumBase &other_enum)
 Copy Constructor for use when creating vectors of MooseEnumBases. More...
 
virtual ~MooseEnumBase ()=default
 This class must have a virtual destructor since it has derived classes. More...
 
void deprecate (const std::string &name, const std::string &new_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...
 
virtual bool isValid () const =0
 IsValid. More...
 
bool isOutOfRangeAllowed () const
 isOutOfRangeAllowed More...
 

Protected Member Functions

 MooseEnumBase ()
 Private constuctor for use by libmesh::Parameters. More...
 
void fillNames (std::string names, std::string option_delim=" ")
 Populates the _names vector. More...
 
virtual void checkDeprecated () const =0
 
void checkDeprecatedBase (const std::string &name_upper) const
 Check and warn deprecated values. More...
 
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 Attributes

std::set< MooseEnumItem_items
 Storage for the assigned items. More...
 
std::map< std::string, std::string > _deprecated_names
 The map of deprecated names and optional replacements. More...
 
int _out_of_range_index
 The index of values assigned that are NOT values in this enum. More...
 

Static Protected Attributes

static const int INVALID_ID = std::numeric_limits<int>::min()
 Constants. More...
 

Detailed Description

The base class for both the MooseEnum and MultiMooseEnum classes.

Definition at line 30 of file MooseEnumBase.h.

Constructor & Destructor Documentation

MooseEnumBase::MooseEnumBase ( std::string  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
allow_out_of_range- determines whether this enumeration will accept values outside of it's range of defined values.

Definition at line 29 of file MooseEnumBase.C.

30  : _out_of_range_index(allow_out_of_range ? INVALID_ID + 1 : 0)
31 {
32  if (names.find(',') != std::string::npos)
33  {
34  mooseDeprecated("Please use a space to separate options in a MooseEnum, commas are "
35  "deprecated\nMooseEnum initialized with names: \"",
36  names,
37  '\"');
38  fillNames(names, ",");
39  }
40  else
41  fillNames(names);
42 }
void fillNames(std::string names, std::string option_delim=" ")
Populates the _names vector.
Definition: MooseEnumBase.C:66
void mooseDeprecated(Args &&...args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:202
int _out_of_range_index
The index of values assigned that are NOT values in this enum.
static const int INVALID_ID
Constants.
MooseEnumBase::MooseEnumBase ( const MooseEnumBase other_enum)

Copy Constructor for use when creating vectors of MooseEnumBases.

Parameters
other_enum- The other enumeration to copy state from

Definition at line 44 of file MooseEnumBase.C.

45  : _items(other_enum._items),
48 {
49 }
std::map< std::string, std::string > _deprecated_names
The map of deprecated names and optional replacements.
int _out_of_range_index
The index of values assigned that are NOT values in this enum.
std::set< MooseEnumItem > _items
Storage for the assigned items.
virtual MooseEnumBase::~MooseEnumBase ( )
virtualdefault

This class must have a virtual destructor since it has derived classes.

MooseEnumBase::MooseEnumBase ( )
protected

Private constuctor for use by libmesh::Parameters.

Definition at line 54 of file MooseEnumBase.C.

Referenced by isOutOfRangeAllowed().

54 {}

Member Function Documentation

virtual void MooseEnumBase::checkDeprecated ( ) const
protectedpure virtual

Implemented in MultiMooseEnum, and MooseEnum.

Referenced by deprecate(), and isOutOfRangeAllowed().

void MooseEnumBase::checkDeprecatedBase ( const std::string &  name_upper) const
protected

Check and warn deprecated values.

Definition at line 99 of file MooseEnumBase.C.

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

100 {
101  std::map<std::string, std::string>::const_iterator it = _deprecated_names.find(name_upper);
102 
103  if (it != _deprecated_names.end())
104  {
105  if (it->second != "")
106  mooseWarning(name_upper + " is deprecated, consider using " + it->second);
107  else
108  mooseWarning(name_upper + " is deprecated");
109  }
110 }
std::map< std::string, std::string > _deprecated_names
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:194
void MooseEnumBase::deprecate ( const std::string &  name,
const std::string &  new_name = "" 
)

Deprecates various options in the MOOSE enum.

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

Definition at line 57 of file MooseEnumBase.C.

58 {
59  std::string upper(MooseUtils::toUpper(name));
60  std::string upper_new(MooseUtils::toUpper(new_name));
61  _deprecated_names[upper] = upper_new;
63 }
std::string toUpper(const std::string &name)
Convert supplied string to upper case.
Definition: MooseUtils.C:555
std::map< std::string, std::string > _deprecated_names
The map of deprecated names and optional replacements.
virtual void checkDeprecated() const =0
void MooseEnumBase::fillNames ( std::string  names,
std::string  option_delim = " " 
)
protected

Populates the _names vector.

Parameters
names- a space separated list of names used to populate the internal names vector

Definition at line 66 of file MooseEnumBase.C.

Referenced by isOutOfRangeAllowed(), and MooseEnumBase().

67 {
68  std::vector<std::string> elements;
69  // split on spaces
70  MooseUtils::tokenize(names, elements, 1, option_delim);
71 
72  int value = 0;
73  for (unsigned int i = 0; i < elements.size(); ++i)
74  {
75  std::vector<std::string> name_value;
76 
77  // Make sure the option is not malformed
78  if (elements[i].find_first_of('=') == 0 ||
79  elements[i].find_last_of('=') == elements[i].length() - 1)
80  mooseError("You cannot place whitespace around the '=' character in MooseEnumBase");
81 
82  // split on equals sign
83  MooseUtils::tokenize(MooseUtils::trim(elements[i]), name_value, 1, "=");
84 
85  if (name_value.size() < 1 || name_value.size() > 2)
86  mooseError("Invalid option supplied in MooseEnumBase: ", elements[i]);
87 
88  // See if there is a value supplied for this option
89  // strtol allows for proper conversions of both int and hex strings
90  if (name_value.size() == 2)
91  value = strtol(name_value[1].c_str(), NULL, 0);
92 
93  // create item entry
94  _items.emplace(name_value[0], value++);
95  }
96 }
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:350
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::string trim(const std::string &str, const std::string &white_space=" \t\n\v\f\r")
Standard scripting language trim function.
Definition: MooseUtils.C:95
std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const MooseEnumItem other) const
protected

Locate an item.

Definition at line 144 of file MooseEnumBase.C.

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

145 {
146  return std::find_if(
147  _items.begin(), _items.end(), [&other](MooseEnumItem const & item) { return item == other; });
148 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:24
std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( const std::string &  name) const
protected

Definition at line 129 of file MooseEnumBase.C.

130 {
131  return std::find_if(_items.begin(), _items.end(), [&name](MooseEnumItem const & item) {
132  return item.name() == name;
133  });
134 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:24
std::set< MooseEnumItem >::const_iterator MooseEnumBase::find ( int  id) const
protected

Definition at line 137 of file MooseEnumBase.C.

138 {
139  return std::find_if(
140  _items.begin(), _items.end(), [&id](MooseEnumItem const & item) { return item.id() == id; });
141 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:24
std::vector< std::string > MooseEnumBase::getNames ( ) const

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

Returns
a vector of names

Definition at line 113 of file MooseEnumBase.C.

114 {
115  std::vector<std::string> out;
116  out.reserve(_items.size());
117  for (auto it = _items.begin(); it != _items.end(); ++it)
118  out.push_back(it->name());
119  return out;
120 }
std::set< MooseEnumItem > _items
Storage for the assigned items.
std::string MooseEnumBase::getRawNames ( ) const

Method for returning the raw name strings for this instance.

Returns
a space separated list of names

Definition at line 123 of file MooseEnumBase.C.

Referenced by MultiMooseEnum::assign(), AdvancedOutput::enableOutputTypes(), MooseEnum::operator=(), MooseEnum::operator==(), validParams< LeastSquaresFit >(), validParams< MultiAppTransfer >(), validParams< PiecewiseConstant >(), and validParams< Residual >().

124 {
125  return Moose::stringify(_items, " ");
126 }
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
std::set< MooseEnumItem > _items
Storage for the assigned items.
bool MooseEnumBase::isOutOfRangeAllowed ( ) const
inline

isOutOfRangeAllowed

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

Definition at line 83 of file MooseEnumBase.h.

83 { return _out_of_range_index; }
int _out_of_range_index
The index of values assigned that are NOT values in this enum.
virtual bool MooseEnumBase::isValid ( ) const
pure virtual

IsValid.

Returns
- a Boolean indicating whether this Enumeration has been set

Implemented in MultiMooseEnum, and MooseEnum.

Member Data Documentation

std::map<std::string, std::string> MooseEnumBase::_deprecated_names
protected

The map of deprecated names and optional replacements.

Definition at line 116 of file MooseEnumBase.h.

Referenced by checkDeprecatedBase(), and deprecate().

std::set<MooseEnumItem> MooseEnumBase::_items
protected
int MooseEnumBase::_out_of_range_index
protected

The index of values assigned that are NOT values in this enum.

If this index is 0 (false) then out of range values are not allowed.

Definition at line 122 of file MooseEnumBase.h.

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

const int MooseEnumBase::INVALID_ID = std::numeric_limits<int>::min()
staticprotected

Constants.

Definition at line 125 of file MooseEnumBase.h.

Referenced by MooseEnum::operator=().


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