X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMDS%2FSMDS_SetIterator.hxx;h=e76ea8ce569927f86030f8701bdb67f93cfe75f4;hb=9a6c1bd34d45e38869069675ab23fc3f958703dd;hp=8c08a737bc17703b28ac1e9217816b8fdaeb9f47;hpb=4ff5bd61540272713e48de1eee75625028c32155;p=modules%2Fsmesh.git diff --git a/src/SMDS/SMDS_SetIterator.hxx b/src/SMDS/SMDS_SetIterator.hxx index 8c08a737b..e76ea8ce5 100644 --- a/src/SMDS/SMDS_SetIterator.hxx +++ b/src/SMDS/SMDS_SetIterator.hxx @@ -1,44 +1,66 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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. // -// 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 +// 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 // Author : Edward AGAPOV (eap) - - +// #ifndef SMDS_SetIterator_HeaderFile #define SMDS_SetIterator_HeaderFile #include "SMDS_Iterator.hxx" /////////////////////////////////////////////////////////////////////////////// -/// specific SMDS_Iterator iterating over abstract set of values like STL containers +/// Accessors to value pointed by iterator +/////////////////////////////////////////////////////////////////////////////// + +namespace SMDS { + + template + struct SimpleAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; } + }; + + template + struct KeyAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; } + }; + + template + struct ValueAccessor { + static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; } + }; +} + +/////////////////////////////////////////////////////////////////////////////// +/// SMDS_Iterator iterating over abstract set of values like STL containers /// /// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE /// /////////////////////////////////////////////////////////////////////////////// -template +template > class SMDS_SetIterator : public SMDS_Iterator { protected: @@ -57,11 +79,67 @@ public: virtual bool more() { return _beg != _end; } /// Return the current object and step to the next one - virtual VALUE next() { return static_cast( *_beg++ ); } + virtual VALUE next() { return ACCESOR::value( _beg++ ); } +}; + +/////////////////////////////////////////////////////////////////////////////// +/// map iterators +/////////////////////////////////////////////////////////////////////////////// +#include +/*! + * \brief iterator on values of a map + */ +template +struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator, + SMDS::ValueAccessor > { + typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator, + SMDS::ValueAccessor > parent_type; + SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {} +}; +/*! + * \brief reverse iterator on values of a map + */ +template +struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type, + typename M::const_reverse_iterator, + SMDS::ValueAccessor > { + typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator, + SMDS::ValueAccessor > parent_type; + SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {} +}; +/*! + * \brief iterator on keys of a map + */ +template +struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > { + typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > parent_type; + SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {} +}; +/*! + * \brief reverse iterator on keys of a map + */ +template +struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > { + typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator, + SMDS::KeyAccessor > parent_type; + SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {} }; +/////////////////////////////////////////////////////////////////////////////// // useful specifications +/////////////////////////////////////////////////////////////////////////////// #include