3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.
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>
61 #define PB_ASSOC_STATIC_ASSERT(UNIQUE, E) \
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 \
76 #define PB_ASSOC_CLASS_C_DEC \
85 #define PB_ASSOC_BASE_C_DEC \
95 typename assoc_cntnr_base< \
100 Allocator>::type>::type
102 template<typename Key,
108 struct value_type_adapter : public PB_ASSOC_BASE_C_DEC
112 typedef typename PB_ASSOC_BASE_C_DEC my_base;
114 typedef typename my_base::data_type my_base_data_type;
120 typename my_base::allocator::template rebind<
122 typename my_base_data_type::allocator::template rebind<
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>
134 it_value_type_traits_<
135 typename base_it_key_type<
137 Mapping_Level == 1>::type,
138 typename my_base_data_type::const_key_reference,
141 typename my_base_data_type::data_type,
142 null_data_type>::value,
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>
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>
163 typename my_base_data_type::data_type,
164 null_data_type>::value
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;
179 typename my_base::key_type,
180 typename my_base_data_type::key_type>
184 typename allocator::template rebind<
185 key_type>::other::reference
189 typename allocator::template rebind<
190 key_type>::other::const_reference
194 typename allocator::template rebind<
195 key_type>::other::pointer
199 typename allocator::template rebind<
200 key_type>::other::const_pointer
203 typedef typename my_base_data_type::data_type data_type;
206 typename allocator::template rebind<
207 data_type>::other::reference
211 typename allocator::template rebind<
212 data_type>::other::const_reference
213 const_data_reference;
216 typename allocator::template rebind<
217 data_type>::other::pointer
221 typename allocator::template rebind<
222 data_type>::other::const_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;
237 typename my_base::const_find_iterator,
238 typename my_base_data_type::const_find_iterator,
245 typename my_base::find_iterator,
246 typename my_base_data_type::find_iterator,
253 typename my_base::const_iterator,
254 typename my_base_data_type::const_iterator,
261 typename my_base::iterator,
262 typename my_base_data_type::iterator,
269 mapping_level = mapping_level_imp<
270 typename my_base::given_data_type>::value -1
275 typedef compound_ds_tag ds_category;
284 compound_data_enabled_ms_tag>::type
291 compound_ds_tag>::type
292 effective_base_ds_tag;
294 typedef ds_traits< my_base_data_type> base_data_ds_traits;
299 base_data_ds_traits::erase_can_throw
305 order_preserving_imp<
307 effective_base_ds_tag>::value&&
308 base_data_ds_traits::order_preserving
314 base_data_ds_traits::erase_iterators
319 typename invalidation_guarantee_imp<
321 effective_base_ds_tag>::type,
323 my_base_data_type>::invalidation_guarantee>::type
324 invalidation_guarantee;
329 reverse_iteration_imp<
331 effective_base_ds_tag>::value&&
332 base_data_ds_traits::reverse_iteration
341 typedef typename my_base_data_type::data_pointer erase_imp_ret_t;
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>)
357 extract_key_imp(typename iterator::const_reference r_val, int_to_type<true>)
359 return (r_val.first);
363 extract_key_imp(typename iterator::const_reference r_val, int_to_type<false>)
373 return (std::distance(begin(), end()));
379 return (my_base::max_size());
385 return (size() == 0);
388 inline static const_key_reference
389 extract_key(const_reference r_val)
391 return (extract_key_imp(
393 int_to_type<has_data>()));
397 extract_key(typename iterator::const_reference r_val)
399 return (extract_key_imp(
401 int_to_type<has_data>()));
407 insert(const_reference r_val)
409 typedef std::pair< typename my_base::find_iterator, bool> base_ins_ret;
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())
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())
434 return (const_find_iterator(it, sec_it));
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())
445 typename my_base_data_type::find_iterator sec_it =
446 it->second.find(r_key.second);
448 if (sec_it == it->second.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));
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())
469 if (it->second.find(r_key.second) == it->second.end())
472 it->second.erase(r_key.second);
477 #include <ext/pb_assoc/detail/value_type_adapter/erase_if_pred.hpp>
483 typename my_base::iterator it = my_base::begin();
485 typename my_base::iterator end_it = my_base::end();
489 // Tmp Ami check erase can throw
493 if (it->second.empty() == false)
495 erase_if_pred<Pred> p(prd, it);
497 ersd += it->second.erase_if(p);
509 typename my_base::iterator it = my_base::begin();
511 typename my_base::iterator end_it = my_base::end();
517 inline const_iterator
520 typename my_base::const_iterator it = my_base::begin();
522 while (it != my_base::end()&& it->second.size() == 0)
525 if (it == my_base::end())
528 return (const_iterator(it, my_base::end(), it->second.begin()));
534 typename my_base::iterator it = my_base::begin();
536 while (it != my_base::end()&& it->second.size() == 0)
539 if (it == my_base::end())
542 return (iterator(it, my_base::end(), it->second.begin()));
545 inline const_iterator
548 return (const_iterator(my_base::end(), my_base::end()));
554 return (iterator(my_base::end(), my_base::end()));
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
579 subscript_imp(const_key_reference r_key)
581 return (my_base::subscript_imp(r_key.first)[r_key.second]);
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