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" 48 void print_helper(std::ostream & os,
const std::vector<P> * param);
51 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param);
54 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param);
56 template<
typename P1,
typename P2,
typename C,
typename A>
57 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param);
59 template <
typename P,
typename C,
typename A>
60 void print_helper(std::ostream & os,
const std::set<P, C, A> * param);
111 template <
typename T>
118 template <
typename T>
119 const T &
get (std::string_view)
const;
126 template <
typename T>
127 void insert (
const std::string &);
135 template <
typename T>
136 T &
set (
const std::string &);
147 void remove (std::string_view);
154 #ifdef LIBMESH_HAVE_RTTI 158 template <
typename T>
160 #endif // LIBMESH_HAVE_RTTI 165 virtual void clear ();
182 virtual ~Value() =
default;
184 #ifdef LIBMESH_HAVE_RTTI 189 virtual std::string
type ()
const = 0;
190 #endif // LIBMESH_HAVE_RTTI 196 virtual void print(std::ostream &)
const = 0;
202 virtual std::unique_ptr<Value>
clone ()
const = 0;
209 template <
typename T>
217 const T &
get ()
const {
return _value; }
224 #ifdef LIBMESH_HAVE_RTTI 228 virtual std::string
type ()
const override;
229 #endif // LIBMESH_HAVE_RTTI 234 virtual void print(std::ostream &)
const override;
239 virtual std::unique_ptr<Value>
clone ()
const override;
251 typedef std::map<std::string, std::unique_ptr<Value>, std::less<>>
map_type;
296 #ifdef LIBMESH_HAVE_RTTI 297 template <
typename T>
305 template <
typename T>
313 template <
typename T>
317 auto copy = std::make_unique<Parameter<T>>();
319 copy->_value = this->_value;
368 os <<
"Name\t Type\t Value\n" 369 <<
"---------------------\n";
372 os <<
" " << it->first
373 #ifdef LIBMESH_HAVE_RTTI 374 <<
"\t " << it->second->type()
375 #endif // LIBMESH_HAVE_RTTI 376 <<
"\t "; it->second->print(os);
397 template <
typename T>
405 #ifdef LIBMESH_HAVE_RTTI 407 if (
dynamic_cast<const Parameter<T> *
>(it->second.get()))
410 #else // !LIBMESH_HAVE_RTTI 415 libmesh_warning(
"Parameters::have_parameter() may return false positives when RTTI is not enabled.");
428 template <
typename T>
432 if (!this->have_parameter<T>(
name))
434 std::ostringstream oss;
437 #ifdef LIBMESH_HAVE_RTTI 440 oss <<
" parameter named \"" 441 <<
name <<
"\" found.\n\n" 442 <<
"Known parameters:\n" 445 libmesh_error_msg(oss.str());
454 auto ptr = cast_ptr<Parameter<T> *>(it->second.get());
460 template <
typename T>
464 if (!this->have_parameter<T>(
name))
471 template <
typename T>
475 if (!this->have_parameter<T>(
name))
481 auto ptr = cast_ptr<Parameter<T> *>(
_values[
name].get());
498 #ifdef LIBMESH_HAVE_RTTI 499 template <
typename T>
503 unsigned int cnt = 0;
505 for (
const auto & pr :
_values)
549 os << static_cast<int>(*param);
557 os << static_cast<int>(*param);
564 for (
const auto & p : *param)
570 void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param)
572 for (
const auto & pv : *param)
573 for (
const auto & p : pv)
579 void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param)
581 for (
const auto & pvv : *param)
582 for (
const auto & pv : pvv)
583 for (
const auto & p : pv)
588 template<
typename P1,
typename P2,
typename C,
typename A>
589 void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param)
592 std::size_t sz = param->size();
593 for (
auto KV : *param)
595 os <<
'\'' << KV.first <<
"\' => \'" << KV.second <<
'\'';
603 template<
typename P,
typename C,
typename A>
606 for (
const auto & p : *param)
613 #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.