]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test with add_parameters, example in documentation.
authorLuca Heltai <luca.heltai@sissa.it>
Fri, 27 Oct 2017 12:17:28 +0000 (14:17 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Sat, 28 Oct 2017 17:57:07 +0000 (19:57 +0200)
include/deal.II/base/patterns.h
tests/base/patterns_12.cc [new file with mode: 0644]
tests/base/patterns_12.output [new file with mode: 0644]

index e4e80971254579f16353f0ee16a7af410ede9aad..8d12d0b5f007ac128648ee0a3964621cafca5b66 100644 (file)
@@ -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<std::string, Point<3>, unsigned int> T;
+   *
+   * T a = Patterns::Tools::Convert<T>::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<T>::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 (file)
index 0000000..e7bd339
--- /dev/null
@@ -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 <deal.II/base/parameter_handler.h>
+#include <deal.II/base/std_cxx14/memory.h>
+#include <memory>
+
+using namespace Patterns;
+using namespace Patterns::Tools;
+
+int main()
+{
+  initlog();
+
+  typedef std::tuple<std::string, Point<3>, unsigned int> T;
+
+  T a;
+  a = Convert<T>::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<T>::to_string(a) << std::endl;
+}
diff --git a/tests/base/patterns_12.output b/tests/base/patterns_12.output
new file mode 100644 (file)
index 0000000..61f2e33
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.