From 46f1a33fd2f090da025facf0b62dab3843c2f43e Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 6 Aug 2007 19:52:00 +0000 Subject: [PATCH] make remove() routines safe --- Geo/GModel.cpp | 26 +++++++++++++++++++++++++- Geo/GModel.h | 8 ++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index 2c7ed6def8..c3b1f09c1e 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1,4 +1,4 @@ -// $Id: GModel.cpp,v 1.43 2007-08-03 14:57:09 geuzaine Exp $ +// $Id: GModel.cpp,v 1.44 2007-08-06 19:52:00 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -91,6 +91,30 @@ GVertex * GModel::vertexByTag(int n) const return 0; } +void GModel::remove(GRegion *r) +{ + riter it = std::find(firstRegion(), lastRegion(), r); + if(it != regions.end()) regions.erase(it); +} + +void GModel::remove(GFace *f) +{ + fiter it = std::find(firstFace(), lastFace(), f); + if(it != faces.end()) faces.erase(it); +} + +void GModel::remove(GEdge *e) +{ + eiter it = std::find(firstEdge(), lastEdge(), e); + if(it != edges.end()) edges.erase(it); +} + +void GModel::remove(GVertex *v) +{ + viter it = std::find(firstVertex(), lastVertex(), v); + if(it != vertices.end()) vertices.erase(it); +} + template <class T> static void removeInvisible(std::vector<T*> &elements, bool all) { diff --git a/Geo/GModel.h b/Geo/GModel.h index bc5e504c2b..863e31c467 100644 --- a/Geo/GModel.h +++ b/Geo/GModel.h @@ -95,10 +95,10 @@ class GModel void add(GEdge *e) { edges.insert(e); } void add(GVertex *v) { vertices.insert(v); } - void remove(GRegion *r) { regions.erase(std::find(firstRegion(), lastRegion(), r)); } - void remove(GFace *f) { faces.erase(std::find(firstFace(), lastFace(), f)); } - void remove(GEdge *e) { edges.erase(std::find(firstEdge(), lastEdge(), e)); } - void remove(GVertex *v) { vertices.erase(std::find(firstVertex(), lastVertex(), v)); } + void remove(GRegion *r); + void remove(GFace *f); + void remove(GEdge *e); + void remove(GVertex *v); // loop over all vertices connected to elements and associate geo entity void associateEntityWithVertices(); -- GitLab