Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / value_type_adapter / value_type_adapter.hpp
blob343d86104029d1b5b2282f3d2ead6a20ea527748
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 value_type_adapter.hpp
42 * Contains an adapter of mapping levels.
45 #ifndef VALUE_TYPE_ADAPTER_HPP
46 #define VALUE_TYPE_ADAPTER_HPP
48 #include <ext/pb_assoc/detail/value_type_adapter/ref_pair.hpp>
49 #include <ext/pb_assoc/detail/assoc_cntnr_base.hpp>
50 #include <ext/pb_assoc/detail/value_type_adapter/invalidation_guarantee_selector.hpp>
51 #include <ext/pb_assoc/detail/type_utils.hpp>
52 #include <utility>
53 #include <algorithm>
55 namespace pb_assoc
58 namespace detail
61 #define PB_ASSOC_STATIC_ASSERT(UNIQUE, E) \
62 typedef \
63 pb_assoc::detail::static_assert_dummy_class< \
64 sizeof(pb_assoc::detail::static_assert<(bool)(E)>)> \
65 UNIQUE##static_assert_type
67 #define PB_ASSOC_CLASS_T_DEC \
68 template< \
69 typename Key, \
70 typename Data, \
71 class DS_Tag, \
72 class Policy_Tl, \
73 class Allocator, \
74 int Mapping_Level>
76 #define PB_ASSOC_CLASS_C_DEC \
77 value_type_adapter< \
78 Key, \
79 Data, \
80 DS_Tag, \
81 Policy_Tl, \
82 Allocator, \
83 Mapping_Level>
85 #define PB_ASSOC_BASE_C_DEC \
86 cond_type< \
87 Mapping_Level != 1, \
88 value_type_adapter< \
89 Key, \
90 Data, \
91 DS_Tag, \
92 Policy_Tl, \
93 Allocator, \
94 Mapping_Level - 1>, \
95 typename assoc_cntnr_base< \
96 Key, \
97 Data, \
98 DS_Tag, \
99 Policy_Tl, \
100 Allocator>::type>::type
102 template<typename Key,
103 typename Data,
104 class DS_Tag,
105 class Policy_Tl,
106 class Allocator,
107 int Mapping_Level>
108 struct value_type_adapter : public PB_ASSOC_BASE_C_DEC
111 private:
112 typedef typename PB_ASSOC_BASE_C_DEC my_base;
114 typedef typename my_base::data_type my_base_data_type;
116 enum
118 same_alloc_type =
119 is_same_type<
120 typename my_base::allocator::template rebind<
121 char>::other,
122 typename my_base_data_type::allocator::template rebind<
123 char>::other>::value
126 PB_ASSOC_STATIC_ASSERT(wrong_level, Mapping_Level > 0);
128 PB_ASSOC_STATIC_ASSERT(must_be_same_alloc, same_alloc_type);
130 #include <ext/pb_assoc/detail/value_type_adapter/value_type_traits.hpp>
131 #include <ext/pb_assoc/detail/value_type_adapter/it_value_type_traits.hpp>
133 typedef
134 it_value_type_traits_<
135 typename base_it_key_type<
136 my_base,
137 Mapping_Level == 1>::type,
138 typename my_base_data_type::const_key_reference,
139 typename cond_type<
140 is_same_type<
141 typename my_base_data_type::data_type,
142 null_data_type>::value,
143 null_data_type,
144 typename my_base_data_type::data_reference>::type,
145 typename my_base_data_type::reference,
146 typename my_base::allocator>
147 it_value_type_traits_t;
149 #include <ext/pb_assoc/detail/value_type_adapter/iterator.hpp>
151 typedef
152 value_type_traits_<
153 typename my_base::key_type,
154 typename my_base_data_type::key_type,
155 typename my_base_data_type::data_type,
156 typename my_base::allocator>
157 value_type_traits_t;
159 enum
161 has_data =
162 !is_same_type<
163 typename my_base_data_type::data_type,
164 null_data_type>::value
167 public:
169 typedef typename Allocator::size_type size_type;
171 typedef typename Allocator::difference_type difference_type;
173 typedef typename my_base::allocator allocator;
175 typedef typename it_value_type_traits_t::key_type it_key_type;
177 typedef
178 std::pair<
179 typename my_base::key_type,
180 typename my_base_data_type::key_type>
181 key_type;
183 typedef
184 typename allocator::template rebind<
185 key_type>::other::reference
186 key_reference;
188 typedef
189 typename allocator::template rebind<
190 key_type>::other::const_reference
191 const_key_reference;
193 typedef
194 typename allocator::template rebind<
195 key_type>::other::pointer
196 key_pointer;
198 typedef
199 typename allocator::template rebind<
200 key_type>::other::const_pointer
201 const_key_pointer;
203 typedef typename my_base_data_type::data_type data_type;
205 typedef
206 typename allocator::template rebind<
207 data_type>::other::reference
208 data_reference;
210 typedef
211 typename allocator::template rebind<
212 data_type>::other::const_reference
213 const_data_reference;
215 typedef
216 typename allocator::template rebind<
217 data_type>::other::pointer
218 data_pointer;
220 typedef
221 typename allocator::template rebind<
222 data_type>::other::const_pointer
223 const_data_pointer;
225 typedef typename value_type_traits_t::value_type value_type;
227 typedef typename value_type_traits_t::reference reference;
229 typedef typename value_type_traits_t::const_reference const_reference;
231 typedef typename value_type_traits_t::pointer pointer;
233 typedef typename value_type_traits_t::const_pointer const_pointer;
235 typedef
236 it_<
237 typename my_base::const_find_iterator,
238 typename my_base_data_type::const_find_iterator,
239 has_data,
240 true>
241 const_find_iterator;
243 typedef
244 it_<
245 typename my_base::find_iterator,
246 typename my_base_data_type::find_iterator,
247 has_data,
248 false>
249 find_iterator;
251 typedef
252 it_<
253 typename my_base::const_iterator,
254 typename my_base_data_type::const_iterator,
255 has_data,
256 true>
257 const_iterator;
259 typedef
260 it_<
261 typename my_base::iterator,
262 typename my_base_data_type::iterator,
263 has_data,
264 false>
265 iterator;
267 enum
269 mapping_level = mapping_level_imp<
270 typename my_base::given_data_type>::value -1
273 // Tmp Ami rebind
275 typedef compound_ds_tag ds_category;
277 typedef
278 typename cond_type<
279 mapping_level == 1,
280 typename cond_type<
281 has_data,
282 data_enabled_ms_tag,
283 basic_ms_tag>::type,
284 compound_data_enabled_ms_tag>::type
285 ms_category;
287 typedef
288 typename cond_type<
289 Mapping_Level == 1,
290 DS_Tag,
291 compound_ds_tag>::type
292 effective_base_ds_tag;
294 typedef ds_traits< my_base_data_type> base_data_ds_traits;
296 enum
298 erase_can_throw =
299 base_data_ds_traits::erase_can_throw
302 enum
304 order_preserving =
305 order_preserving_imp<
306 my_base,
307 effective_base_ds_tag>::value&&
308 base_data_ds_traits::order_preserving
311 enum
313 erase_iterators =
314 base_data_ds_traits::erase_iterators
317 typedef
318 typename ig_sel<
319 typename invalidation_guarantee_imp<
320 my_base,
321 effective_base_ds_tag>::type,
322 typename ds_traits<
323 my_base_data_type>::invalidation_guarantee>::type
324 invalidation_guarantee;
326 enum
328 reverse_iteration =
329 reverse_iteration_imp<
330 my_base,
331 effective_base_ds_tag>::value&&
332 base_data_ds_traits::reverse_iteration
335 enum
337 split_join = false
340 protected:
341 typedef typename my_base_data_type::data_pointer erase_imp_ret_t;
343 private:
344 inline const_key_reference
345 extract_key_imp(const_reference r_val, int_to_type<true>)
347 return (r_val.first);
350 inline const_key_reference
351 extract_key_imp(const_reference r_val, int_to_type<false>)
353 return (r_val);
356 inline it_key_type
357 extract_key_imp(typename iterator::const_reference r_val, int_to_type<true>)
359 return (r_val.first);
362 inline it_key_type
363 extract_key_imp(typename iterator::const_reference r_val, int_to_type<false>)
365 return (r_val);
368 public:
370 inline size_type
371 size() const
373 return (std::distance(begin(), end()));
376 inline size_type
377 max_size() const
379 return (my_base::max_size());
382 inline bool
383 empty() const
385 return (size() == 0);
388 inline static const_key_reference
389 extract_key(const_reference r_val)
391 return (extract_key_imp(
392 r_val,
393 int_to_type<has_data>()));
396 inline it_key_type
397 extract_key(typename iterator::const_reference r_val)
399 return (extract_key_imp(
400 r_val,
401 int_to_type<has_data>()));
404 inline std::pair<
405 find_iterator,
406 bool>
407 insert(const_reference r_val)
409 typedef std::pair< typename my_base::find_iterator, bool> base_ins_ret;
411 // Tmp Ami
414 inline data_reference
415 operator[](const_key_reference r_key)
417 return (subscript_imp(r_key));
420 inline const_find_iterator
421 find(const_key_reference r_key) const
423 typename my_base::const_find_iterator it = my_base::find(r_key.first);
425 if (it == my_base::end())
426 return (end());
428 typename my_base_data_type::const_find_iterator sec_it =
429 it->second.find(r_key.second);
431 if (sec_it == it->second.end())
432 return (end());
434 return (const_find_iterator(it, sec_it));
437 inline find_iterator
438 find(const_key_reference r_key)
440 typename my_base::find_iterator it = my_base::find(r_key.first);
442 if (it == my_base::end())
443 return (end());
445 typename my_base_data_type::find_iterator sec_it =
446 it->second.find(r_key.second);
448 if (sec_it == it->second.end())
449 return (end());
451 return (find_iterator(it, my_base::end(), sec_it));
454 inline const_data_reference
455 operator[](const_key_reference r_key) const
457 return (my_base::operator[](r_key.first).operator[](r_key.second));
460 inline size_type
461 erase(const_key_reference r_key)
463 typename my_base::find_iterator it =
464 my_base::find(r_key.first);
466 if (it == my_base::end())
467 return (0);
469 if (it->second.find(r_key.second) == it->second.end())
470 return (0);
472 it->second.erase(r_key.second);
474 return (1);
477 #include <ext/pb_assoc/detail/value_type_adapter/erase_if_pred.hpp>
479 template<class Pred>
480 inline size_type
481 erase_if(Pred prd)
483 typename my_base::iterator it = my_base::begin();
485 typename my_base::iterator end_it = my_base::end();
487 size_type ersd = 0;
489 // Tmp Ami check erase can throw
491 while (it != end_it)
493 if (it->second.empty() == false)
495 erase_if_pred<Pred> p(prd, it);
497 ersd += it->second.erase_if(p);
500 ++it;
503 return (ersd);
506 void
507 clear()
509 typename my_base::iterator it = my_base::begin();
511 typename my_base::iterator end_it = my_base::end();
513 while (it != end_it)
514 it->second.clear();
517 inline const_iterator
518 begin() const
520 typename my_base::const_iterator it = my_base::begin();
522 while (it != my_base::end()&& it->second.size() == 0)
523 ++it;
525 if (it == my_base::end())
526 return (end());
528 return (const_iterator(it, my_base::end(), it->second.begin()));
531 inline iterator
532 begin()
534 typename my_base::iterator it = my_base::begin();
536 while (it != my_base::end()&& it->second.size() == 0)
537 ++it;
539 if (it == my_base::end())
540 return (end());
542 return (iterator(it, my_base::end(), it->second.begin()));
545 inline const_iterator
546 end() const
548 return (const_iterator(my_base::end(), my_base::end()));
551 inline iterator
552 end()
554 return (iterator(my_base::end(), my_base::end()));
557 protected:
559 virtual
560 ~value_type_adapter()
563 #define PB_ASSOC_CLASS_NAME value_type_adapter
565 #define PB_ASSOC_DIRECT_BASE_C_DEC PB_ASSOC_BASE_C_DEC
567 #define PB_ASSOC_DIRECT_BASE_CAST_C_DEC \
568 typename PB_ASSOC_DIRECT_BASE_C_DEC
570 #include <ext/pb_assoc/detail/constructors_destructor_fn_imps.hpp>
572 #undef PB_ASSOC_CLASS_NAME
574 #undef PB_ASSOC_DIRECT_BASE_C_DEC
576 #undef PB_ASSOC_DIRECT_BASE_CAST_C_DEC
578 data_reference
579 subscript_imp(const_key_reference r_key)
581 return (my_base::subscript_imp(r_key.first)[r_key.second]);
584 private:
585 value_type_adapter&
586 operator=(const value_type_adapter& r_other);
589 #undef PB_ASSOC_CLASS_T_DEC
591 #undef PB_ASSOC_CLASS_C_DEC
593 #undef PB_ASSOC_BASE_C_DEC
595 } // namespace detail
597 } // namespace pb_assoc
599 #endif // #ifndef VALUE_TYPE_ADAPTER_HPP