www.mooseframework.org
MultiMooseEnum.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 // MOOSE includes
13 #include "Moose.h"
14 #include "MooseEnumBase.h"
15 
16 // C++ includes
17 #include <vector>
18 
19 // Forward declarations
20 class ExecFlagEnum;
21 namespace libMesh
22 {
23 class Parameters;
24 }
25 
26 typedef std::vector<MooseEnumItem>::const_iterator MooseEnumIterator;
27 
39 {
40 public:
50  MultiMooseEnum(std::string names,
51  std::string default_names = "",
52  bool allow_out_of_range = false);
53 
58  MultiMooseEnum(const MultiMooseEnum & other_enum);
59 
64  MultiMooseEnum & operator=(const MultiMooseEnum & other_enum) = default;
65 
67 
73  bool operator==(const MultiMooseEnum & value) const;
74  bool operator!=(const MultiMooseEnum & value) const;
76 
78 
82  bool contains(const std::string & value) const;
83  bool contains(int value) const;
84  bool contains(unsigned short value) const;
85  bool contains(const MultiMooseEnum & value) const;
86  bool contains(const MooseEnumItem & value) const;
88 
90 
95  MultiMooseEnum & operator=(const std::string & names);
96  MultiMooseEnum & operator=(const std::vector<std::string> & names);
97  MultiMooseEnum & operator=(const std::set<std::string> & names);
99 
101 
105  void erase(const std::string & names);
106  void erase(const std::vector<std::string> & names);
107  void erase(const std::set<std::string> & names);
109 
111 
117  void push_back(const std::string & names);
118  void push_back(const std::vector<std::string> & names);
119  void push_back(const std::set<std::string> & names);
120  void push_back(const MultiMooseEnum & other_enum);
122 
130  const std::string & operator[](unsigned int i) const;
131 
138  unsigned int get(unsigned int i) const;
139 
141  template <typename T>
142  std::vector<T> getEnum() const;
143 
145 
149  MooseEnumIterator begin() const { return _current.begin(); }
150  MooseEnumIterator end() const { return _current.end(); }
152 
156  void clear();
157 
161  unsigned int size() const;
162 
167  virtual bool isValid() const override { return !_current.empty(); }
168 
169  // InputParameters and Output is allowed to create an empty enum but is responsible for
170  // filling it in after the fact
171  friend class libMesh::Parameters;
172 
174  friend std::ostream & operator<<(std::ostream & out, const MultiMooseEnum & obj);
175 
176 protected:
178  virtual void checkDeprecated() const override;
179 
183  template <typename InputIterator>
184  MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append);
185 
189  template <typename InputIterator>
190  void remove(InputIterator first, InputIterator last);
191 
195  void setCurrentItems(const std::vector<MooseEnumItem> & current);
196 
198  std::vector<MooseEnumItem> _current;
199 
203  MultiMooseEnum();
204 
209  MultiMooseEnum(const MooseEnumBase & other_enum);
210 };
211 
212 template <typename T>
213 std::vector<T>
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 }
const std::string & operator[](unsigned int i) const
Indexing operator Operator to retrieve an item from the MultiMooseEnum.
virtual void checkDeprecated() const override
Check whether any of the current values are deprecated when called.
friend std::ostream & operator<<(std::ostream &out, const MultiMooseEnum &obj)
Operator for printing to iostreams.
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append)
Helper method for all inserts and assignment operators.
bool operator!=(const MultiMooseEnum &value) const
void setCurrentItems(const std::vector< MooseEnumItem > &current)
Set the current items.
std::vector< MooseEnumItem > _current
The current id.
MooseEnumIterator begin() const
Returns a begin/end iterator to all of the items in the enum.
MultiMooseEnum()
Protected constructor for use by libmesh::Parameters.
virtual bool isValid() const override
IsValid.
unsigned int size() const
Return the number of active items in the MultiMooseEnum.
MooseEnumIterator end() const
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
The base class for both the MooseEnum and MultiMooseEnum classes.
Definition: MooseEnumBase.h:24
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)
std::vector< MooseEnumItem >::const_iterator MooseEnumIterator
void erase(const std::string &names)
Un-assign a value.
void clear()
Clear the MultiMooseEnum.
std::vector< T > getEnum() const
get the current values cast to a vector of enum type T
MultiMooseEnum & operator=(const MultiMooseEnum &other_enum)=default
Copy Assignment operator must be explicitly defined when a copy ctor exists and this method is used...
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
bool operator==(const MultiMooseEnum &value) const
Comparison operators for comparing with character constants, MultiMooseEnums or integer values...
void push_back(const std::string &names)
Insert operators Operator to insert (push_back) values into the enum.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
OStreamProxy out(std::cout)