]> https://gitweb.dealii.org/ - dealii.git/commitdiff
constructor CellId from string 10996/head
authorTimo Heister <timo.heister@gmail.com>
Thu, 1 Oct 2020 19:34:08 +0000 (15:34 -0400)
committerTimo Heister <timo.heister@gmail.com>
Fri, 2 Oct 2020 19:04:48 +0000 (19:04 +0000)
doc/news/changes/minor/20201001Heister [new file with mode: 0644]
include/deal.II/grid/cell_id.h
source/grid/cell_id.cc
tests/grid/cell_id_07.cc [new file with mode: 0644]
tests/grid/cell_id_07.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20201001Heister b/doc/news/changes/minor/20201001Heister
new file mode 100644 (file)
index 0000000..8fce5c2
--- /dev/null
@@ -0,0 +1,3 @@
+New: CellId has a new constructor to create it from a std::string.
+<br>
+(Timo Heister, 2020/10/05)
index 3078efc1fe098262f1169e2edeb0f3712267b478..15b7425ea18badef77353cb19aee1fbdaaf9582e 100644 (file)
@@ -112,6 +112,12 @@ public:
    */
   CellId(const binary_type &binary_representation);
 
+  /**
+   * Create a CellId from a string with the same format that is produced by
+   * to_string().
+   */
+  explicit CellId(const std::string &string_representation);
+
   /**
    * Construct an invalid CellId.
    */
index 28c4b8206c42e1ce13423f706519607cd445c32c..81ba05cdb629415ac89c7f3626f00b430ebb9963 100644 (file)
@@ -97,6 +97,14 @@ CellId::CellId(const CellId::binary_type &binary_representation)
 
 
 
+CellId::CellId(const std::string &string_representation)
+{
+  std::istringstream ss(string_representation);
+  ss >> *this;
+}
+
+
+
 template <int dim>
 CellId::binary_type
 CellId::to_binary() const
diff --git a/tests/grid/cell_id_07.cc b/tests/grid/cell_id_07.cc
new file mode 100644 (file)
index 0000000..dc780f6
--- /dev/null
@@ -0,0 +1,44 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// testing CellId from / to_string
+
+#include <deal.II/grid/cell_id.h>
+
+#include "../tests.h"
+
+int
+main()
+{
+  initlog();
+
+  std::vector<CellId> ids;
+
+  ids.emplace_back(CellId(0, {0}));
+  ids.emplace_back(CellId(0, {1}));
+  ids.emplace_back(CellId(0, {0, 0}));
+  ids.emplace_back(CellId(0, {1, 2, 0}));
+  ids.emplace_back(CellId(23, {}));
+
+  for (const auto &id : ids)
+    {
+      std::string s = id.to_string();
+      deallog << s << '\n';
+      AssertThrow(CellId(s) == id, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/grid/cell_id_07.output b/tests/grid/cell_id_07.output
new file mode 100644 (file)
index 0000000..65da49f
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::0_1:0
+0_1:1
+0_2:00
+0_3:120
+23_0:
+OK

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.