20 #ifndef LIBMESH_PARAMETERS_H 21 #define LIBMESH_PARAMETERS_H 24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/reference_counted_object.h" 26 #include "libmesh/print_trace.h" 47 void print_helper(std::ostream & os,
const std::vector<P> * param);
50 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param);
53 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param);
55 template<
typename P1,
typename P2,
typename C,
typename A>
56 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param);
107 template <
typename T>
114 template <
typename T>
115 const T &
get (std::string_view)
const;
122 template <
typename T>
123 void insert (
const std::string &);
131 template <
typename T>
132 T &
set (
const std::string &);
143 void remove (std::string_view);
150 #ifdef LIBMESH_HAVE_RTTI 154 template <
typename T>
156 #endif // LIBMESH_HAVE_RTTI 161 virtual void clear ();
178 virtual ~Value() =
default;
180 #ifdef LIBMESH_HAVE_RTTI 185 virtual std::string
type ()
const = 0;
186 #endif // LIBMESH_HAVE_RTTI 192 virtual void print(std::ostream &)
const = 0;
198 virtual std::unique_ptr<Value>
clone ()
const = 0;
205 template <
typename T>
213 const T &
get ()
const {
return _value; }
220 #ifdef LIBMESH_HAVE_RTTI 224 virtual std::string
type ()
const override;
225 #endif // LIBMESH_HAVE_RTTI 230 virtual void print(std::ostream &)
const override;
235 virtual std::unique_ptr<Value>
clone ()
const override;
247 typedef std::map<std::string, std::unique_ptr<Value>, std::less<>>
map_type;
292 #ifdef LIBMESH_HAVE_RTTI 293 template <
typename T>
301 template <
typename T>
309 template <
typename T>
313 auto copy = std::make_unique<Parameter<T>>();
315 copy->_value = this->_value;
364 os <<
"Name\t Type\t Value\n" 365 <<
"---------------------\n";
368 os <<
" " << it->first
369 #ifdef LIBMESH_HAVE_RTTI 370 <<
"\t " << it->second->type()
371 #endif // LIBMESH_HAVE_RTTI 372 <<
"\t "; it->second->print(os);
393 template <
typename T>
401 #ifdef LIBMESH_HAVE_RTTI 403 if (
dynamic_cast<const Parameter<T> *
>(it->second.get()))
406 #else // !LIBMESH_HAVE_RTTI 411 libmesh_warning(
"Parameters::have_parameter() may return false positives when RTTI is not enabled.");
424 template <
typename T>
428 if (!this->have_parameter<T>(
name))
430 std::ostringstream oss;
433 #ifdef LIBMESH_HAVE_RTTI 436 oss <<
" parameter named \"" 437 <<
name <<
"\" found.\n\n" 438 <<
"Known parameters:\n" 441 libmesh_error_msg(oss.str());
450 auto ptr = cast_ptr<Parameter<T> *>(it->second.get());
456 template <
typename T>
460 if (!this->have_parameter<T>(
name))
467 template <
typename T>
471 if (!this->have_parameter<T>(
name))
477 auto ptr = cast_ptr<Parameter<T> *>(
_values[
name].get());
494 #ifdef LIBMESH_HAVE_RTTI 495 template <
typename T>
499 unsigned int cnt = 0;
501 for (
const auto & pr :
_values)
545 os << static_cast<int>(*param);
553 os << static_cast<int>(*param);
560 for (
const auto & p : *param)
566 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param)
568 for (
const auto & pv : *param)
569 for (
const auto & p : pv)
575 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param)
577 for (
const auto & pvv : *param)
578 for (
const auto & pv : pvv)
579 for (
const auto & p : pv)
584 template<
typename P1,
typename P2,
typename C,
typename A>
585 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param)
588 std::size_t sz = param->size();
589 for (
auto KV : *param)
591 os <<
'\'' << KV.first <<
"\' => \'" << KV.second <<
'\'';
601 #endif // LIBMESH_PARAMETERS_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
bool have_parameter(std::string_view) const
virtual void print(std::ostream &) const =0
Prints the parameter value to the specified stream.
virtual ~Parameters()=default
Destructor.
virtual std::string type() const =0
String identifying the type of parameter stored.
void print_helper(std::ostream &os, const P *param)
Helper functions for printing scalar, vector, vector<vector> and vector<vector<vector>> types...
This class provides the ability to map between arbitrary, user-defined strings and several data types...
map_type _values
Data structure to map names with values.
Tnew cast_ptr(Told *oldvar)
void print(std::ostream &os=libMesh::out) const
Prints the contents, by default to libMesh::out.
virtual std::unique_ptr< Value > clone() const override
Clone this value.
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
std::map< std::string, std::unique_ptr< Value >, std::less<> > map_type
The type of the map that we store internally.
The libMesh namespace provides an interface to certain functionality in the library.
virtual Parameters & operator+=(const Parameters &source)
Addition/Assignment operator.
virtual std::unique_ptr< Value > clone() const =0
Clone this value.
Concrete definition of a parameter value for a specified type.
virtual Parameters & operator=(const Parameters &source)
Assignment operator.
iterator end()
Iterator pointing to the end of the set of parameters.
const T & get(std::string_view) const
void remove(std::string_view)
Removes the specified parameter from the list, if it exists.
Abstract definition of a parameter value.
virtual ~Value()=default
Destructor.
iterator begin()
Iterator pointing to the beginning of the set of parameters.
This class implements reference counting.
std::string demangle(const char *name)
Mostly system independent demangler.
T _value
Stored parameter value.
virtual std::string type() const override
String identifying the type of parameter stored.
virtual void print(std::ostream &) const override
Prints the parameter value to the specified stream.
T & set(const std::string &)
virtual void clear()
Clears internal data structures & frees any allocated memory.
void insert(const std::string &)
Inserts a new Parameter into the object but does not return a writable reference. ...
std::size_t n_parameters() const
Parameters()=default
Default constructor.
map_type::const_iterator const_iterator
Constant parameter map iterator.
virtual void set_attributes(const std::string &, bool)
Overridable function to set any extended attributes for classes inheriting from this class...
map_type::iterator iterator
Parameter map iterator.