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
51void print_helper(std::ostream & os,
const std::vector<P> * param);
54void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param);
57void print_helper(std::ostream & os,
const std::vector<std::vector<std::vector<P>>> * param);
59template<
typename P1,
typename P2,
typename C,
typename A>
60void print_helper(std::ostream & os,
const std::map<P1, P2, C, A> * param);
62template <
typename P,
typename C,
typename A>
63void 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>
168 virtual void clear ();
187#ifdef LIBMESH_HAVE_RTTI
198 virtual std::string
type ()
const = 0;
205 virtual void print(std::ostream &)
const = 0;
211 virtual std::unique_ptr<Value>
clone ()
const = 0;
218 template <
typename T>
233#ifdef LIBMESH_HAVE_RTTI
237 virtual const std::type_info &
type_info ()
const override;
242 virtual std::string
type ()
const override;
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
322 return demangle(type_info().name());
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()
397 <<
"\t "; it->second->print(os);
426#ifdef LIBMESH_HAVE_RTTI
428 if (
dynamic_cast<const Parameter<T> *
>(it->second.get()))
436 libmesh_warning(
"Parameters::have_parameter() may return false positives when RTTI is not enabled.");
453 if (!this->have_parameter<T>(name))
455 std::ostringstream oss;
458#ifdef LIBMESH_HAVE_RTTI
459 oss <<
' ' <<
demangle(
typeid(T).name());
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());
485 if (!this->have_parameter<T>(name))
486 _values[name] = std::make_unique<Parameter<T>>();
496 if (!this->have_parameter<T>(name))
497 _values[name] = std::make_unique<Parameter<T>>();
502 auto ptr = cast_ptr<Parameter<T> *>(
_values[name].get());
519#ifdef LIBMESH_HAVE_RTTI
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)
591void print_helper(std::ostream & os,
const std::vector<std::vector<P>> * param)
593 for (
const auto & pv : *param)
594 for (
const auto & p : pv)
600void 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)
609template<
typename P1,
typename P2,
typename C,
typename A>
610void 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 <<
'\'';
624template<
typename P,
typename C,
typename A>
627 for (
const auto & p : *param)
Concrete definition of a parameter value for a specified type.
virtual std::unique_ptr< Value > clone() const override
Clone this value.
T _value
Stored parameter value.
virtual const std::type_info & type_info() const override
std::type_info for type of parameter stored.
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.
Abstract definition of a parameter value.
virtual const std::type_info & type_info() const =0
std::type_info for type of parameter stored.
virtual ~Value()=default
Destructor.
virtual std::string type() const =0
String identifying the type of parameter stored.
virtual void print(std::ostream &) const =0
Prints the parameter value to the specified stream.
virtual std::unique_ptr< Value > clone() const =0
Clone this value.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
map_type::iterator iterator
Parameter map iterator.
void remove(std::string_view)
Removes the specified parameter from the list, if it exists.
std::size_t n_parameters() const
bool have_parameter(std::string_view) const
iterator begin()
Iterator pointing to the beginning of the set of parameters.
void insert(const std::string &)
Inserts a new Parameter into the object but does not return a writable reference.
map_type _values
Data structure to map names with values.
map_type::const_iterator const_iterator
Constant parameter map iterator.
virtual void clear()
Clears internal data structures & frees any allocated memory.
T & set(const std::string &)
void print(std::ostream &os=libMesh::out) const
Prints the contents, by default to libMesh::out.
iterator end()
Iterator pointing to the end of the set of parameters.
virtual void set_attributes(const std::string &, bool)
Overridable function to set any extended attributes for classes inheriting from this class.
virtual Parameters & operator=(const Parameters &source)
Assignment operator.
virtual Parameters & operator+=(const Parameters &source)
Addition/Assignment operator.
virtual ~Parameters()=default
Destructor.
const T & get(std::string_view) const
std::map< std::string, std::unique_ptr< Value >, std::less<> > map_type
The type of the map that we store internally.
Parameters()=default
Default constructor.
This class implements reference counting.
The libMesh namespace provides an interface to certain functionality in the library.
std::string demangle(const char *name)
Mostly system independent demangler.
std::ostream & operator<<(std::ostream &os, const OrderWrapper &order)
Overload stream operators.
void print_helper(std::ostream &os, const P *param)
Helper functions for printing scalar, vector, vector<vector> and vector<vector<vector>> types.
Tnew cast_ptr(Told *oldvar)