Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*      Copyright (C) 2004-2007 Garrett A. Kajmowicz
  2.         This file is part of the uClibc++ Library.
  3.  
  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.
  8.  
  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.
  13.  
  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
  17. */
  18.  
  19.  
  20.  
  21. #include <memory>
  22. #include <utility>
  23. #include <iterator>
  24. #include <associative_base>
  25.  
  26.  
  27. #ifndef __STD_HEADER_MAP
  28. #define __STD_HEADER_MAP
  29.  
  30. #pragma GCC visibility push(default)
  31.  
  32. namespace std{
  33.  
  34.  
  35. template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class map;
  36. template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class multimap;
  37.  
  38.  
  39.         //Compare the keys of the two items
  40. /*      template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT
  41.                 __base_map<Key, T, Compare, Allocator>::value_compare : public binary_function<
  42.                         typename map<Key, T, Compare, Allocator>::value_type,
  43.                         typename map<Key, T, Compare, Allocator>::value_type,
  44.                 bool>
  45.         {
  46.                 friend class __base_map<Key, T, Compare, Allocator>;
  47.         protected:
  48.                 Compare comp;
  49.                 value_compare(Compare c) : comp(c) { }
  50.                 ~value_compare() {  }
  51.         public:
  52.                 bool operator()(const value_type& x, const value_type& y) const {
  53.                         return comp(x.first, y.first);
  54.                 }
  55.         };
  56. */
  57.  
  58. //      value_compare value_comp() const;
  59.  
  60.  
  61.  
  62. /* This is the implementation for the map container.  As noted above, it deviates
  63.  * from ISO spec by deriving from a base class in order to reduce code redundancy.
  64.  * More code could be reduced by convirting to virtual functions (thus allowing
  65.  * much of the erase and insert code to be duplicated), but that would deviate from
  66.  * the specifications too much to be worth the risk.
  67.  */
  68.  
  69.  
  70.  
  71. //Implementation of map
  72.  
  73.  
  74. template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT map
  75.         : public __single_associative<Key, pair<Key, T>, Compare, Allocator>
  76. {
  77.                 //Default value of allocator does not meet C++ standard specs, but it works for this library
  78.                 //Deal with it
  79.  
  80. public:
  81.  
  82.         typedef __single_associative<Key, pair<Key, T>, Compare, Allocator>     base;
  83.         typedef T                                                               mapped_type;
  84.         typedef typename base::key_type                                         key_type;
  85.         typedef typename base::value_type                                       value_type;
  86.         typedef typename base::key_compare                                      key_compare;
  87.         typedef typename base::allocator_type                                   allocator_type;
  88.         typedef typename base::reference                                        reference;
  89.         typedef typename base::const_reference                                  const_reference;
  90.         typedef typename base::iterator                                         iterator;
  91.         typedef typename base::const_iterator                                   const_iterator;
  92.         typedef typename base::size_type                                        size_type;
  93.         typedef typename base::difference_type                                  difference_type;
  94.         typedef typename base::pointer                                          pointer;
  95.         typedef typename base::const_pointer                                    const_pointer;
  96.         typedef typename base::reverse_iterator                                 reverse_iterator;
  97.         typedef typename base::const_reverse_iterator                           const_reverse_iterator;
  98.  
  99.         static const key_type v_t_k(const value_type v){
  100.                 return v.first;
  101.         }
  102.  
  103. //      using base::value_compare;
  104.  
  105.         explicit map(const Compare& comp = Compare(), const Allocator& al = Allocator())
  106.                 : base(comp, al, v_t_k) {  }
  107.  
  108.         template <class InputIterator> map(InputIterator first, InputIterator last,
  109.                 const Compare& comp = Compare(), const Allocator& al = Allocator())
  110.                 : base(first, last, comp, al, v_t_k) {  }
  111.  
  112.         map(const map<Key,T,Compare,Allocator>& x) : base(x) {  }
  113.         ~map() {  }
  114.  
  115.         using base::operator=;
  116.         using base::operator==;
  117.         using base::operator!=;
  118.  
  119.         using base::insert;
  120.         using base::erase;
  121.  
  122.         using base::begin;
  123.         using base::end;
  124.         using base::rbegin;
  125.         using base::rend;
  126.  
  127.         using base::empty;
  128.         using base::size;
  129.         using base::max_size;
  130.  
  131.         using base::find;
  132.         using base::count;
  133.         using base::lower_bound;
  134.         using base::upper_bound;
  135.         using base::equal_range;
  136.         using base::swap;
  137.  
  138.         reference operator[](const key_type& k){
  139.                 iterator i = lower_bound(k);
  140.                 if (i == end() || base::c(k, i->first)) {
  141.                         i = insert(make_pair(k, T())).first;
  142.                 }
  143.                 return i->second;
  144.         }
  145.  
  146. protected:
  147.         using base::backing;
  148. };
  149.  
  150.  
  151. //Implementation of multimap
  152.  
  153.  
  154. template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT multimap
  155.         : public __multi_associative<Key, pair<Key, T>, Compare, Allocator>
  156.  
  157. {
  158.                 //Default value of allocator does not meet C++ standard specs, but it works for this library
  159.                 //Deal with it
  160. public:
  161.  
  162.         typedef __multi_associative<Key, pair<Key, T>, Compare, Allocator>      base;
  163.         typedef T                                                               mapped_type;
  164.         typedef typename base::key_type                                         key_type;
  165.         typedef typename base::value_type                                       value_type;
  166.         typedef typename base::key_compare                                      key_compare;
  167.         typedef typename base::allocator_type                                   allocator_type;
  168.         typedef typename base::reference                                        reference;
  169.         typedef typename base::const_reference                                  const_reference;
  170.         typedef typename base::iterator                                         iterator;
  171.         typedef typename base::const_iterator                                   const_iterator;
  172.         typedef typename base::size_type                                        size_type;
  173.         typedef typename base::difference_type                                  difference_type;
  174.         typedef typename base::pointer                                          pointer;
  175.         typedef typename base::const_pointer                                    const_pointer;
  176.         typedef typename base::reverse_iterator                                 reverse_iterator;
  177.         typedef typename base::const_reverse_iterator                           const_reverse_iterator;
  178.  
  179.         static const key_type v_t_k(const value_type v){
  180.                 return v.first;
  181.         }
  182.  
  183.         explicit multimap(const Compare& comp = Compare(), const Allocator& al = Allocator())
  184.                 : base(comp, al, v_t_k) {  }
  185.  
  186.         template <class InputIterator> multimap(InputIterator first, InputIterator last,
  187.                 const Compare& comp = Compare(), const Allocator& al = Allocator())
  188.                 : base(first, last, comp, al, v_t_k) {  }
  189.  
  190.  
  191.         multimap(const multimap<Key,T,Compare,Allocator>& x) : base(x) {  }
  192.         ~multimap() {  }
  193.  
  194.         using base::operator=;
  195.         using base::operator==;
  196.         using base::operator!=;
  197.  
  198.         using base::insert;
  199.         using base::erase;
  200.  
  201.         using base::begin;
  202.         using base::end;
  203.         using base::rbegin;
  204.         using base::rend;
  205.  
  206.         using base::empty;
  207.         using base::size;
  208.         using base::max_size;
  209.  
  210.         using base::find;
  211.         using base::count;
  212.         using base::lower_bound;
  213.         using base::upper_bound;
  214.         using base::equal_range;
  215.         using base::swap;
  216.  
  217. protected:
  218.  
  219.         using base::c;
  220.  
  221. };
  222.  
  223.  
  224. /* Non-member functions.  These are at the end because they are not associated with any
  225.    particular class.  These will be implemented as I figure out exactly what all of
  226.    them are supposed to do, and I have time.
  227.  */
  228.  
  229.         template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<
  230.                 (const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
  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 void swap
  240.                 (map<Key,T,Compare,Allocator>& x, map<Key,T,Compare,Allocator>& y);
  241.  
  242.  
  243.         template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator==
  244.                 (const multimap<Key,T,Compare,Allocator>& x, const multimap<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 void swap
  256.                 (multimap<Key,T,Compare,Allocator>& x, multimap<Key,T,Compare,Allocator>& y);
  257.  
  258. }
  259.  
  260. #pragma GCC visibility pop
  261.  
  262. #endif
  263.  
  264.        
  265.