Back to index

salome-smesh  6.5.0
SMDS_StdIterator.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SMESH SMDS : implementaion of Salome mesh data structure
00021 // File      : SMDS_StdIterator.hxx
00022 // Created   : Fri Feb  5 11:03:46 2010
00023 // Author    : Edward AGAPOV (eap)
00024 //
00025 #ifndef __SMDS_StdIterator_HXX__
00026 #define __SMDS_StdIterator_HXX__
00027 
00028 
00030 
00034 
00035 
00036 template<typename VALUE, class PtrSMDSIterator, class EqualVALUE = std::equal_to<VALUE> >
00037 class SMDS_StdIterator : public std::iterator< std::input_iterator_tag, VALUE >
00038 {
00039   VALUE           _value;
00040   PtrSMDSIterator _piterator;
00041   EqualVALUE      _EqualVALUE;
00042 
00043 public:
00044   typedef SMDS_StdIterator<VALUE, PtrSMDSIterator> _Self;
00045 
00046   // constructor to use as return from begin()
00047   SMDS_StdIterator( PtrSMDSIterator pItr )
00048     : _value( pItr->more() ? (VALUE)(pItr->next()) : 0 ), _piterator(pItr)
00049   {}
00050   // constructor to use as return from end()
00051   SMDS_StdIterator(): _value( 0 )
00052   {}
00053 
00055   VALUE operator*() const
00056   { return _value; }
00057 
00058   //  Step to the next one
00059   _Self&
00060   operator++()
00061   { _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return *this; }
00062 
00063   //  Step to the next one
00064   _Self
00065   operator++(int)
00066   { _Self res = *this; _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return res; }
00067 
00068   // Test of end
00069   bool
00070   operator!=(const _Self& __x) const
00071   { return !_EqualVALUE( _value, __x._value); }
00072 
00073   // Test of equality
00074   bool
00075   operator==(const _Self& __x) const
00076   { return _EqualVALUE( _value, __x._value); }
00077 
00078 };
00079 
00080 #endif