From: Luca Heltai Date: Sat, 28 Oct 2017 17:54:16 +0000 (+0200) Subject: Addressed WB comments. X-Git-Tag: v9.0.0-rc1~848^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=872eb93d68e25e7f642be9019797b44738cfefd7;p=dealii.git Addressed WB comments. --- diff --git a/include/deal.II/base/patterns.h b/include/deal.II/base/patterns.h index 5e5de71143..ee9932adbb 100644 --- a/include/deal.II/base/patterns.h +++ b/include/deal.II/base/patterns.h @@ -527,7 +527,7 @@ namespace Patterns * map is described in the form key1: value1, key2: value2, key3: * value3, .... Two constructor arguments allow to choose a delimiter * between pairs other than the comma, and a delimeter between key and value - * other than column. + * other than colon. * * With two additional parameters, the number of elements this list has to * have can be specified. If none is specified, the map may have zero or @@ -666,7 +666,7 @@ namespace Patterns /** - * This pattern matches column-separated values of arbitrary types. Each type + * 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: @@ -680,7 +680,7 @@ namespace Patterns * * Patterns::Tuple pattern(ps, ":"); * - * bool check = ps.match("5: 3.14: Ciao"); // check = true + * bool check = ps.match("5 : 3.14 : Ciao"); // check = true * @endcode * * or, if you want to exploit ParameterHandler::add_parameter(): @@ -700,15 +700,15 @@ namespace Patterns * prm.log_parameters(deallog); * // DEAL:parameters::A tuple: Mondo : 2.0, 3.0, 4.0 : 34 * - * deallog << Convert::to_string(a) << std::endl; + * deallog << Patterns::Tools::Convert::to_string(a) << std::endl; * // DEAL::Mondo : 2.000000, 3.000000, 4.000000 : 34 * @endcode * * 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 the semicolumn, owing to the fact that a pair - * is in fact a tuple with two elements. + * The default separator is a colon, owing to the fact that a pair is in fact + * a tuple with two elements. * * @author Luca Heltai, 2017. */ @@ -1866,7 +1866,6 @@ namespace Patterns } }; - // Pairs template struct Convert> @@ -1923,6 +1922,38 @@ namespace Patterns *Convert::to_pattern()...); } + static std::string to_string(const T &t, + const std::unique_ptr + &pattern = Convert::to_pattern()) + { + auto p = dynamic_cast(pattern.get()); + AssertThrow(p,ExcMessage("I need a Tuple pattern to convert a tuple " + "to a string.")); + + const auto string_array = Convert::to_string_internal_2(t,*p); + std::string str; + for (unsigned int i=0; i< string_array.size(); ++i) + str += (i ? " " + p->get_separator() + " " : "") +string_array[i]; + AssertThrow(p->match(str), ExcNoMatch(str, *p)); + return str; + } + + static T to_value(const std::string &s, + const std::unique_ptr &pattern = + Convert::to_pattern()) + { + AssertThrow(pattern->match(s), ExcNoMatch(s, *pattern)); + + auto p = dynamic_cast(pattern.get()); + AssertThrow(p,ExcMessage("I need a Tuple pattern to convert a string " + "to a tuple type.")); + + auto v = Utilities::split_string_list(s, p->get_separator()); + + return Convert::to_value_internal_2(v,*p); + } + + private: template static std::array::value> @@ -1948,23 +1979,6 @@ namespace Patterns std_cxx14::make_index_sequence::value> {}); } - static std::string to_string(const T &t, - const std::unique_ptr - &pattern = Convert::to_pattern()) - { - auto p = dynamic_cast(pattern.get()); - AssertThrow(p,ExcMessage("I need a Tuple pattern to convert a tuple " - "to a string.")); - - const auto string_array = Convert::to_string_internal_2(t,*p); - std::string str; - for (unsigned int i=0; i< string_array.size(); ++i) - str += (i ? " " + p->get_separator() + " " : "") +string_array[i]; - AssertThrow(p->match(str), ExcNoMatch(str, *p)); - return str; - } - - template static T to_value_internal_1(const std::vector &s, @@ -1982,22 +1996,6 @@ namespace Patterns return Convert::to_value_internal_1(s, pattern, std_cxx14::make_index_sequence::value> {}); } - - - static T to_value(const std::string &s, - const std::unique_ptr &pattern = - Convert::to_pattern()) - { - AssertThrow(pattern->match(s), ExcNoMatch(s, *pattern)); - - auto p = dynamic_cast(pattern.get()); - AssertThrow(p,ExcMessage("I need a Tuple pattern to convert a string " - "to a tuple type.")); - - auto v = Utilities::split_string_list(s, p->get_separator()); - - return Convert::to_value_internal_2(v,*p); - } }; } diff --git a/tests/base/patterns_12.cc b/tests/base/patterns_13.cc similarity index 100% rename from tests/base/patterns_12.cc rename to tests/base/patterns_13.cc diff --git a/tests/base/patterns_12.output b/tests/base/patterns_13.output similarity index 100% rename from tests/base/patterns_12.output rename to tests/base/patterns_13.output