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