1 // Copyright (C) 2007-2008 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
22 // SMESH SMDS : implementaion of Salome mesh data structure
23 // File : SMDS_SetIterator.hxx
24 // Created : Mon Feb 27 16:57:43 2006
25 // Author : Edward AGAPOV (eap)
27 #ifndef SMDS_SetIterator_HeaderFile
28 #define SMDS_SetIterator_HeaderFile
30 #include "SMDS_Iterator.hxx"
32 ///////////////////////////////////////////////////////////////////////////////
33 /// Accessors to value pointed by iterator
34 ///////////////////////////////////////////////////////////////////////////////
38 template<typename VALUE,typename VALUE_SET_ITERATOR>
39 struct SimpleAccessor {
40 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
43 template<typename VALUE,typename VALUE_SET_ITERATOR>
45 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
48 template<typename VALUE,typename VALUE_SET_ITERATOR>
49 struct ValueAccessor {
50 static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
54 ///////////////////////////////////////////////////////////////////////////////
55 /// SMDS_Iterator iterating over abstract set of values like STL containers
57 /// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE
59 ///////////////////////////////////////////////////////////////////////////////
61 template<typename VALUE,
62 typename VALUE_SET_ITERATOR,
63 typename ACCESOR=SMDS::SimpleAccessor<VALUE,VALUE_SET_ITERATOR> >
64 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
67 VALUE_SET_ITERATOR _beg, _end;
69 SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
70 const VALUE_SET_ITERATOR & end)
71 { init ( begin, end ); }
74 virtual void init(const VALUE_SET_ITERATOR & begin,
75 const VALUE_SET_ITERATOR & end)
76 { _beg = begin; _end = end; }
78 /// Return true if and only if there are other object in this iterator
79 virtual bool more() { return _beg != _end; }
81 /// Return the current object and step to the next one
82 virtual VALUE next() { return ACCESOR::value( _beg++ ); }
85 ///////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////
91 * \brief iterator on values of a map
94 struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
95 SMDS::ValueAccessor<typename M::mapped_type,
96 typename M::const_iterator> > {
97 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
98 SMDS::ValueAccessor<typename M::mapped_type,
99 typename M::const_iterator> > parent_type;
100 SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {}
103 * \brief reverse iterator on values of a map
106 struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type,
107 typename M::const_reverse_iterator,
108 SMDS::ValueAccessor<typename M::mapped_type,
109 typename M::const_reverse_iterator> > {
110 typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator,
111 SMDS::ValueAccessor<typename M::mapped_type,
112 typename M::const_reverse_iterator> > parent_type;
113 SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
116 * \brief iterator on keys of a map
119 struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
120 SMDS::KeyAccessor<typename M::key_type,
121 typename M::const_iterator> > {
122 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
123 SMDS::KeyAccessor<typename M::key_type,
124 typename M::const_iterator> > parent_type;
125 SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {}
128 * \brief reverse iterator on keys of a map
131 struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
132 SMDS::KeyAccessor<typename M::key_type,
133 typename M::const_iterator> > {
134 typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
135 SMDS::KeyAccessor<typename M::key_type,
136 typename M::const_iterator> > parent_type;
137 SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
140 ///////////////////////////////////////////////////////////////////////////////
141 // useful specifications
142 ///////////////////////////////////////////////////////////////////////////////
146 class SMDS_MeshElement;
149 typedef const SMDS_MeshElement* SMDS_pElement;
150 typedef const SMDS_MeshNode* SMDS_pNode;
154 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
155 SMDS_ElementVectorIterator;
158 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
159 SMDS_ElementArrayIterator;
162 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
163 SMDS_NodeVectorElemIterator;
166 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
167 SMDS_NodeArrayElemIterator;
171 typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
172 SMDS_NodeVectorIterator;
175 typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
176 SMDS_NodeArrayIterator;