Version: 8.3.0
SMDS_SetIterator.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 
23 // SMESH SMDS : implementaion of Salome mesh data structure
24 // File : SMDS_SetIterator.hxx
25 // Created : Feb 27 2006
26 // Author : Edward AGAPOV (eap)
27 //
28 #ifndef SMDS_SetIterator_HeaderFile
29 #define SMDS_SetIterator_HeaderFile
30 
31 #include "SMDS_Iterator.hxx"
32 
33 namespace SMDS {
34 
38 
39  template<typename VALUE,typename VALUE_SET_ITERATOR>
40  struct SimpleAccessor {
41  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
42  };
43 
44  template<typename VALUE,typename VALUE_SET_ITERATOR>
45  struct KeyAccessor {
46  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
47  };
48 
49  template<typename VALUE,typename VALUE_SET_ITERATOR>
50  struct ValueAccessor {
51  static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
52  };
53 
57 
58  template <typename VALUE>
60  {
61  bool operator()(const VALUE& t ) { return true; }
62  };
63 
64  template <typename VALUE>
66  {
67  bool operator()(const VALUE& t ) { return bool( t ); }
68  };
69 }
70 
77 
78 template<typename VALUE,
79  typename VALUE_SET_ITERATOR,
81  typename VALUE_FILTER=SMDS::PassAllValueFilter<VALUE> >
82 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
83 {
84 protected:
85  VALUE_SET_ITERATOR _beg, _end;
86  VALUE_FILTER _filter;
87 public:
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 ); }
92 
94  virtual void init(const VALUE_SET_ITERATOR & begin,
95  const VALUE_SET_ITERATOR & end,
96  const VALUE_FILTER& filter=VALUE_FILTER())
97  {
98  _beg = begin;
99  _end = end;
100  _filter = filter;
101  if ( more() && !_filter( ACCESOR::value( _beg )))
102  next();
103  }
105  virtual bool more()
106  {
107  return _beg != _end;
108  }
110  virtual VALUE next()
111  {
112  VALUE ret = ACCESOR::value( _beg++ );
113  while ( more() && !_filter( ACCESOR::value( _beg )))
114  ++_beg;
115  return ret;
116  }
117 };
118 
122 
123 #include <map>
127 template<typename M>
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()) {}
135 };
139 template<typename M>
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()) {}
148 };
152 template<typename M>
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()) {}
160 };
164 template<typename M>
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()) {}
172 };
173 
175 // useful specifications
177 
178 #include <vector>
179 
180 class SMDS_MeshElement;
182 
183 typedef const SMDS_MeshElement* SMDS_pElement;
184 typedef const SMDS_MeshNode* SMDS_pNode;
185 
186 // element iterators
187 
190 
191 
194 
195 
198 
199 
202 
203 // node iterators
204 
207 
208 
211 
212 
213 #endif