Reference documentation for deal.II version Git 6fa7894 2017-12-12 13:14:59 +0100
Classes | Functions
Patterns::Tools Namespace Reference

Classes

struct  Convert
 

Functions

static::ExceptionBase & ExcNoMatch (std::string arg1, Patterns::PatternBase &arg2)
 

Detailed Description

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:

typedef std::vector<unsigned int> T;
T vec(3);
vec[0] = 1;
vec[1] = 3;
vec[2] = 5;
std::cout << pattern->description() << std::endl;
// [List of <[Integer]> of length 0...4294967295 (inclusive)]
std::cout << s << std::endl;
// 1, 2, 3
// now vec has size 4, and contains the elements 2,3,4,5
std::cout << internal::RankInfo<T>::list_rank << std::endl; // Outputs 1
std::cout << internal::RankInfo<T>::map_rank << std::endl; // Outputs 0

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.

std::vector<std::vector<unsigned int>> vec;
vec = Convert<decltype(vec)>::to_value("1,2,3 ; 4,5,6");
s = convert<decltype(vec[0])>::to_string(vec[0]);
// s now contains the string "1,2,3"

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:

default_list_separator{{"," , ";" , "|" , "%"}};
default_map_separator {{":" , "=" , "@" , "#"}};

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

... // Build compare class
std::map<std::vector<unsigned int>, std::vector<double>, compare> map;
map = convert<decltype(map)>::to_value("1,2,3 : 5.0,6.0,7.0 ; 8,9,10 :
11.0,12.0,13.0");

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.

Author
Luca Heltai, 2017