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 
61 
67  bool operator==(const MultiMooseEnum & value) const;
68  bool operator!=(const MultiMooseEnum & value) const;
70 
72 
76  bool contains(const std::string & value) const;
77  bool contains(int value) const;
78  bool contains(unsigned short value) const;
79  bool contains(const MultiMooseEnum & value) const;
80  bool contains(const MooseEnumItem & value) const;
82 
84 
89  MultiMooseEnum & operator=(const std::string & names);
90  MultiMooseEnum & operator=(const std::vector<std::string> & names);
91  MultiMooseEnum & operator=(const std::set<std::string> & names);
93 
95 
99  void erase(const std::string & names);
100  void erase(const std::vector<std::string> & names);
101  void erase(const std::set<std::string> & names);
103 
105 
111  void push_back(const std::string & names);
112  void push_back(const std::vector<std::string> & names);
113  void push_back(const std::set<std::string> & names);
115 
123  const std::string & operator[](unsigned int i) const;
124 
131  unsigned int get(unsigned int i) const;
132 
134 
138  MooseEnumIterator begin() const { return _current.begin(); }
139  MooseEnumIterator end() const { return _current.end(); }
141 
145  void clear();
146 
150  unsigned int size() const;
151 
156  virtual bool isValid() const override { return !_current.empty(); }
157 
158  // InputParameters and Output is allowed to create an empty enum but is responsible for
159  // filling it in after the fact
160  friend class libMesh::Parameters;
161 
163  friend std::ostream & operator<<(std::ostream & out, const MultiMooseEnum & obj);
164 
165 protected:
167  virtual void checkDeprecated() const override;
168 
172  template <typename InputIterator>
173  MultiMooseEnum & assign(InputIterator first, InputIterator last, bool append);
174 
178  template <typename InputIterator>
179  void remove(InputIterator first, InputIterator last);
180 
184  void setCurrentItems(const std::vector<MooseEnumItem> & current);
185 
187  std::vector<MooseEnumItem> _current;
188 
192  MultiMooseEnum();
193 
198  MultiMooseEnum(const MooseEnumBase & other_enum);
199 };
200 
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:24
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
friend class libMesh::Parameters
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.
std::vector< MooseEnumItem >::const_iterator MooseEnumIterator
void erase(const std::string &names)
Un-assign a value.
void clear()
Clear the MultiMooseEnum.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:21
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...
MultiMooseEnum & operator=(const std::string &names)
Assignment operators.