-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62faded
commit b3c97fb
Showing
7 changed files
with
278 additions
and
190 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
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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <variant> | ||
#include <vector> | ||
|
||
typedef enum { triangle_eclass, quad_eclass, eclass_count } eclass; | ||
|
||
// Opaque pointer to cast the element type into | ||
typedef struct element element_t; | ||
|
||
// Using CRTP to avoid virtual function calls | ||
template <class Derived_scheme_t> | ||
class Scheme_base { | ||
public: | ||
~Scheme_base () | ||
{ | ||
} | ||
|
||
inline int | ||
get_level (element_t *elem) | ||
{ | ||
// cast derived class into base class to avoid virtual functions | ||
return static_cast<Derived_scheme_t const &> (*this).get_level (elem); | ||
}; | ||
|
||
inline int | ||
get_num_children (element_t *elem) | ||
{ | ||
// cast derived class into base class to avoid virtual functions | ||
return static_cast<Derived_scheme_t const &> (*this).get_num_children (elem); | ||
}; | ||
|
||
inline int | ||
get_num_vertices () | ||
{ | ||
// cast derived class into base class to avoid virtual functions | ||
return static_cast<Derived_scheme_t const &> (*this).get_num_vertices (); | ||
}; | ||
|
||
private: | ||
// This way the derived class and only the derived class can use this constructor. | ||
// This way you get an error when doing: `class triangle_scheme: public scheme_base <quad_scheme>` | ||
Scheme_base () {}; | ||
friend Derived_scheme_t; | ||
}; |
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,79 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <variant> | ||
#include <vector> | ||
#include <example/multilevel/t8_multilevel_concept_base.hxx> | ||
|
||
struct triangle | ||
{ | ||
int level; | ||
int orientation; | ||
}; | ||
|
||
struct quad | ||
{ | ||
int level; | ||
}; | ||
|
||
// inherits from base which is a template for this class | ||
class Triangle_scheme: public Scheme_base<Triangle_scheme> { | ||
public: | ||
Triangle_scheme () {}; | ||
|
||
inline int | ||
get_level (element_t *elem) const | ||
{ | ||
elem_type *tri = (elem_type *) elem; | ||
return tri->level; | ||
}; | ||
|
||
inline int | ||
get_num_children (element_t *elem) const | ||
{ | ||
return 4; | ||
}; | ||
|
||
inline int | ||
get_num_vertices () const | ||
{ | ||
return 3; | ||
}; | ||
|
||
protected: | ||
// When the multilevel class inherits from this it needs to know the element type of this scheme | ||
using elem_type = triangle; | ||
|
||
private: | ||
}; | ||
|
||
// inherits from base which is a template for this class | ||
class Quad_scheme: public Scheme_base<Quad_scheme> { | ||
public: | ||
Quad_scheme () {}; | ||
|
||
inline int | ||
get_level (element_t *elem) const | ||
{ | ||
elem_type *q = (elem_type *) elem; | ||
return q->level; | ||
}; | ||
|
||
int | ||
get_num_children (element_t *elem) const | ||
{ | ||
return 4; | ||
}; | ||
|
||
int | ||
get_num_vertices () const | ||
{ | ||
return 4; | ||
}; | ||
|
||
protected: | ||
// When the multilevel class inherits from this it needs to know the element type of this scheme | ||
using elem_type = quad; | ||
|
||
private: | ||
}; |
Oops, something went wrong.