Updated binary toolchain for kernel 2.4 target (gcc 4.2.4, binutils 2.20.1)
[tomato.git] / tools / brcm / K24 / hndtools-mipsel-uclibc-4.2.4 / mipsel-linux-uclibc / include / c++ / 4.2.4 / ext / pb_ds / detail / map_debug_base.hpp
blobd31a0c2699c0936829c71e8097639259bfea4557
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
42 /**
43 * @file map_debug_base.hpp
44 * Contains a debug-mode base for all maps.
47 #ifndef PB_DS_MAP_DEBUG_BASE_HPP
48 #define PB_DS_MAP_DEBUG_BASE_HPP
50 #ifdef _GLIBCXX_DEBUG
52 #include <list>
53 #include <utility>
54 #include <ext/throw_allocator.h>
55 #include <debug/debug.h>
57 namespace pb_ds
59 namespace detail
62 #define PB_DS_CLASS_T_DEC \
63 template<typename Key, class Eq_Fn, typename Const_Key_Reference>
65 #define PB_DS_CLASS_C_DEC \
66 map_debug_base<Key, Eq_Fn, Const_Key_Reference>
68 template<typename Key, class Eq_Fn, typename Const_Key_Reference>
69 class map_debug_base
71 private:
72 typedef typename std::allocator< Key> key_allocator;
74 typedef typename key_allocator::size_type size_type;
76 typedef Const_Key_Reference const_key_reference;
78 protected:
79 map_debug_base();
81 map_debug_base(const PB_DS_CLASS_C_DEC& other);
83 ~map_debug_base();
85 inline void
86 insert_new(const_key_reference r_key);
88 inline void
89 erase_existing(const_key_reference r_key);
91 void
92 clear();
94 inline void
95 check_key_exists(const_key_reference r_key) const;
97 inline void
98 check_key_does_not_exist(const_key_reference r_key) const;
100 inline void
101 check_size(size_type size) const;
103 void
104 swap(PB_DS_CLASS_C_DEC& other);
106 template<typename Cmp_Fn>
107 void
108 split(const_key_reference, Cmp_Fn, PB_DS_CLASS_C_DEC&);
110 void
111 join(PB_DS_CLASS_C_DEC& other);
113 private:
114 typedef std::list< Key> key_set;
115 typedef typename key_set::iterator key_set_iterator;
116 typedef typename key_set::const_iterator const_key_set_iterator;
118 #ifdef _GLIBCXX_DEBUG
119 void
120 assert_valid() const;
121 #endif
123 const_key_set_iterator
124 find(const_key_reference r_key) const;
126 key_set_iterator
127 find(const_key_reference r_key);
129 key_set m_key_set;
130 Eq_Fn m_eq;
133 PB_DS_CLASS_T_DEC
134 PB_DS_CLASS_C_DEC::
135 map_debug_base()
136 { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
138 PB_DS_CLASS_T_DEC
139 PB_DS_CLASS_C_DEC::
140 map_debug_base(const PB_DS_CLASS_C_DEC& other) : m_key_set(other.m_key_set)
141 { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
143 PB_DS_CLASS_T_DEC
144 PB_DS_CLASS_C_DEC::
145 ~map_debug_base()
146 { _GLIBCXX_DEBUG_ONLY(assert_valid();) }
148 PB_DS_CLASS_T_DEC
149 inline void
150 PB_DS_CLASS_C_DEC::
151 insert_new(const_key_reference r_key)
153 _GLIBCXX_DEBUG_ONLY(assert_valid();)
154 __gnu_cxx::throw_allocator<char> alloc;
155 const double orig_throw_prob = alloc.get_throw_prob();
156 alloc.set_throw_prob(0);
157 if (find(r_key) != m_key_set.end())
159 std::cerr << "insert_new " << r_key << std::endl;
160 abort();
165 m_key_set.push_back(r_key);
167 catch(...)
169 std::cerr << "insert_new 1" << r_key << std::endl;
170 abort();
172 alloc.set_throw_prob(orig_throw_prob);
173 _GLIBCXX_DEBUG_ONLY(assert_valid();)
176 PB_DS_CLASS_T_DEC
177 inline void
178 PB_DS_CLASS_C_DEC::
179 erase_existing(const_key_reference r_key)
181 _GLIBCXX_DEBUG_ONLY(assert_valid();)
182 key_set_iterator it = find(r_key);
183 if (it == m_key_set.end())
185 std::cerr << "erase_existing " << r_key << std::endl;
186 abort();
188 m_key_set.erase(it);
189 _GLIBCXX_DEBUG_ONLY(assert_valid();)
192 PB_DS_CLASS_T_DEC
193 void
194 PB_DS_CLASS_C_DEC::
195 clear()
197 _GLIBCXX_DEBUG_ONLY(assert_valid();)
198 m_key_set.clear();
199 _GLIBCXX_DEBUG_ONLY(assert_valid();)
202 PB_DS_CLASS_T_DEC
203 inline void
204 PB_DS_CLASS_C_DEC::
205 check_key_exists(const_key_reference r_key) const
207 _GLIBCXX_DEBUG_ONLY(assert_valid();)
208 if (find(r_key) == m_key_set.end())
210 std::cerr << "check_key_exists " << r_key << std::endl;
211 abort();
213 _GLIBCXX_DEBUG_ONLY(assert_valid();)
216 PB_DS_CLASS_T_DEC
217 inline void
218 PB_DS_CLASS_C_DEC::
219 check_key_does_not_exist(const_key_reference r_key) const
221 _GLIBCXX_DEBUG_ONLY(assert_valid();)
222 if (find(r_key) != m_key_set.end())
224 std::cerr << "check_key_does_not_exist " << r_key << std::endl;
225 abort();
229 PB_DS_CLASS_T_DEC
230 inline void
231 PB_DS_CLASS_C_DEC::
232 check_size(size_type size) const
234 _GLIBCXX_DEBUG_ONLY(assert_valid();)
235 const size_type key_set_size = m_key_set.size();
236 if (size != key_set_size)
238 std::cerr << "check_size " << size
239 << " " << key_set_size << std::endl;
240 abort();
242 _GLIBCXX_DEBUG_ONLY(assert_valid();)
245 PB_DS_CLASS_T_DEC
246 void
247 PB_DS_CLASS_C_DEC::
248 swap(PB_DS_CLASS_C_DEC& other)
250 _GLIBCXX_DEBUG_ONLY(assert_valid();)
251 m_key_set.swap(other.m_key_set);
252 _GLIBCXX_DEBUG_ONLY(assert_valid();)
255 PB_DS_CLASS_T_DEC
256 typename PB_DS_CLASS_C_DEC::const_key_set_iterator
257 PB_DS_CLASS_C_DEC::
258 find(const_key_reference r_key) const
260 _GLIBCXX_DEBUG_ONLY(assert_valid();)
261 typedef const_key_set_iterator iterator_type;
262 for (iterator_type it = m_key_set.begin(); it != m_key_set.end(); ++it)
263 if (m_eq(*it, r_key))
264 return it;
265 return m_key_set.end();
268 PB_DS_CLASS_T_DEC
269 typename PB_DS_CLASS_C_DEC::key_set_iterator
270 PB_DS_CLASS_C_DEC::
271 find(const_key_reference r_key)
273 _GLIBCXX_DEBUG_ONLY(assert_valid();)
274 key_set_iterator it = m_key_set.begin();
275 while (it != m_key_set.end())
277 if (m_eq(*it, r_key))
278 return it;
279 ++it;
281 return it;
282 _GLIBCXX_DEBUG_ONLY(assert_valid();)
285 #ifdef _GLIBCXX_DEBUG
286 PB_DS_CLASS_T_DEC
287 void
288 PB_DS_CLASS_C_DEC::
289 assert_valid() const
291 const_key_set_iterator prime_it = m_key_set.begin();
292 while (prime_it != m_key_set.end())
294 const_key_set_iterator sec_it = prime_it;
295 ++sec_it;
296 while (sec_it != m_key_set.end())
298 _GLIBCXX_DEBUG_ASSERT(!m_eq(*sec_it, *prime_it));
299 _GLIBCXX_DEBUG_ASSERT(!m_eq(*prime_it, *sec_it));
300 ++sec_it;
302 ++prime_it;
305 #endif
307 PB_DS_CLASS_T_DEC
308 template<typename Cmp_Fn>
309 void
310 PB_DS_CLASS_C_DEC::
311 split(const_key_reference r_key, Cmp_Fn cmp_fn, PB_DS_CLASS_C_DEC& other)
313 __gnu_cxx::throw_allocator<char> alloc;
314 const double orig_throw_prob = alloc.get_throw_prob();
315 alloc.set_throw_prob(0);
316 other.clear();
317 key_set_iterator it = m_key_set.begin();
318 while (it != m_key_set.end())
319 if (cmp_fn(r_key, * it))
321 other.insert_new(*it);
322 it = m_key_set.erase(it);
324 else
325 ++it;
326 alloc.set_throw_prob(orig_throw_prob);
329 PB_DS_CLASS_T_DEC
330 void
331 PB_DS_CLASS_C_DEC::
332 join(PB_DS_CLASS_C_DEC& other)
334 __gnu_cxx::throw_allocator<char> alloc;
335 const double orig_throw_prob = alloc.get_throw_prob();
336 alloc.set_throw_prob(0);
337 key_set_iterator it = other.m_key_set.begin();
338 while (it != other.m_key_set.end())
340 insert_new(*it);
341 it = other.m_key_set.erase(it);
343 _GLIBCXX_DEBUG_ASSERT(other.m_key_set.empty());
344 alloc.set_throw_prob(orig_throw_prob);
347 #undef PB_DS_CLASS_T_DEC
348 #undef PB_DS_CLASS_C_DEC
350 } // namespace detail
351 } // namespace pb_ds
353 #endif
355 #endif