]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Custom enums.
authorLuca Heltai <luca.heltai@unipi.it>
Mon, 12 Aug 2024 21:25:57 +0000 (15:25 -0600)
committerLuca Heltai <luca.heltai@unipi.it>
Mon, 12 Aug 2024 21:25:57 +0000 (15:25 -0600)
tests/parameter_handler/pattern_tools_15.cc [new file with mode: 0644]
tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output [new file with mode: 0644]

diff --git a/tests/parameter_handler/pattern_tools_15.cc b/tests/parameter_handler/pattern_tools_15.cc
new file mode 100644 (file)
index 0000000..9c77ba5
--- /dev/null
@@ -0,0 +1,56 @@
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2010 - 2022 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// Part of the source code is dual licensed under Apache-2.0 WITH
+// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
+// governing the source code and code contributions can be found in
+// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
+//
+// ------------------------------------------------------------------------
+
+// Check Patterns::Tools::Convert for custom enum types
+
+#include <deal.II/fe/fe_values.h>
+
+#include <memory>
+
+#include "../tests.h"
+
+enum TestFlag
+{
+  red   = 1,
+  green = 2,
+  blue  = 4
+};
+
+enum class TestFlagClass
+{
+  yellow = 1,
+  orange = 2,
+  white  = 4
+};
+
+template <typename T>
+using C = Patterns::Tools::Convert<T>;
+
+int
+main()
+{
+  initlog();
+  {
+    TestFlag flags = red;
+    deallog << C<TestFlag>::to_string(flags) << std::endl;
+    flags = C<TestFlag>::to_value("green|blue");
+    deallog << C<TestFlag>::to_string(flags) << std::endl;
+  }
+  {
+    TestFlagClass flags = TestFlagClass::yellow;
+    deallog << C<TestFlagClass>::to_string(flags) << std::endl;
+    flags = C<TestFlagClass>::to_value("orange|white");
+    deallog << C<TestFlagClass>::to_string(flags) << std::endl;
+  }
+}
diff --git a/tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output b/tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output
new file mode 100644 (file)
index 0000000..5b15e10
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::red
+DEAL::green| blue
+DEAL::yellow
+DEAL::orange| white

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.