1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementation of Salome mesh data structure
24 // File : SMDS_SetIterator.hxx
25 // Created : Feb 27 2006
26 // Author : Edward AGAPOV (eap)
28 #ifndef SMDS_SetIterator_HeaderFile
29 #define SMDS_SetIterator_HeaderFile
31 #include "SMDS_Iterator.hxx"
35 ///////////////////////////////////////////////////////////////////////////////
36 /// Accessors to value pointed by iterator
37 ///////////////////////////////////////////////////////////////////////////////
39 template<typename VALUE,typename VALUE_SET_ITERATOR>
40 struct SimpleAccessor {
41 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
44 template<typename VALUE,typename VALUE_SET_ITERATOR>
46 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
49 template<typename VALUE,typename VALUE_SET_ITERATOR>
50 struct ValueAccessor {
51 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
54 template<typename VALUE,typename VALUE_SET_ITERATOR>
55 struct PointerAccessor {
56 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) &(*it); }
59 ///////////////////////////////////////////////////////////////////////////////
60 /// Filters of value pointed by iterator
61 ///////////////////////////////////////////////////////////////////////////////
63 template <typename VALUE>
64 struct PassAllValueFilter
66 bool operator()(const VALUE& t ) { return true; }
69 template <typename VALUE>
72 bool operator()(const VALUE& t ) { return bool( t ); }
76 ///////////////////////////////////////////////////////////////////////////////
77 /// SMDS_Iterator iterating over abstract set of values like STL containers
79 /// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE
81 ///////////////////////////////////////////////////////////////////////////////
83 template<typename VALUE,
84 typename VALUE_SET_ITERATOR,
85 typename ACCESOR=SMDS::SimpleAccessor<VALUE,VALUE_SET_ITERATOR>,
86 typename VALUE_FILTER=SMDS::PassAllValueFilter<VALUE> >
87 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
90 VALUE_SET_ITERATOR _beg, _end;
93 SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
94 const VALUE_SET_ITERATOR & end,
95 const VALUE_FILTER& filter=VALUE_FILTER())
96 { init ( begin, end, filter ); }
99 virtual void init(const VALUE_SET_ITERATOR & begin,
100 const VALUE_SET_ITERATOR & end,
101 const VALUE_FILTER& filter=VALUE_FILTER())
106 if ( more() && !_filter( ACCESOR::value( _beg )))
109 /// Return true iff there are other object in this iterator
114 /// Return the current object and step to the next one
117 VALUE ret = ACCESOR::value( _beg++ );
118 while ( more() && !_filter( ACCESOR::value( _beg )))
124 ///////////////////////////////////////////////////////////////////////////////
126 ///////////////////////////////////////////////////////////////////////////////
130 * \brief iterator on values of a map
133 struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
134 SMDS::ValueAccessor<typename M::mapped_type,
135 typename M::const_iterator> > {
136 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
137 SMDS::ValueAccessor<typename M::mapped_type,
138 typename M::const_iterator> > parent_type;
139 SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {}
142 * \brief reverse iterator on values of a map
145 struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type,
146 typename M::const_reverse_iterator,
147 SMDS::ValueAccessor<typename M::mapped_type,
148 typename M::const_reverse_iterator> > {
149 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator,
150 SMDS::ValueAccessor<typename M::mapped_type,
151 typename M::const_reverse_iterator> > parent_type;
152 SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
155 * \brief iterator on keys of a map
158 struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
159 SMDS::KeyAccessor<typename M::key_type,
160 typename M::const_iterator> > {
161 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
162 SMDS::KeyAccessor<typename M::key_type,
163 typename M::const_iterator> > parent_type;
164 SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {}
167 * \brief reverse iterator on keys of a map
170 struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
171 SMDS::KeyAccessor<typename M::key_type,
172 typename M::const_iterator> > {
173 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
174 SMDS::KeyAccessor<typename M::key_type,
175 typename M::const_iterator> > parent_type;
176 SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
179 ///////////////////////////////////////////////////////////////////////////////
180 // useful specifications
181 ///////////////////////////////////////////////////////////////////////////////
185 class SMDS_MeshElement;
188 typedef const SMDS_MeshElement* SMDS_pElement;
189 typedef const SMDS_MeshNode* SMDS_pNode;
193 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
194 SMDS_ElementVectorIterator;
197 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
198 SMDS_ElementArrayIterator;
201 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
202 SMDS_NodeVectorElemIterator;
205 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
206 SMDS_NodeArrayElemIterator;
210 typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
211 SMDS_NodeVectorIterator;
214 typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
215 SMDS_NodeArrayIterator;