X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_SetIterator.hxx;h=e0b3c8b0888938ca1eafaed263dc8bbb4b69e437;hp=9272b979e422802630f6c8bff4f2e580cca7256b;hb=ccb5e3c25bf204e839c0094f50f543eacedba5e6;hpb=79b1ac2b6df9117f16f11d444b1f165d477a1813 diff --git a/src/SMDS/SMDS_SetIterator.hxx b/src/SMDS/SMDS_SetIterator.hxx index 9272b979e..e0b3c8b08 100644 --- a/src/SMDS/SMDS_SetIterator.hxx +++ b/src/SMDS/SMDS_SetIterator.hxx @@ -1,42 +1,41 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// Copyright (C) 2003-2007 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, or (at your option) any later version. // +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SMESH SMDS : implementaion of Salome mesh data structure // File : SMDS_SetIterator.hxx -// Created : Mon Feb 27 16:57:43 2006 +// Created : Feb 27 2006 // Author : Edward AGAPOV (eap) - - +// #ifndef SMDS_SetIterator_HeaderFile #define SMDS_SetIterator_HeaderFile #include "SMDS_Iterator.hxx" -/////////////////////////////////////////////////////////////////////////////// -/// Accessors to value pointed by iterator -/////////////////////////////////////////////////////////////////////////////// - namespace SMDS { + /////////////////////////////////////////////////////////////////////////////// + /// Accessors to value pointed by iterator + /////////////////////////////////////////////////////////////////////////////// + template struct SimpleAccessor { static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; } @@ -51,6 +50,22 @@ namespace SMDS { struct ValueAccessor { static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; } }; + + /////////////////////////////////////////////////////////////////////////////// + /// Filters of value pointed by iterator + /////////////////////////////////////////////////////////////////////////////// + + template + struct PassAllValueFilter + { + bool operator()(const VALUE& t ) { return true; } + }; + + template + struct NonNullFilter + { + bool operator()(const VALUE& t ) { return bool( t ); } + }; } /////////////////////////////////////////////////////////////////////////////// @@ -62,26 +77,43 @@ namespace SMDS { template > + typename ACCESOR=SMDS::SimpleAccessor, + typename VALUE_FILTER=SMDS::PassAllValueFilter > class SMDS_SetIterator : public SMDS_Iterator { protected: VALUE_SET_ITERATOR _beg, _end; + VALUE_FILTER _filter; public: SMDS_SetIterator(const VALUE_SET_ITERATOR & begin, - const VALUE_SET_ITERATOR & end) - { init ( begin, end ); } + const VALUE_SET_ITERATOR & end, + const VALUE_FILTER& filter=VALUE_FILTER()) + { init ( begin, end, filter ); } /// Initialization virtual void init(const VALUE_SET_ITERATOR & begin, - const VALUE_SET_ITERATOR & end) - { _beg = begin; _end = end; } - - /// Return true if and only if there are other object in this iterator - virtual bool more() { return _beg != _end; } - + const VALUE_SET_ITERATOR & end, + const VALUE_FILTER& filter=VALUE_FILTER()) + { + _beg = begin; + _end = end; + _filter = filter; + if ( more() && !_filter( ACCESOR::value( _beg ))) + next(); + } + /// Return true iff there are other object in this iterator + virtual bool more() + { + return _beg != _end; + } /// Return the current object and step to the next one - virtual VALUE next() { return ACCESOR::value( _beg++ ); } + virtual VALUE next() + { + VALUE ret = ACCESOR::value( _beg++ ); + while ( more() && !_filter( ACCESOR::value( _beg ))) + ++_beg; + return ret; + } }; ///////////////////////////////////////////////////////////////////////////////