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" 37 #ifdef LIBMESH_HAVE_RTTI 51 void print_helper(std::ostream & os,
const std::vector<P> * param);
54 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param);
57 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param);
59 template<
typename P1,
typename P2,
typename C,
typename A>
60 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param);
62 template <
typename P,
typename C,
typename A>
63 void print_helper(std::ostream & os,
const std::set<P, C, A> * param);
114 template <
typename T>
121 template <
typename T>
122 const T &
get (std::string_view)
const;
129 template <
typename T>
130 void insert (
const std::string &);
138 template <
typename T>
139 T &
set (
const std::string &);
150 void remove (std::string_view);
157 #ifdef LIBMESH_HAVE_RTTI 161 template <
typename T>
163 #endif // LIBMESH_HAVE_RTTI 168 virtual void clear ();
185 virtual ~Value() =
default;
187 #ifdef LIBMESH_HAVE_RTTI 192 virtual const std::type_info &
type_info ()
const = 0;
198 virtual std::string
type ()
const = 0;
199 #endif // LIBMESH_HAVE_RTTI 205 virtual void print(std::ostream &)
const = 0;
211 virtual std::unique_ptr<Value>
clone ()
const = 0;
218 template <
typename T>
226 const T &
get ()
const {
return _value; }
233 #ifdef LIBMESH_HAVE_RTTI 237 virtual const std::type_info &
type_info ()
const override;
242 virtual std::string
type ()
const override;
243 #endif // LIBMESH_HAVE_RTTI 248 virtual void print(std::ostream &)
const override;
253 virtual std::unique_ptr<Value>
clone ()
const override;
265 typedef std::map<std::string, std::unique_ptr<Value>, std::less<>>
map_type;
310 #ifdef LIBMESH_HAVE_RTTI 311 template <
typename T>
318 template <
typename T>
326 template <
typename T>
334 template <
typename T>
338 auto copy = std::make_unique<Parameter<T>>();
340 copy->_value = this->_value;
389 os <<
"Name\t Type\t Value\n" 390 <<
"---------------------\n";
393 os <<
" " << it->first
394 #ifdef LIBMESH_HAVE_RTTI 395 <<
"\t " << it->second->type()
396 #endif // LIBMESH_HAVE_RTTI 397 <<
"\t "; it->second->print(os);
418 template <
typename T>
426 #ifdef LIBMESH_HAVE_RTTI 428 if (
dynamic_cast<const Parameter<T> *
>(it->second.get()))
431 #else // !LIBMESH_HAVE_RTTI 436 libmesh_warning(
"Parameters::have_parameter() may return false positives when RTTI is not enabled.");
449 template <
typename T>
453 if (!this->have_parameter<T>(
name))
455 std::ostringstream oss;
458 #ifdef LIBMESH_HAVE_RTTI 461 oss <<
" parameter named \"" 462 <<
name <<
"\" found.\n\n" 463 <<
"Known parameters:\n" 466 libmesh_error_msg(oss.str());
475 auto ptr = cast_ptr<Parameter<T> *>(it->second.get());
481 template <
typename T>
485 if (!this->have_parameter<T>(
name))
492 template <
typename T>
496 if (!this->have_parameter<T>(
name))
502 auto ptr = cast_ptr<Parameter<T> *>(
_values[
name].get());
519 #ifdef LIBMESH_HAVE_RTTI 520 template <
typename T>
524 unsigned int cnt = 0;
526 for (
const auto & pr :
_values)
570 os << static_cast<int>(*param);
578 os << static_cast<int>(*param);
585 for (
const auto & p : *param)
591 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param)
593 for (
const auto & pv : *param)
594 for (
const auto & p : pv)
600 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param)
602 for (
const auto & pvv : *param)
603 for (
const auto & pv : pvv)
604 for (
const auto & p : pv)
609 template<
typename P1,
typename P2,
typename C,
typename A>
610 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param)
613 std::size_t sz = param->size();
614 for (
auto KV : *param)
616 os <<
'\'' << KV.first <<
"\' => \'" << KV.second <<
'\'';
624 template<
typename P,
typename C,
typename A>
627 for (
const auto & p : *param)
634 #endif // LIBMESH_PARAMETERS_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
virtual const std::type_info & type_info() const override
std::type_info for type of parameter stored.
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.
virtual const std::type_info & type_info() const =0
std::type_info for type of parameter stored.