From: Luca Heltai Date: Fri, 27 Oct 2017 12:17:28 +0000 (+0200) Subject: Test with add_parameters, example in documentation. X-Git-Tag: v9.0.0-rc1~848^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cf5238791bb9a84a674d7985e3a14004b602e53;p=dealii.git Test with add_parameters, example in documentation. --- diff --git a/include/deal.II/base/patterns.h b/include/deal.II/base/patterns.h index e4e8097125..8d12d0b5f0 100644 --- a/include/deal.II/base/patterns.h +++ b/include/deal.II/base/patterns.h @@ -683,6 +683,27 @@ namespace Patterns * bool check = ps.match("5: 3.14: Ciao"); // check = true * @endcode * + * or, if you want to exploit ParameterHandler::add_parameter(): + * + * @code + * typedef std::tuple, unsigned int> T; + * + * T a = Patterns::Tools::Convert::to_value("Ciao : 1.0, 2.0, 3.0 : 33"); + * + * ParameterHandler prm; + * prm.add_parameter("A tuple", a); + * + * prm.log_parameters(deallog); + * // DEAL:parameters::A tuple: Ciao : 1.000000, 2.000000, 3.000000 : 33 + * + * prm.set("A tuple", "Mondo : 2.0, 3.0, 4.0 : 34"); + * prm.log_parameters(deallog); + * // DEAL:parameters::A tuple: Mondo : 2.0, 3.0, 4.0 : 34 + * + * deallog << 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. * diff --git a/tests/base/patterns_12.cc b/tests/base/patterns_12.cc new file mode 100644 index 0000000000..e7bd339de5 --- /dev/null +++ b/tests/base/patterns_12.cc @@ -0,0 +1,50 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2005 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +// test add_parameters with tuples. + +#include "../tests.h" +#include +#include +#include + +using namespace Patterns; +using namespace Patterns::Tools; + +int main() +{ + initlog(); + + typedef std::tuple, unsigned int> T; + + T a; + a = Convert::to_value("Ciao : 1.0, 2.0, 3.0 : 33"); + + ParameterHandler prm; + prm.add_parameter("A tuple", a); + + prm.log_parameters(deallog); + + prm.set("A tuple", "Mondo : 2.0, 3.0, 4.0 : 34"); + + deallog << "After ParameterHandler::set ==========================" + << std::endl << std::endl; + prm.log_parameters(deallog); + + deallog << "Actual variables ==========================" + << std::endl << std::endl; + + deallog << Convert::to_string(a) << std::endl; +} diff --git a/tests/base/patterns_12.output b/tests/base/patterns_12.output new file mode 100644 index 0000000000..61f2e33db2 --- /dev/null +++ b/tests/base/patterns_12.output @@ -0,0 +1,8 @@ + +DEAL:parameters::A tuple: Ciao : 1.000000, 2.000000, 3.000000 : 33 +DEAL::After ParameterHandler::set ========================== +DEAL:: +DEAL:parameters::A tuple: Mondo : 2.0, 3.0, 4.0 : 34 +DEAL::Actual variables ========================== +DEAL:: +DEAL::Mondo : 2.000000, 3.000000, 4.000000 : 34