www.mooseframework.org
MooseEnumBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // C++ includes
13 #include <string>
14 #include <set>
15 #include <vector>
16 #include <map>
17 
18 // MOOSE includes
19 #include "MooseEnumItem.h"
20 
25 {
26 public:
34  MooseEnumBase(std::string names, bool allow_out_of_range = false);
35 
40  MooseEnumBase(const MooseEnumBase & other_enum);
41 
45  virtual ~MooseEnumBase() = default;
46 
52  virtual void deprecate(const std::string & name, const std::string & raw_name = "");
53 
58  std::vector<std::string> getNames() const;
59 
64  std::string getRawNames() const;
65 
70  std::vector<int> getIDs() const;
71 
76  virtual bool isValid() const = 0;
77 
82  bool isOutOfRangeAllowed() const { return _allow_out_of_range; }
83 
87  const std::set<MooseEnumItem> & items() { return _items; }
88 
90 
93  std::set<MooseEnumItem>::const_iterator find(const MooseEnumItem & other) const;
94  std::set<MooseEnumItem>::const_iterator find(const std::string & name) const;
95  std::set<MooseEnumItem>::const_iterator find(int id) const;
97 
101  int getNextValidID() const;
102 
103 protected:
104  MooseEnumBase();
105 
107 
115  void addEnumerationNames(const std::string & names);
116  void addEnumerationName(const std::string & raw_name);
117  void addEnumerationName(const std::string & name, const int & value);
118  void addEnumerationItem(const MooseEnumItem & item);
120 
124  virtual void checkDeprecated() const = 0;
125 
129  void checkDeprecated(const MooseEnumItem & item) const;
130 
132  std::set<MooseEnumItem> _items;
133 
135  std::map<MooseEnumItem, MooseEnumItem> _deprecated_items;
136 
139 };
140 
int getNextValidID() const
Compute the next valid ID.
void addEnumerationItem(const MooseEnumItem &item)
void addEnumerationName(const std::string &raw_name)
Definition: MooseEnumBase.C:73
std::map< MooseEnumItem, MooseEnumItem > _deprecated_items
The map of deprecated names and optional replacements.
void addEnumerationNames(const std::string &names)
Methods to add possible enumeration value to the enum.
Definition: MooseEnumBase.C:64
MooseEnumBase()
Private constuctor for use by libmesh::Parameters.
Definition: MooseEnumBase.C:42
std::string getRawNames() const
Method for returning the raw name strings for this instance.
virtual bool isValid() const =0
IsValid.
The base class for both the MooseEnum and MultiMooseEnum classes.
Definition: MooseEnumBase.h:24
virtual ~MooseEnumBase()=default
This class must have a virtual destructor since it has derived classes.
virtual void checkDeprecated() const =0
Method that must be implemented to check derived class values against the _deprecated_names.
std::vector< int > getIDs() const
Method for returning a vector of ids for this instance.
std::vector< std::string > getNames() const
Method for returning a vector of all valid enumeration names for this instance.
std::set< MooseEnumItem > _items
Storage for the assigned items.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
bool isOutOfRangeAllowed() const
isOutOfRangeAllowed
Definition: MooseEnumBase.h:82
virtual void deprecate(const std::string &name, const std::string &raw_name="")
Deprecates various options in the MOOSE enum.
Definition: MooseEnumBase.C:45
const std::set< MooseEnumItem > & items()
Return the complete set of available flags.
Definition: MooseEnumBase.h:87
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.