Reference documentation for deal.II version Git 53084d8c6a 2020-10-21 00:34:33 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Patterns::Tuple Class Reference

#include <deal.II/base/patterns.h>

Inheritance diagram for Patterns::Tuple:
[legend]

Public Types

enum  OutputStyle { Machine, Text, LaTeX }
 

Public Member Functions

 Tuple (const std::vector< std::unique_ptr< PatternBase >> &patterns, const std::string &separator=":")
 
 Tuple (const std::vector< std::unique_ptr< PatternBase >> &patterns, const char *separator)
 
template<class... PatternTypes>
 Tuple (const std::string &separator, const PatternTypes &... patterns)
 
template<class... PatternTypes>
 Tuple (const char *separator, const PatternTypes &... patterns)
 
template<typename... Patterns>
 Tuple (const Patterns &... patterns)
 
 Tuple (const Tuple &other)
 
virtual bool match (const std::string &test_string) const override
 
virtual std::string description (const OutputStyle style=Machine) const override
 
virtual std::unique_ptr< PatternBaseclone () const override
 
std::size_t memory_consumption () const override
 
const PatternBaseget_pattern (const unsigned int i) const
 
const std::string & get_separator () const
 

Static Public Member Functions

static std::unique_ptr< Tuplecreate (const std::string &description)
 

Private Attributes

std::vector< std::unique_ptr< PatternBase > > patterns
 
const std::string separator
 

Static Private Attributes

static const char * description_init = "[Tuple"
 

Detailed Description

This pattern matches colon-separated values of arbitrary types. Each type has to match a pattern given to the constructor.

An example usage is the following:

std::vector< std::unique_ptr<Patterns::PatternBase> > ps;
ps.push_back(std::unique_ptr<Patterns::Integer>());
ps.push_back(std::unique_ptr<Patterns::Double>());
ps.push_back(std::unique_ptr<Patterns::Anything>());
Patterns::Tuple pattern(ps, ":");
bool check = ps.match("5 : 3.14 : Ciao"); // check = true

or, if you want to exploit ParameterHandler::add_parameter():

using T = std::tuple<std::string, Point<3>, unsigned int>;
T a = Patterns::Tools::Convert<T>::to_value("Ciao : 1.0, 2.0, 3.0 : 33");
prm.add_parameter("A tuple", a);
// DEAL:parameters::A tuple: Ciao : 1.000000, 2.000000, 3.000000 : 33
prm.set("A tuple", "Mondo : 2.0, 3.0, 4.0 : 34");
// DEAL:parameters::A tuple: Mondo : 2.0, 3.0, 4.0 : 34
// DEAL::Mondo : 2.000000, 3.000000, 4.000000 : 34

The constructor expects a vector of Patterns, and optionally a string specifying the separator to use when parsing the Tuple from a string.

The default separator is a colon, owing to the fact that a pair is in fact a tuple with two elements.

Definition at line 771 of file patterns.h.

Member Enumeration Documentation

◆ OutputStyle

List of possible description output formats.

Capitalization chosen for similarity to ParameterHandler::OutputStyle.

Enumerator
Machine 

Simple text suitable for machine parsing in the static public member functions for all of the built in inheriting classes.

Preferably human readable, but machine parsing is more critical.

Text 

Easily human readable plain text format suitable for plain text documentation.

LaTeX 

Easily human readable LaTeX format suitable for printing in manuals.

Definition at line 98 of file patterns.h.

Constructor & Destructor Documentation

◆ Tuple() [1/6]

Patterns::Tuple::Tuple ( const std::vector< std::unique_ptr< PatternBase >> &  patterns,
const std::string &  separator = ":" 
)

Constructor. Use a vector of unique pointers to Patterns to construct the tuple.

Parameters
patternsThe pattern each object of the Tuple should match
separatorAn optional string used to delimit each element Constructor.

Definition at line 1057 of file patterns.cc.

◆ Tuple() [2/6]

Patterns::Tuple::Tuple ( const std::vector< std::unique_ptr< PatternBase >> &  patterns,
const char *  separator 
)

Constructor. Same as above, specialized for const char *. This is necessary to avoid compilers errors due to the variadic constructors provided below.

Definition at line 1072 of file patterns.cc.

◆ Tuple() [3/6]

template<class... PatternTypes>
Patterns::Tuple::Tuple ( const std::string &  separator,
const PatternTypes &...  patterns 
)

Constructor. Creates a Tuple from more than one class derived from PatternBase.

Parameters
separatorWhat separator to use.
patternsThe list of patterns to use

Definition at line 1424 of file patterns.h.

◆ Tuple() [4/6]

template<class... PatternTypes>
Patterns::Tuple::Tuple ( const char *  separator,
const PatternTypes &...  patterns 
)

Constructor. This is needed to allow users to specify directly the separator without using std::string(";").

Since we support a pure variadic templates version, without this specialization, the compiler will fail with cryptic errors.

Definition at line 1416 of file patterns.h.

◆ Tuple() [5/6]

template<class... PatternTypes>
Patterns::Tuple::Tuple ( const PatternTypes &...  patterns)

Constructor. Same as above, using the default separator.

Parameters
patternsThe list of patterns to use

Definition at line 1440 of file patterns.h.

◆ Tuple() [6/6]

Patterns::Tuple::Tuple ( const Tuple other)

Copy constructor.

Definition at line 1079 of file patterns.cc.

Member Function Documentation

◆ match()

bool Patterns::Tuple::match ( const std::string &  test_string) const
overridevirtual

Return true if the string is a list of strings each of which matches the patterns given to the constructor.

Implements Patterns::PatternBase.

Definition at line 1090 of file patterns.cc.

◆ description()

std::string Patterns::Tuple::description ( const OutputStyle  style = Machine) const
overridevirtual

Return a description of the pattern that valid strings are expected to match.

Implements Patterns::PatternBase.

Definition at line 1109 of file patterns.cc.

◆ clone()

std::unique_ptr< PatternBase > Patterns::Tuple::clone ( ) const
overridevirtual

Return a copy of the present object, which is newly allocated on the heap. Ownership of that object is transferred to the caller of this function.

Implements Patterns::PatternBase.

Definition at line 1159 of file patterns.cc.

◆ create()

std::unique_ptr< Tuple > Patterns::Tuple::create ( const std::string &  description)
static

Create a new object if the start of description matches description_init. Ownership of that object is transferred to the caller of this function.

Definition at line 1175 of file patterns.cc.

◆ memory_consumption()

std::size_t Patterns::Tuple::memory_consumption ( ) const
overridevirtual

Determine an estimate for the memory consumption (in bytes) of this object.

Reimplemented from Patterns::PatternBase.

Definition at line 1166 of file patterns.cc.

◆ get_pattern()

const PatternBase & Patterns::Tuple::get_pattern ( const unsigned int  i) const

Return a reference to the i-th pattern in the tuple.

Definition at line 1223 of file patterns.cc.

◆ get_separator()

const std::string & Patterns::Tuple::get_separator ( ) const

Return the separator of the tuple entries.

Definition at line 1231 of file patterns.cc.

Member Data Documentation

◆ patterns

std::vector<std::unique_ptr<PatternBase> > Patterns::Tuple::patterns
private

Copy of the patterns stored in the Tuple.

Definition at line 880 of file patterns.h.

◆ separator

const std::string Patterns::Tuple::separator
private

Separator between elements of the list.

Definition at line 885 of file patterns.h.

◆ description_init

const char * Patterns::Tuple::description_init = "[Tuple"
staticprivate

Initial part of description.

Definition at line 890 of file patterns.h.


The documentation for this class was generated from the following files: