Skip to content

Commit

Permalink
switch scheme array to vector
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro-elsweijer committed Nov 25, 2024
2 parents f57f762 + 60d946c commit 844e683
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/t8_schemes/t8_default/t8_default.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ t8_scheme_new_default (void)
{
t8_scheme_builder builder;

builder.add_eclass_scheme<t8_default_scheme_vertex> (T8_ECLASS_VERTEX);
builder.add_eclass_scheme<t8_default_scheme_line> (T8_ECLASS_LINE);
builder.add_eclass_scheme<t8_default_scheme_quad> (T8_ECLASS_QUAD);
builder.add_eclass_scheme<t8_default_scheme_hex> (T8_ECLASS_HEX);
builder.add_eclass_scheme<t8_default_scheme_tri> (T8_ECLASS_TRIANGLE);
builder.add_eclass_scheme<t8_default_scheme_tet> (T8_ECLASS_TET);
builder.add_eclass_scheme<t8_default_scheme_prism> (T8_ECLASS_PRISM);
builder.add_eclass_scheme<t8_default_scheme_pyramid> (T8_ECLASS_PYRAMID);
builder.add_eclass_scheme<t8_default_scheme_vertex> ();
builder.add_eclass_scheme<t8_default_scheme_line> ();
builder.add_eclass_scheme<t8_default_scheme_quad> ();
builder.add_eclass_scheme<t8_default_scheme_tri> ();
builder.add_eclass_scheme<t8_default_scheme_hex> ();
builder.add_eclass_scheme<t8_default_scheme_tet> ();
builder.add_eclass_scheme<t8_default_scheme_prism> ();
builder.add_eclass_scheme<t8_default_scheme_pyramid> ();
return builder.build_scheme ();
}

Expand Down
4 changes: 2 additions & 2 deletions src/t8_schemes/t8_scheme.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#pragma once

#include <variant>
#include <array>
#include <vector>
#include <t8_refcount.h>
#include <t8_eclass.h>
#include <t8_schemes/t8_default/t8_default.hxx>
Expand Down Expand Up @@ -72,7 +72,7 @@ class t8_scheme {
>;
/* clang-format on */

using scheme_container = std::array<scheme_var, T8_ECLASS_COUNT>; /**< Container type for holding eclass schemes. */
using scheme_container = std::vector<scheme_var>; /**< Container type for holding eclass schemes. */

private:
scheme_container eclass_schemes; /**< The container holding the eclass schemes. */
Expand Down
26 changes: 23 additions & 3 deletions src/t8_schemes/t8_scheme_builder.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,40 @@

#include <t8_schemes/t8_scheme.hxx>

#if T8_ENABLE_DEBUG
// Only needed for a debug print
#include <typeinfo>
#endif // T8_ENABLE_DEBUG

class t8_scheme_builder {
public:
t8_scheme_builder (): scheme (new t8_scheme) {};
~t8_scheme_builder () {};

using scheme_var = t8_scheme::scheme_var;

/** Add a new element class scheme to the scheme.
* \tparam [in] TEclass_Scheme The type of the element class scheme.
* \tparam [in] _Args The types of the arguments to pass to the constructor of the element class scheme.
* \param [in] args The arguments to pass to the constructor of the element class scheme.
* \return The position of the added element class scheme in the scheme.
*/
template <typename TEclass_Scheme, typename... _Args>
void
add_eclass_scheme (t8_eclass_t tree_class, _Args &&...args)
size_t
add_eclass_scheme (_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 with position %li.\n", typeid (TEclass_Scheme).name (),
scheme->eclass_schemes.size ());
#endif // T8_ENABLE_DEBUG
scheme->eclass_schemes.emplace_back (std::in_place_type<TEclass_Scheme>, std::forward<_Args> (args)...);
return scheme->eclass_schemes.size ();
}

/** Build the scheme.
* \return The built scheme.
*/
t8_scheme *
build_scheme () const
{
Expand Down

0 comments on commit 844e683

Please sign in to comment.