From fea759ff6a70730afc6558ee22088a518e397d79 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Mon, 10 Oct 2016 18:04:45 +0200 Subject: [PATCH] [MeL] Add polymorphic construct to Element class. The existing clone function is a direct copy, but setting different nodes is required. --- MeshLib/Elements/Element.h | 8 ++++++++ MeshLib/Elements/TemplateElement.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h index f7d8b2820d6..d37186059e2 100644 --- a/MeshLib/Elements/Element.h +++ b/MeshLib/Elements/Element.h @@ -172,6 +172,14 @@ public: */ virtual Element* clone() const = 0; + /** + * Constructs a new object polymorphically. This is similar to clone, but + * accepts new nodes and id. + * \pre The length of the \c nodes vector is equal to the derived element's + * total number of nodes. + */ + virtual Element* clone(Node** nodes, std::size_t id) const = 0; + /** * Computes the length / area / volumen of this element. This is automatically * done at initalisation time but can be repeated by calling this function at any time. diff --git a/MeshLib/Elements/TemplateElement.h b/MeshLib/Elements/TemplateElement.h index 822ff3758e9..8335715c4ec 100644 --- a/MeshLib/Elements/TemplateElement.h +++ b/MeshLib/Elements/TemplateElement.h @@ -69,6 +69,12 @@ public: return new TemplateElement(*this); } + /// \copydoc MeshLib::Element::clone(Node*[], std::size_t) + virtual Element* clone(Node** nodes, std::size_t id) const + { + return new TemplateElement(nodes, id); + } + /// Get dimension of the mesh element. unsigned getDimension() const { return dimension; } -- GitLab