xc
iterator.hpp
Go to the documentation of this file.
1 
7 #ifndef INCLUDE_KDTREE_ITERATOR_HPP
8 #define INCLUDE_KDTREE_ITERATOR_HPP
9 
10 #include <iterator>
11 
12 #include "utility/kdtree++/node.hpp" //Modificado LCPT.
13 
14 namespace kd_tree
15 {
16  template <typename _Val, typename _Ref, typename _Ptr>
17  class _Iterator;
18 
19  template<typename _Val, typename _Ref, typename _Ptr>
20  inline bool
21  operator==(_Iterator<_Val, _Ref, _Ptr> const&,
23 
24  template<typename _Val>
25  inline bool
28 
29  template<typename _Val>
30  inline bool
31  operator==(_Iterator<_Val, _Val&, _Val*> const&,
33 
34  template<typename _Val, typename _Ref, typename _Ptr>
35  inline bool
36  operator!=(_Iterator<_Val, _Ref, _Ptr> const&,
38 
39  template<typename _Val>
40  inline bool
43 
44  template<typename _Val>
45  inline bool
46  operator!=(_Iterator<_Val, _Val&, _Val*> const&,
48 
50  {
51  protected:
52  typedef _Node_base::_Base_const_ptr _Base_const_ptr;
53  _Base_const_ptr _M_node;
54 
55  inline _Base_iterator(_Base_const_ptr const __N = NULL)
56  : _M_node(__N) {}
57  inline _Base_iterator(_Base_iterator const& __THAT)
58  : _M_node(__THAT._M_node) {}
59 
60  inline void
61  _M_increment()
62  {
63  if (_M_node->_M_right)
64  {
65  _M_node = _M_node->_M_right;
66  while (_M_node->_M_left) _M_node = _M_node->_M_left;
67  }
68  else
69  {
70  _Base_const_ptr __p = _M_node->_M_parent;
71  while (__p && _M_node == __p->_M_right)
72  {
73  _M_node = __p;
74  __p = _M_node->_M_parent;
75  }
76  if (__p) // (__p) provide undetermined behavior on end()++ rather
77  // than a seg fault, similar to standard iterator.
78  _M_node = __p;
79  }
80  }
81 
82  inline void
83  _M_decrement()
84  {
85  if (!_M_node->_M_parent) // clearly identify the header node
86  {
87  _M_node = _M_node->_M_right;
88  }
89  else if (_M_node->_M_left)
90  {
91  _Base_const_ptr x = _M_node->_M_left;
92  while (x->_M_right) x = x->_M_right;
93  _M_node = x;
94  }
95  else
96  {
97  _Base_const_ptr __p = _M_node->_M_parent;
98  while (__p && _M_node == __p->_M_left) // see below
99  {
100  _M_node = __p;
101  __p = _M_node->_M_parent;
102  }
103  if (__p) // (__p) provide undetermined behavior on rend()++ rather
104  // than a seg fault, similar to standard iterator.
105  _M_node = __p;
106  }
107  }
108 
109  template <size_t const __K, typename _Val, typename _Acc,
110  typename _Dist, typename _Cmp, typename _Alloc>
111  friend class KDTree;
112  };
113 
114  template <typename _Val, typename _Ref, typename _Ptr>
115  class _Iterator : protected _Base_iterator
116  {
117  public:
118  typedef _Val value_type;
119  typedef _Ref reference;
120  typedef _Ptr pointer;
121  typedef _Iterator<_Val, _Val&, _Val*> iterator;
122  typedef _Iterator<_Val, _Val const&, _Val const*> const_iterator;
123  typedef _Iterator<_Val, _Ref, _Ptr> _Self;
124  typedef _Node<_Val> const* _Link_const_type;
125  typedef std::bidirectional_iterator_tag iterator_category;
126  typedef ptrdiff_t difference_type;
127 
128  inline _Iterator()
129  : _Base_iterator() {}
130  inline _Iterator(_Link_const_type const __N)
131  : _Base_iterator(__N) {}
132  inline _Iterator(iterator const& __THAT)
133  : _Base_iterator(__THAT) {}
134 
135  _Link_const_type get_raw_node() const
136  {
137  return _Link_const_type(_M_node);
138  }
139 
140  reference
141  operator*() const
142  {
143  return _Link_const_type(_M_node)->_M_value;
144  }
145 
146  pointer
147  operator->() const
148  {
149  return &(operator*());
150  }
151 
152  _Self
153  operator++()
154  {
155  _M_increment();
156  return *this;
157  }
158 
159  _Self
160  operator++(int)
161  {
162  _Self ret = *this;
163  _M_increment();
164  return ret;
165  }
166 
167  _Self&
168  operator--()
169  {
170  _M_decrement();
171  return *this;
172  }
173 
174  _Self
175  operator--(int)
176  {
177  _Self ret = *this;
178  _M_decrement();
179  return ret;
180  }
181 
182  friend bool
183  operator== <>(_Iterator<_Val, _Ref, _Ptr> const&,
185 
186  friend bool
187  operator== <>(_Iterator<_Val, const _Val&, const _Val*> const&,
189 
190  friend bool
191  operator== <>(_Iterator<_Val, _Val&, _Val*> const&,
193 
194  friend bool
195  operator!= <>(_Iterator<_Val, _Ref, _Ptr> const&,
197 
198  friend bool
199  operator!= <>(_Iterator<_Val, const _Val&, const _Val*> const&,
201 
202  friend bool
203  operator!= <>(_Iterator<_Val, _Val&, _Val*> const&,
205  };
206 
207  template<typename _Val, typename _Ref, typename _Ptr>
208  inline bool
209  operator==(_Iterator<_Val, _Ref, _Ptr> const& __X,
210  _Iterator<_Val, _Ref, _Ptr> const& __Y)
211  { return __X._M_node == __Y._M_node; }
212 
213  template<typename _Val>
214  inline bool
215  operator==(_Iterator<_Val, const _Val&, const _Val*> const& __X,
217  { return __X._M_node == __Y._M_node; }
218 
219  template<typename _Val>
220  inline bool
221  operator==(_Iterator<_Val, _Val&, _Val*> const& __X,
223  { return __X._M_node == __Y._M_node; }
224 
225  template<typename _Val, typename _Ref, typename _Ptr>
226  inline bool
227  operator!=(_Iterator<_Val, _Ref, _Ptr> const& __X,
228  _Iterator<_Val, _Ref, _Ptr> const& __Y)
229  { return __X._M_node != __Y._M_node; }
230 
231  template<typename _Val>
232  inline bool
233  operator!=(_Iterator<_Val, const _Val&, const _Val*> const& __X,
235  { return __X._M_node != __Y._M_node; }
236 
237  template<typename _Val>
238  inline bool
239  operator!=(_Iterator<_Val, _Val&, _Val*> const& __X,
241  { return __X._M_node != __Y._M_node; }
242 
243 } // namespace kd_tree
244 
245 #endif // include guard
246 
247 /* COPYRIGHT --
248  *
249  * This file is part of libkdtree++, a C++ template KD-Tree sorting container.
250  * libkdtree++ is (c) 2004-2007 Martin F. Krafft <libkdtree@pobox.madduck.net>
251  * and Sylvain Bougerel <sylvain.bougerel.devel@gmail.com> distributed under the
252  * terms of the Artistic License 2.0. See the ./COPYING file in the source tree
253  * root for more information.
254  *
255  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
256  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
257  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
258  */
Definition: iterator.hpp:17
Definition: kdtree.hpp:99
Definition: node.hpp:49
Definition: iterator.hpp:49
Defines interfaces for nodes as used by the KDTree class.
Definition: allocator.hpp:14