1
/*      Copyright (C) 2004-2007 Garrett A. Kajmowicz
 
 
2
        This file is part of the uClibc++ Library.
 
 
4
        This library is free software; you can redistribute it and/or
 
 
5
        modify it under the terms of the GNU Lesser General Public
 
 
6
        License as published by the Free Software Foundation; either
 
 
7
        version 2.1 of the License, or (at your option) any later version.
 
 
9
        This library is distributed in the hope that it will be useful,
 
 
10
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
11
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
 
12
        Lesser General Public License for more details.
 
 
14
        You should have received a copy of the GNU Lesser General Public
 
 
15
        License along with this library; if not, write to the Free Software
 
 
16
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
26
#include <associative_base>
 
 
29
#ifndef __STD_HEADER_MAP
 
 
30
#define __STD_HEADER_MAP
 
 
32
#pragma GCC visibility push(default)
 
 
37
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class map;
 
 
38
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class multimap;
 
 
41
        //Compare the keys of the two items
 
 
42
/*      template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT 
 
 
43
                __base_map<Key, T, Compare, Allocator>::value_compare : public binary_function<
 
 
44
                        typename map<Key, T, Compare, Allocator>::value_type,
 
 
45
                        typename map<Key, T, Compare, Allocator>::value_type,
 
 
48
                friend class __base_map<Key, T, Compare, Allocator>;
 
 
51
                value_compare(Compare c) : comp(c) { }
 
 
54
                bool operator()(const value_type& x, const value_type& y) const {
 
 
55
                        return comp(x.first, y.first);
 
 
60
//      value_compare value_comp() const;
 
 
64
/* This is the implementation for the map container.  As noted above, it deviates
 
 
65
 * from ISO spec by deriving from a base class in order to reduce code redundancy.
 
 
66
 * More code could be reduced by convirting to virtual functions (thus allowing
 
 
67
 * much of the erase and insert code to be duplicated), but that would deviate from
 
 
68
 * the specifications too much to be worth the risk.
 
 
73
//Implementation of map
 
 
76
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT map
 
 
77
        : public __single_associative<Key, pair<Key, T>, Compare, Allocator>
 
 
79
                //Default value of allocator does not meet C++ standard specs, but it works for this library
 
 
84
        typedef __single_associative<Key, pair<Key, T>, Compare, Allocator>     base;
 
 
85
        typedef T                                                               mapped_type;
 
 
86
        typedef typename base::key_type                                         key_type;
 
 
87
        typedef typename base::value_type                                       value_type;
 
 
88
        typedef typename base::key_compare                                      key_compare;
 
 
89
        typedef typename base::allocator_type                                   allocator_type;
 
 
90
        typedef typename base::reference                                        reference;
 
 
91
        typedef typename base::const_reference                                  const_reference;
 
 
92
        typedef typename base::iterator                                         iterator;
 
 
93
        typedef typename base::const_iterator                                   const_iterator;
 
 
94
        typedef typename base::size_type                                        size_type;
 
 
95
        typedef typename base::difference_type                                  difference_type;
 
 
96
        typedef typename base::pointer                                          pointer;
 
 
97
        typedef typename base::const_pointer                                    const_pointer;
 
 
98
        typedef typename base::reverse_iterator                                 reverse_iterator;
 
 
99
        typedef typename base::const_reverse_iterator                           const_reverse_iterator;
 
 
101
        static const key_type v_t_k(const value_type v){
 
 
105
//      using base::value_compare;
 
 
107
        explicit map(const Compare& comp = Compare(), const Allocator& al = Allocator())
 
 
108
                : base(comp, al, v_t_k) {  }
 
 
110
        template <class InputIterator> map(InputIterator first, InputIterator last,
 
 
111
                const Compare& comp = Compare(), const Allocator& al = Allocator())
 
 
112
                : base(first, last, comp, al, v_t_k) {  }
 
 
114
        map(const map<Key,T,Compare,Allocator>& x) : base(x) {  }
 
 
117
        using base::operator=;
 
 
118
        using base::operator==;
 
 
119
        using base::operator!=;
 
 
131
        using base::max_size;
 
 
135
        using base::lower_bound;
 
 
136
        using base::upper_bound;
 
 
137
        using base::equal_range;
 
 
140
        reference operator[](const key_type& k){
 
 
141
                iterator i = lower_bound(k);
 
 
142
                if (i == end() || base::c(k, i->first)) {
 
 
143
                        i = insert(make_pair(k, T())).first;
 
 
153
//Implementation of multimap
 
 
156
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT multimap
 
 
157
        : public __multi_associative<Key, pair<Key, T>, Compare, Allocator>
 
 
160
                //Default value of allocator does not meet C++ standard specs, but it works for this library
 
 
164
        typedef __multi_associative<Key, pair<Key, T>, Compare, Allocator>      base;
 
 
165
        typedef T                                                               mapped_type;
 
 
166
        typedef typename base::key_type                                         key_type;
 
 
167
        typedef typename base::value_type                                       value_type;
 
 
168
        typedef typename base::key_compare                                      key_compare;
 
 
169
        typedef typename base::allocator_type                                   allocator_type;
 
 
170
        typedef typename base::reference                                        reference;
 
 
171
        typedef typename base::const_reference                                  const_reference;
 
 
172
        typedef typename base::iterator                                         iterator;
 
 
173
        typedef typename base::const_iterator                                   const_iterator;
 
 
174
        typedef typename base::size_type                                        size_type;
 
 
175
        typedef typename base::difference_type                                  difference_type;
 
 
176
        typedef typename base::pointer                                          pointer;
 
 
177
        typedef typename base::const_pointer                                    const_pointer;
 
 
178
        typedef typename base::reverse_iterator                                 reverse_iterator;
 
 
179
        typedef typename base::const_reverse_iterator                           const_reverse_iterator;
 
 
181
        static const key_type v_t_k(const value_type v){
 
 
185
        explicit multimap(const Compare& comp = Compare(), const Allocator& al = Allocator())
 
 
186
                : base(comp, al, v_t_k) {  }
 
 
188
        template <class InputIterator> multimap(InputIterator first, InputIterator last,
 
 
189
                const Compare& comp = Compare(), const Allocator& al = Allocator())
 
 
190
                : base(first, last, comp, al, v_t_k) {  }
 
 
193
        multimap(const multimap<Key,T,Compare,Allocator>& x) : base(x) {  }
 
 
196
        using base::operator=;
 
 
197
        using base::operator==;
 
 
198
        using base::operator!=;
 
 
210
        using base::max_size;
 
 
214
        using base::lower_bound;
 
 
215
        using base::upper_bound;
 
 
216
        using base::equal_range;
 
 
226
/* Non-member functions.  These are at the end because they are not associated with any
 
 
227
   particular class.  These will be implemented as I figure out exactly what all of 
 
 
228
   them are supposed to do, and I have time.
 
 
231
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator< 
 
 
232
                (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
 
 
233
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator!=
 
 
234
                (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
 
 
235
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>
 
 
236
                (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
 
 
237
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>=
 
 
238
                (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
 
 
239
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<=
 
 
240
                (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
 
 
241
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT void swap
 
 
242
                (map<Key,T,Compare,Allocator>& x, map<Key,T,Compare,Allocator>& y);
 
 
245
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator==
 
 
246
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
247
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator< 
 
 
248
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
249
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator!=
 
 
250
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
251
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator> 
 
 
252
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
253
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>=
 
 
254
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
255
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<=
 
 
256
                (const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
 
 
257
        template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT void swap
 
 
258
                (multimap<Key,T,Compare,Allocator>& x, multimap<Key,T,Compare,Allocator>& y);
 
 
262
#pragma GCC visibility pop