From 4f33a5625d7e61c0f78deff6afd2d87d342f066a Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Tue, 18 Jul 2017 21:04:24 +0200 Subject: [PATCH] Specialization of Convert for Map types. --- include/deal.II/base/patterns_tools.h | 121 +++++++++++++++++++++++--- source/base/patterns_tools.cc | 11 ++- 2 files changed, 117 insertions(+), 15 deletions(-) diff --git a/include/deal.II/base/patterns_tools.h b/include/deal.II/base/patterns_tools.h index 92549022b9..631de078ef 100644 --- a/include/deal.II/base/patterns_tools.h +++ b/include/deal.II/base/patterns_tools.h @@ -76,6 +76,7 @@ namespace PatternsTools struct RankInfo { typedef std::integral_constant::type vector_rank_type; + typedef std::integral_constant::type map_rank_type; }; @@ -94,6 +95,15 @@ namespace PatternsTools + /** + * Return the default map separator for an object with the given map rank. + * + * This function helps in constructing patterns for non elementary types, + * like for example std::map> + */ + std::string default_map_separator(unsigned int); + + /** * Converter class. This class is used to generate strings and Patterns associated to * the given type, and to convert from a string to the given type and viceversa. @@ -114,14 +124,14 @@ namespace PatternsTools * passed to perform the conversion, or create and use a default one. */ static std::string to_string(const T &s, - std::unique_ptr p = Convert::to_pattern()) = delete; + const std::unique_ptr &p = Convert::to_pattern()) = delete; /** * Convert a string to a value, using the given pattern, or a default one. */ static T to_value(const std::string &s, - std::unique_ptr p = Convert::to_pattern()) = delete; + const std::unique_ptr &p = Convert::to_pattern()) = delete; }; /** @@ -150,17 +160,18 @@ namespace PatternsTools static std::unique_ptr to_pattern() { - if(std::is_integral::value) + if (std::is_integral::value) return std_cxx14::make_unique(std::numeric_limits::min(), std::numeric_limits::max()); - else if(std::is_floating_point::value) + else if (std::is_floating_point::value) return std_cxx14::make_unique(std::numeric_limits::min(), std::numeric_limits::max()); - else { - AssertThrow(false, ExcNotImplemented()); - return std::unique_ptr(); + else + { + AssertThrow(false, ExcNotImplemented()); + return std::unique_ptr(); } } - static std::string to_string(const T &value, std::unique_ptr p = Convert::to_pattern()) + static std::string to_string(const T &value, const std::unique_ptr &p = Convert::to_pattern()) { std::stringstream str; str << value; @@ -169,7 +180,7 @@ namespace PatternsTools } static T to_value(const std::string &s, - std::unique_ptr p = Convert::to_pattern()) + const std::unique_ptr &p = Convert::to_pattern()) { AssertThrow(p->match(s), ExcNoMatch(s, *p)); std::istringstream is(s); @@ -186,10 +197,22 @@ namespace PatternsTools struct RankInfo> { typedef typename std::integral_constant::vector_rank_type::value+1>::type vector_rank_type; + typedef typename std::integral_constant::type map_rank_type; }; + // Rank of map types + template