Debian Codegraph @

src/3rdParty/salomesmesh/inc/SMDS_StdIterator.hxx

raw
1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 : [email protected]
18 //
19
20 // SMESH SMDS : implementation 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
38 {
39 VALUE _value;
40 PtrSMDSIterator _piterator;
41 EqualVALUE _EqualVALUE;
42
43 public:
44 using iterator_category = std::input_iterator_tag;
45 using value_type = VALUE;
46 using difference_type = std::ptrdiff_t;
47 using pointer = value_type*;
48 using reference = value_type&;
49 typedef SMDS_StdIterator<VALUE, PtrSMDSIterator> _Self;
50
51 // constructor to use as return from begin()
52 SMDS_StdIterator( PtrSMDSIterator pItr )
53 : _value( pItr->more() ? (VALUE)(pItr->next()) : 0 ), _piterator(pItr)
54 {}
55 // constructor to use as return from end()
56 SMDS_StdIterator(): _value( 0 )
57 {}
58
59 /// Return the current object
60 VALUE operator*() const
61 { return _value; }
62
63 // Step to the next one
64 _Self&
65 operator++()
66 { _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return *this; }
67
68 // Step to the next one
69 _Self
70 operator++(int)
71 { _Self res = *this; _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return res; }
72
73 // Test of end
74 bool
75 operator!=(const _Self& __x) const
76 { return !_EqualVALUE( _value, __x._value); }
77
78 // Test of equality
79 bool
80 operator==(const _Self& __x) const
81 { return _EqualVALUE( _value, __x._value); }
82
83 };
84
85 #endif