From ad51c2d24dc3dff65c7919fc8bb49fd07b6cbbc0 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Wed, 19 Jul 2017 21:23:41 +0200 Subject: [PATCH] Add Convert for string types. --- include/deal.II/base/patterns_tools.h | 44 +++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/include/deal.II/base/patterns_tools.h b/include/deal.II/base/patterns_tools.h index cc61706fa1..dc06e46aea 100644 --- a/include/deal.II/base/patterns_tools.h +++ b/include/deal.II/base/patterns_tools.h @@ -192,6 +192,11 @@ namespace PatternsTools << "The string " << arg1 << " does not match the pattern \"" << arg2.description() << "\""); //@} +} + + +// ---------------------- inline and template functions -------------------- +namespace PatternsTools { namespace internal { /** @@ -226,12 +231,8 @@ namespace PatternsTools static constexpr int map_rank = 0; }; } -} - -// ---------------------- inline and template functions -------------------- -namespace PatternsTools -{ + // Arithmetic types template struct Convert::value>::type> { @@ -320,6 +321,7 @@ namespace PatternsTools static constexpr bool const value = internal::is_stl_map>::value; }; + namespace internal { // Rank of vector types @@ -362,6 +364,7 @@ namespace PatternsTools } + // stl containers template struct Convert::value>::type> { @@ -420,6 +423,7 @@ namespace PatternsTools }; + // stl maps template struct Convert::value>::type> { @@ -487,6 +491,7 @@ namespace PatternsTools }; + // Tensors template struct Convert> { @@ -542,6 +547,7 @@ namespace PatternsTools }; + // Points template struct Convert> { @@ -567,7 +573,7 @@ namespace PatternsTools }; - + // Complex numbers template struct Convert> { @@ -619,6 +625,32 @@ namespace PatternsTools }; + // Strings + template<> + struct Convert + { + typedef std::string T; + + static std::unique_ptr to_pattern() + { + return std_cxx14::make_unique(); + } + + static std::string to_string(const T &t, + const std::unique_ptr &pattern = Convert::to_pattern()) + { + AssertThrow(pattern->match(t), ExcNoMatch(t,*pattern)); + return t; + } + + static T to_value(const std::string &s, + const std::unique_ptr &pattern = Convert::to_pattern()) + { + AssertThrow(pattern->match(s), ExcNoMatch(s,*pattern)); + return s; + } + }; + template void add_parameter(const std::string &entry, -- 2.39.5