From 60d946c72512421a3975b98a3ce7ba53f5b80fae Mon Sep 17 00:00:00 2001 From: Sandro Elsweijer Date: Tue, 19 Nov 2024 21:11:22 +0100 Subject: [PATCH] convert array to map --- src/t8_schemes/t8_scheme.hxx | 8 ++++++-- src/t8_schemes/t8_scheme_builder.hxx | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/t8_schemes/t8_scheme.hxx b/src/t8_schemes/t8_scheme.hxx index fe1ff70005..999c0b9e24 100644 --- a/src/t8_schemes/t8_scheme.hxx +++ b/src/t8_schemes/t8_scheme.hxx @@ -23,7 +23,7 @@ #pragma once #include -#include +#include #include #include #include @@ -64,7 +64,7 @@ class t8_scheme { >; /* clang-format on */ - using scheme_container = std::array; /**< Container type for holding eclass schemes. */ + using scheme_container = std::unordered_map; /**< Container type for holding eclass schemes. */ private: scheme_container eclass_schemes; /**< The container holding the eclass schemes. */ @@ -114,6 +114,10 @@ class t8_scheme { inline size_t get_element_size (t8_eclass_t tree_class) const { +#if T8_ENABLE_DEBUG + // Check if the scheme actually exists + T8_ASSERT (eclass_schemes.contains (tree_class)); +#endif // T8_ENABLE_DEBUG return std::visit ([&] (auto &&scheme) { return scheme.get_element_size (); }, eclass_schemes[tree_class]); }; diff --git a/src/t8_schemes/t8_scheme_builder.hxx b/src/t8_schemes/t8_scheme_builder.hxx index 9f3f038a42..f1deede917 100644 --- a/src/t8_schemes/t8_scheme_builder.hxx +++ b/src/t8_schemes/t8_scheme_builder.hxx @@ -29,6 +29,11 @@ #include +#if T8_ENABLE_DEBUG +// Only needed for a debug print +#include +#endif // T8_ENABLE_DEBUG + class t8_scheme_builder { public: t8_scheme_builder (): scheme (new t8_scheme) {}; @@ -40,7 +45,17 @@ class t8_scheme_builder { void add_eclass_scheme (t8_eclass_t tree_class, _Args &&...args) { - scheme->eclass_schemes[tree_class] = TEclass_Scheme (std::forward<_Args> (args)...); +#if T8_ENABLE_DEBUG + // This way the typeinfo header is only included when needed + t8_debugf ("Registering scheme of type %s for tree class %s.\n", typeid (T).name (), + t8_eclass_to_string[tree_class]); +#endif // T8_ENABLE_DEBUG + if (scheme->eclass_schemes.find (tree_class) == scheme->eclass_schemes.end ()) { + registered_geometries.emplace (tree_class, TEclass_Scheme (std::forward<_Args> (args)...)); + } + else { + SC_ABORTF ("Scheme for tree class %d already exists.", tree_class); + } } t8_scheme *