1 // Copyright (C) 2007-2013 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.
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 : implementaion 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 ///////////////////////////////////////////////////////////////////////////////
55 /// Filters of value pointed by iterator
56 ///////////////////////////////////////////////////////////////////////////////
58 template <typename VALUE>
59 struct PassAllValueFilter
61 bool operator()(const VALUE& t ) { return true; }
64 template <typename VALUE>
67 bool operator()(const VALUE& t ) { return bool( t ); }
71 ///////////////////////////////////////////////////////////////////////////////
72 /// SMDS_Iterator iterating over abstract set of values like STL containers
74 /// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE
76 ///////////////////////////////////////////////////////////////////////////////
78 template<typename VALUE,
79 typename VALUE_SET_ITERATOR,
80 typename ACCESOR=SMDS::SimpleAccessor<VALUE,VALUE_SET_ITERATOR>,
81 typename VALUE_FILTER=SMDS::PassAllValueFilter<VALUE> >
82 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
85 VALUE_SET_ITERATOR _beg, _end;
88 SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
89 const VALUE_SET_ITERATOR & end,
90 const VALUE_FILTER& filter=VALUE_FILTER())
91 { init ( begin, end, filter ); }
94 virtual void init(const VALUE_SET_ITERATOR & begin,
95 const VALUE_SET_ITERATOR & end,
96 const VALUE_FILTER& filter=VALUE_FILTER())
101 if ( more() && !_filter( ACCESOR::value( _beg )))
104 /// Return true iff there are other object in this iterator
109 /// Return the current object and step to the next one
112 VALUE ret = ACCESOR::value( _beg++ );
113 while ( more() && !_filter( ACCESOR::value( _beg )))
119 ///////////////////////////////////////////////////////////////////////////////
121 ///////////////////////////////////////////////////////////////////////////////
125 * \brief iterator on values of a map
128 struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
129 SMDS::ValueAccessor<typename M::mapped_type,
130 typename M::const_iterator> > {
131 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
132 SMDS::ValueAccessor<typename M::mapped_type,
133 typename M::const_iterator> > parent_type;
134 SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {}
137 * \brief reverse iterator on values of a map
140 struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type,
141 typename M::const_reverse_iterator,
142 SMDS::ValueAccessor<typename M::mapped_type,
143 typename M::const_reverse_iterator> > {
144 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator,
145 SMDS::ValueAccessor<typename M::mapped_type,
146 typename M::const_reverse_iterator> > parent_type;
147 SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
150 * \brief iterator on keys of a map
153 struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
154 SMDS::KeyAccessor<typename M::key_type,
155 typename M::const_iterator> > {
156 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
157 SMDS::KeyAccessor<typename M::key_type,
158 typename M::const_iterator> > parent_type;
159 SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {}
162 * \brief reverse iterator on keys of a map
165 struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
166 SMDS::KeyAccessor<typename M::key_type,
167 typename M::const_iterator> > {
168 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
169 SMDS::KeyAccessor<typename M::key_type,
170 typename M::const_iterator> > parent_type;
171 SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
174 ///////////////////////////////////////////////////////////////////////////////
175 // useful specifications
176 ///////////////////////////////////////////////////////////////////////////////
180 class SMDS_MeshElement;
183 typedef const SMDS_MeshElement* SMDS_pElement;
184 typedef const SMDS_MeshNode* SMDS_pNode;
188 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
189 SMDS_ElementVectorIterator;
192 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
193 SMDS_ElementArrayIterator;
196 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
197 SMDS_NodeVectorElemIterator;
200 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
201 SMDS_NodeArrayElemIterator;
205 typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
206 SMDS_NodeVectorIterator;
209 typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
210 SMDS_NodeArrayIterator;