From: jrt Date: Wed, 3 Sep 2003 17:21:40 +0000 (+0000) Subject: Add iterator classes X-Git-Tag: V1_2_2~41 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=ec6221e48c7b7c6ee6e11008d57d0bfc0dd41992 Add iterator classes --- diff --git a/src/SMDS/SMDS_Iterator.hxx b/src/SMDS/SMDS_Iterator.hxx new file mode 100644 index 000000000..144f075d1 --- /dev/null +++ b/src/SMDS/SMDS_Iterator.hxx @@ -0,0 +1,42 @@ +// SMESH SMDS : implementaion of Salome mesh data structure +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + +#ifndef _SMDS_Iterator_HeaderFile +#define _SMDS_Iterator_HeaderFile + +/////////////////////////////////////////////////////////////////////////////// +///Abstract class for iterators +///@author Jerome Robert +/////////////////////////////////////////////////////////////////////////////// +template class SMDS_Iterator +{ + public: + /// Return true if and only if there are other object in this iterator + virtual bool more()=0; + + /// Return the current object and step to the next one + virtual VALUE next()=0; + + /// Delete the current element and step to the next one + virtual void remove(){}; +}; + +#endif diff --git a/src/SMDS/SMDS_IteratorOfElements.cxx b/src/SMDS/SMDS_IteratorOfElements.cxx new file mode 100644 index 000000000..3f1a392fd --- /dev/null +++ b/src/SMDS/SMDS_IteratorOfElements.cxx @@ -0,0 +1,111 @@ +// SMESH SMDS : implementaion of Salome mesh data structure +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + +#include "SMDS_IteratorOfElements.hxx" + +bool SMDS_IteratorOfElements::subMore() +{ + if((t2Iterator==NULL)||(!t2Iterator->more())) + { + if(t1Iterator->more()) + { + if(t2Iterator!=NULL) delete t2Iterator; + t2Iterator=t1Iterator->next()->elementsIterator(myType); + return subMore(); + } + else return false; + } + else return true; +} + +const SMDS_MeshElement * SMDS_IteratorOfElements::subNext() +{ + if((t2Iterator==NULL)||(!t2Iterator->more())) + { + if(t1Iterator->more()) + { + if(t2Iterator!=NULL) delete t2Iterator; + t2Iterator=t1Iterator->next()->elementsIterator(myType); + } + } + return t2Iterator->next(); +} + +///////////////////////////////////////////////////////////////////////////// +/// Create an iterator which look for elements of type type which are linked +/// to the element element. it is the iterator to get connectivity of element +////////////////////////////////////////////////////////////////////////////// +SMDS_IteratorOfElements::SMDS_IteratorOfElements(const SMDS_MeshElement * element, + SMDSAbs_ElementType type, SMDS_Iterator* it) + :t1Iterator(it), t2Iterator(NULL), myType(type), myElement(element), + myProxyElement(NULL) +{ + while(subMore()) + alreadyReturnedElements.insert(subNext()); + itAlreadyReturned= alreadyReturnedElements.begin(); + switch(myElement->GetType()) + { + case SMDSAbs_Node: + case SMDSAbs_Edge: myReverseIteration=true; break; + case SMDSAbs_Face: myReverseIteration=(type==SMDSAbs_Volume); break; + default: myReverseIteration=false; + } +} + +bool SMDS_IteratorOfElements::more() +{ + if(myProxyElement==NULL) + { + while(itAlreadyReturned!=alreadyReturnedElements.end()) + { + myProxyElement=*itAlreadyReturned; + itAlreadyReturned++; + + if(myReverseIteration) + { + SMDS_Iterator * it= + myProxyElement->elementsIterator(myElement->GetType()); + while(it->more()) + { + if(it->next()==myElement) return true; + } + } + else return true; + } + myProxyElement=NULL; + return false; + } + else return true; +} + +const SMDS_MeshElement * SMDS_IteratorOfElements::next() +{ + more(); + const SMDS_MeshElement *e=myProxyElement; + myProxyElement=NULL; + return e; +} + +SMDS_IteratorOfElements::~SMDS_IteratorOfElements() +{ + delete t1Iterator; + if(t2Iterator!=NULL) delete t2Iterator; +} diff --git a/src/SMDS/SMDS_IteratorOfElements.hxx b/src/SMDS/SMDS_IteratorOfElements.hxx new file mode 100644 index 000000000..5d2d3700c --- /dev/null +++ b/src/SMDS/SMDS_IteratorOfElements.hxx @@ -0,0 +1,53 @@ +// SMESH SMDS : implementaion of Salome mesh data structure +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + +#include "SMDS_Iterator.hxx" +#include "SMDS_MeshElement.hxx" +#include + +using namespace std; + +class SMDS_IteratorOfElements:public SMDS_Iterator +{ + public: +///////////////////////////////////////////////////////////////////////////// +/// Create an iterator which look for elements of type type which are linked +/// to the element element. it is the iterator to get connectivity of element +////////////////////////////////////////////////////////////////////////////// + SMDS_IteratorOfElements(const SMDS_MeshElement * element, + SMDSAbs_ElementType type, SMDS_Iterator* it); + bool more(); + const SMDS_MeshElement * next(); + ~SMDS_IteratorOfElements(); + + private: + SMDS_Iterator * t2Iterator; + SMDS_Iterator * t1Iterator; + SMDSAbs_ElementType myType; + const SMDS_MeshElement * myProxyElement; + const SMDS_MeshElement * myElement; + bool myReverseIteration; + + set alreadyReturnedElements; + set::iterator itAlreadyReturned; + bool subMore(); + const SMDS_MeshElement * subNext(); +};