forked from dealii/dealii
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dealii#17491 from luca-heltai/patterns-enums
Added support for magic_enum.
- Loading branch information
Showing
9 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## ------------------------------------------------------------------------ | ||
## | ||
## SPDX-License-Identifier: LGPL-2.1-or-later | ||
## Copyright (C) 2012 - 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. | ||
## | ||
## ------------------------------------------------------------------------ | ||
|
||
# | ||
# Configuration for the MAGIC_ENUM library: | ||
# | ||
|
||
configure_feature(MAGIC_ENUM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## ------------------------------------------------------------------------ | ||
## | ||
## SPDX-License-Identifier: LGPL-2.1-or-later | ||
## Copyright (C) 2012 - 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. | ||
## | ||
## ------------------------------------------------------------------------ | ||
|
||
# | ||
# Try to find the MAGIC ENUM library | ||
# | ||
# This module exports | ||
# | ||
# MAGIC_ENUM_FOUND | ||
# MAGIC_ENUM_INCLUDE_DIRS | ||
# | ||
|
||
set(MAGIC_ENUM_DIR "" CACHE PATH "An optional hint to a MAGIC_ENUM installation") | ||
set_if_empty(MAGIC_ENUM_DIR "$ENV{MAGIC_ENUM_DIR}") | ||
|
||
deal_ii_find_path(MAGIC_ENUM_INCLUDE_DIR magic_enum.hpp | ||
HINTS ${MAGIC_ENUM_DIR} | ||
PATH_SUFFIXES include | ||
) | ||
|
||
process_feature(MAGIC_ENUM | ||
LIBRARIES | ||
INCLUDE_DIRS | ||
REQUIRED MAGIC_ENUM_INCLUDE_DIR | ||
CLEAR MAGIC_ENUM_INCLUDE_DIR | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
New: Added support for magic_enum.hpp. Now PatternsTools::Convert<T> works also when T is an enum type. | ||
<br> | ||
(Luca Heltai, 2024/08/12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ------------------------------------------------------------------------ | ||
// | ||
// 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 enum types | ||
// Test the conversion of UpdateFlags to string and back | ||
|
||
#include <deal.II/fe/fe_values.h> | ||
|
||
#include <memory> | ||
|
||
#include "../tests.h" | ||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
UpdateFlags flags = update_values; | ||
|
||
deallog << Patterns::Tools::Convert<UpdateFlags>::to_string(flags) | ||
<< std::endl; | ||
|
||
flags = Patterns::Tools::Convert<UpdateFlags>::to_value( | ||
"update_values|update_gradients"); | ||
|
||
deallog << Patterns::Tools::Convert<UpdateFlags>::to_string(flags) | ||
<< std::endl; | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/parameter_handler/pattern_tools_14.with_magic_enum=true.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
DEAL::update_default| update_values | ||
DEAL::update_default| update_values| update_gradients |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// ------------------------------------------------------------------------ | ||
// | ||
// 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 | ||
// Test the conversion of a standard enum to string and back, and of an enum | ||
// class to string and back | ||
|
||
#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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/parameter_handler/pattern_tools_15.with_magic_enum=true.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
DEAL::red | ||
DEAL::green| blue | ||
DEAL::yellow | ||
DEAL::orange| white |