SALOME - SMESH
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SMDS_SetIterator.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
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)
26 //
27 #ifndef SMDS_SetIterator_HeaderFile
28 #define SMDS_SetIterator_HeaderFile
29 
30 #include "SMDS_Iterator.hxx"
31 
35 
36 namespace SMDS {
37 
38  template<typename VALUE,typename VALUE_SET_ITERATOR>
39  struct SimpleAccessor {
40  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
41  };
42 
43  template<typename VALUE,typename VALUE_SET_ITERATOR>
44  struct KeyAccessor {
45  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
46  };
47 
48  template<typename VALUE,typename VALUE_SET_ITERATOR>
49  struct ValueAccessor {
50  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
51  };
52 }
53 
60 
61 template<typename VALUE,
62  typename VALUE_SET_ITERATOR,
64 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
65 {
66 protected:
67  VALUE_SET_ITERATOR _beg, _end;
68 public:
69  SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
70  const VALUE_SET_ITERATOR & end)
71  { init ( begin, end ); }
72 
74  virtual void init(const VALUE_SET_ITERATOR & begin,
75  const VALUE_SET_ITERATOR & end)
76  { _beg = begin; _end = end; }
77 
79  virtual bool more() { return _beg != _end; }
80 
82  virtual VALUE next() { return ACCESOR::value( _beg++ ); }
83 };
84 
88 
89 #include <map>
93 template<typename M>
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()) {}
101 };
105 template<typename M>
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()) {}
114 };
118 template<typename M>
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()) {}
126 };
130 template<typename M>
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()) {}
138 };
139 
141 // useful specifications
143 
144 #include <vector>
145 
146 class SMDS_MeshElement;
148 
149 typedef const SMDS_MeshElement* SMDS_pElement;
150 typedef const SMDS_MeshNode* SMDS_pNode;
151 
152 // element iterators
153 
156 
157 
160 
161 
164 
165 
168 
169 // node iterators
170 
173 
174 
177 
178 
179 #endif