Salome HOME
97c4ae9ad871a0169b50f8f9be2e25ab73500622
[modules/smesh.git] / src / SMDS / SMDS_StdIterator.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMDS : implementaion of Salome mesh data structure
23 //
24 // File      : SMDS_StdIterator.hxx
25 // Created   : Fri Feb  5 11:03:46 2010
26 // Author    : Edward AGAPOV (eap)
27
28
29 #ifndef __SMDS_StdIterator_HXX__
30 #define __SMDS_StdIterator_HXX__
31
32
33 ///////////////////////////////////////////////////////////////////////////////
34 /*!
35  * \brief Wrapper over pointer to SMDS_Iterator, like SMDS_ElemIteratorPtr, enabling
36  *   its usage in std-like way: provide operators ++, *,  etc.
37  */
38 ///////////////////////////////////////////////////////////////////////////////
39
40 template<typename VALUE, class PtrSMDSIterator, class EqualVALUE = std::equal_to<VALUE> >
41 class SMDS_StdIterator : public std::iterator< std::input_iterator_tag, VALUE >
42 {
43   VALUE           _value;
44   PtrSMDSIterator _piterator;
45   EqualVALUE      _EqualVALUE;
46
47 public:
48   typedef SMDS_StdIterator<VALUE, PtrSMDSIterator> _Self;
49
50   // constructor to use as return from begin()
51   SMDS_StdIterator( PtrSMDSIterator pItr )
52     : _value( pItr->more() ? (VALUE)(pItr->next()) : 0 ), _piterator(pItr)
53   {}
54   // constructor to use as return from end()
55   SMDS_StdIterator(): _value( 0 )
56   {}
57
58   /// Return the current object
59   VALUE operator*() const
60   { return _value; }
61
62   //  Step to the next one
63   _Self&
64   operator++()
65   { _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return *this; }
66
67   // Test of end
68   bool
69   operator!=(const _Self& __x) const
70   { return !_EqualVALUE( _value, __x._value); }
71
72 };
73
74 #endif