Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / bin_search_tree_ / find_iterators.hpp
blobd6ddadc7a559f6d19f679e35ed9d9762a9267770
1 // -*- C++ -*-
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
40 /**
41 * @file find_iterators.hpp
42 * Contains an implementation class for bin_search_tree_.
45 #define PB_ASSOC_CONST_IT_C_DEC \
46 const_it_< \
47 Is_Forward_Iterator>
49 #define PB_ASSOC_CONST_ODIR_IT_C_DEC \
50 const_it_< \
51 !Is_Forward_Iterator>
53 #define PB_ASSOC_IT_C_DEC \
54 it_< \
55 Is_Forward_Iterator>
57 #define PB_ASSOC_ODIR_IT_C_DEC \
58 it_< \
59 !Is_Forward_Iterator>
61 template<bool Is_Forward_Iterator>
62 class const_it_
65 public:
67 typedef std::bidirectional_iterator_tag iterator_category;
69 typedef typename Allocator::difference_type difference_type;
71 typedef mapped_value_type value_type;
73 typedef mapped_pointer pointer;
75 typedef const_mapped_pointer const_pointer;
77 typedef mapped_reference reference;
79 typedef const_mapped_reference const_reference;
81 public:
83 inline
84 const_it_(const node_pointer p_nd = NULL) : m_p_nd(const_cast<node_pointer>(p_nd))
85 { }
87 inline
88 const_it_(const PB_ASSOC_CONST_ODIR_IT_C_DEC&
89 r_other)
91 : m_p_nd(r_other.m_p_nd)
92 { }
94 inline
95 PB_ASSOC_CONST_IT_C_DEC&
96 operator=(const PB_ASSOC_CONST_IT_C_DEC&
97 r_other)
99 m_p_nd = r_other.m_p_nd;
101 return (*this);
104 inline
105 PB_ASSOC_CONST_IT_C_DEC&
106 operator=(const PB_ASSOC_CONST_ODIR_IT_C_DEC&
107 r_other)
109 m_p_nd = r_other.m_p_nd;
111 return (*this);
114 inline const_pointer
115 operator->() const
117 PB_ASSOC_DBG_ASSERT(m_p_nd != NULL);
119 return (&m_p_nd->m_value);
122 inline const_reference
123 operator*() const
125 PB_ASSOC_DBG_ASSERT(m_p_nd != NULL);
127 return (m_p_nd->m_value);
130 inline bool
131 operator==(const PB_ASSOC_CONST_IT_C_DEC
132 &r_other) const
134 return (m_p_nd == r_other.m_p_nd);
137 inline bool
138 operator==(const PB_ASSOC_CONST_ODIR_IT_C_DEC
139 &r_other) const
141 return (m_p_nd == r_other.m_p_nd);
144 inline bool
145 operator!=(const PB_ASSOC_CONST_IT_C_DEC&
146 r_other) const
148 return (m_p_nd != r_other.m_p_nd);
151 inline bool
152 operator!=(const PB_ASSOC_CONST_ODIR_IT_C_DEC&
153 r_other) const
155 return (m_p_nd != r_other.m_p_nd);
158 inline PB_ASSOC_CONST_IT_C_DEC&
159 operator++()
161 PB_ASSOC_DBG_ASSERT(m_p_nd != NULL);
163 inc(int_to_type<Is_Forward_Iterator>());
165 return (*this);
168 inline PB_ASSOC_CONST_IT_C_DEC
169 operator++(int)
171 PB_ASSOC_CONST_IT_C_DEC
172 ret_it(m_p_nd);
174 operator++();
176 return (ret_it);
179 inline PB_ASSOC_CONST_IT_C_DEC&
180 operator--()
182 dec(int_to_type<Is_Forward_Iterator>());
184 return (*this);
187 inline PB_ASSOC_CONST_IT_C_DEC
188 operator--(int)
190 PB_ASSOC_CONST_IT_C_DEC
191 ret_it(m_p_nd);
193 operator--();
195 return (ret_it);
198 protected:
199 inline void
200 inc(int_to_type<false>)
202 dec(int_to_type<true>());
205 void
206 inc(int_to_type<true>)
208 if (m_p_nd->m_p_right != NULL)
210 m_p_nd = m_p_nd->m_p_right;
212 while (m_p_nd->m_p_left != NULL)
213 m_p_nd = m_p_nd->m_p_left;
215 return;
218 node_pointer p_y = m_p_nd->m_p_parent;
220 while (m_p_nd == p_y->m_p_right)
222 m_p_nd = p_y;
224 p_y = p_y->m_p_parent;
227 if (m_p_nd->m_p_right != p_y)
228 m_p_nd = p_y;
231 inline void
232 dec(int_to_type<false>)
234 inc(int_to_type<true>());
237 void
238 dec(int_to_type<true>)
240 if (m_p_nd->special_dec_check()&&
241 m_p_nd->m_p_parent->m_p_parent == m_p_nd)
243 m_p_nd = m_p_nd->m_p_right;
245 return;
248 if (m_p_nd->m_p_left != NULL)
250 node_pointer p_y = m_p_nd->m_p_left;
252 while (p_y->m_p_right != NULL)
253 p_y = p_y->m_p_right;
255 m_p_nd = p_y;
257 return;
260 node_pointer p_y = m_p_nd->m_p_parent;
262 while (m_p_nd == p_y->m_p_left)
264 m_p_nd = p_y;
266 p_y = p_y->m_p_parent;
270 * This seems to correct an apparent bug in the SGI STL
271 * implementation. */
272 if (m_p_nd->m_p_left != p_y)
273 m_p_nd = p_y;
276 friend class PB_ASSOC_CLASS_C_DEC;
278 public:
279 node_pointer m_p_nd;
282 template<bool Is_Forward_Iterator>
283 class it_ :
284 public PB_ASSOC_CONST_IT_C_DEC
288 public:
290 inline
291 it_(const node_pointer p_nd = NULL) : PB_ASSOC_CONST_IT_C_DEC((node_pointer)p_nd)
294 inline
295 it_(const PB_ASSOC_ODIR_IT_C_DEC&
296 r_other)
298 : PB_ASSOC_CONST_IT_C_DEC(
299 r_other.m_p_nd)
302 inline
303 PB_ASSOC_IT_C_DEC&
304 operator=(const PB_ASSOC_IT_C_DEC&
305 r_other)
307 my_base_it::m_p_nd = r_other.m_p_nd;
309 return (*this);
312 inline
313 PB_ASSOC_IT_C_DEC&
314 operator=(const PB_ASSOC_ODIR_IT_C_DEC&
315 r_other)
317 my_base_it::m_p_nd = r_other.m_p_nd;
319 return (*this);
322 inline pointer
323 operator->()
325 PB_ASSOC_DBG_ASSERT(my_base_it::m_p_nd != NULL);
327 return (&my_base_it::m_p_nd->m_value);
330 inline reference
331 operator*()
333 PB_ASSOC_DBG_ASSERT(my_base_it::m_p_nd != NULL);
335 return (my_base_it::m_p_nd->m_value);
338 inline PB_ASSOC_IT_C_DEC&
339 operator++()
341 PB_ASSOC_CONST_IT_C_DEC::
342 operator++();
344 return (*this);
347 inline PB_ASSOC_IT_C_DEC
348 operator++(int)
350 PB_ASSOC_IT_C_DEC
351 ret_it(my_base_it::m_p_nd);
353 operator++();
355 return (ret_it);
358 inline PB_ASSOC_IT_C_DEC&
359 operator--()
361 PB_ASSOC_CONST_IT_C_DEC::
362 operator--();
364 return (*this);
367 inline PB_ASSOC_IT_C_DEC
368 operator--(int)
370 PB_ASSOC_IT_C_DEC
371 ret_it(my_base_it::m_p_nd);
373 operator--();
375 return (ret_it);
378 protected:
379 typedef PB_ASSOC_CONST_IT_C_DEC my_base_it;
381 friend class PB_ASSOC_CLASS_C_DEC;
384 #undef PB_ASSOC_CONST_IT_C_DEC
386 #undef PB_ASSOC_CONST_ODIR_IT_C_DEC
388 #undef PB_ASSOC_IT_C_DEC
390 #undef PB_ASSOC_ODIR_IT_C_DEC