Reference documentation for deal.II version 9.0.0
|
Classes | |
struct | Convert |
Functions | |
template<typename T > | |
std::string | to_string (const T &t) |
template<typename T > | |
void | to_value (const std::string &s, T &t) |
static ::ExceptionBase & | ExcNoMatch (std::string arg1, Patterns::PatternBase &arg2) |
Namespace for a few classes and functions that act on values and patterns, and allow to convert from non elementary types to strings and vice versa.
A typical usage of these tools is in the following example:
Convert<T> is used by the function Patterns::Tools::add_parameter() in this namespace. Internally it uses the internal::RankInfo<T> class to decide how many different separators are required to convert the given type to a string.
For example, to write vectors of vectors, the default is to use "," for the first (inner) separator, and ";" for the second (outer) separator, i.e.
Separators for Patterns::List and Patterns::Map compatible types are selected according to the rank of the list and map objects, using the arrays Patterns::Tools::internal::default_list_separator and Patterns::Tools::internal::default_map_separator.
They are currently set to:
When one needs a mixture of Patterns::List and Patterns::Map types, their RankInfo is computed by taking the maximum of the vector_rank of the Key and of the Value type, so that, for example, it is possible to have the following
Some non elementary types are supported, like Point(), or std::complex<double>. If you wish to support more types, you have to specialize the Convert struct as well as the RankInfo struct.
std::string Patterns::Tools::to_string | ( | const T & | t | ) |
A utility function that simplifies the conversion to strings of arbitrarily complex types.
This function calls the method Convert<T>::to_string() with the default pattern. An example usage is the following:
See the documentation of the class Patterns::Tools::Convert, and of the helper class Patterns::Tools::RankInfo for details on the way separators are selected when outputting STL container types.
Definition at line 2075 of file patterns.h.
void Patterns::Tools::to_value | ( | const std::string & | s, |
T & | t | ||
) |
A utility function that simplifies the conversion from strings to arbitrary types.
This function calls the method Convert<T>::to_value() with the default pattern. An example usage is the following:
See the documentation of the class Patterns::Tools::Convert, and of the helper class Patterns::Tools::RankInfo for details on the separators you should use in your string patterns when converting from a string to a container type.
Notice that the current content of variable t
is ignored. Its type is used to infer how to interpret the string. If the string is succesfully parsed, then t
will be set to the parsed content of s
.
Definition at line 2082 of file patterns.h.