00001
00002
00003
00004
00005
00006
00007
00018 #ifndef OSCL_MAP_H_INCLUDED
00019 #define OSCL_MAP_H_INCLUDED
00020
00021 #ifndef OSCL_BASE_H_INCLUDED
00022 #include "oscl_base.h"
00023 #endif
00024
00025 #ifndef OSCL_TREE_H_INCLUDED
00026 #include "oscl_tree.h"
00027 #endif
00028
00029 #define OSCL_DISABLE_WARNING_TRUNCATE_DEBUG_MESSAGE
00030 #include "osclconfig_compiler_warnings.h"
00031
00032 template <class T>
00033 struct Oscl_Less
00034 {
00035 bool operator()(const T& x, const T& y) const
00036 {
00037 return x < y ? true : false ;
00038 }
00039 };
00040
00041 template <class V, class U>
00042 struct Oscl_Select1st
00043 {
00044 const U& operator()(const V& x) const
00045 {
00046 return x.first;
00047 }
00048 };
00049
00060 template < class Key, class T, class Alloc, class Compare = Oscl_Less<Key> >
00061 class Oscl_Map
00062 {
00063
00064 public:
00065 typedef Key key_type;
00066 typedef Compare key_compare;
00067 typedef Oscl_Pair<const Key, T> value_type;
00068 typedef Oscl_Map<Key, T, Alloc, Compare> self;
00069
00070 private:
00071 typedef Oscl_Rb_Tree < key_type, value_type,
00072 Oscl_Select1st<value_type, key_type>,
00073 key_compare, Alloc > rep_type;
00074 rep_type t;
00075
00076 public:
00077 typedef typename rep_type::pointer pointer;
00078 typedef typename rep_type::reference reference;
00079 typedef typename rep_type::const_reference const_reference;
00080 typedef typename rep_type::iterator iterator;
00081 typedef typename rep_type::const_iterator const_iterator;
00082 typedef typename rep_type::size_type size_type;
00083
00084 class value_compare
00085 {
00086 friend class Oscl_Map<Key, T, Alloc, Compare>;
00087 protected :
00088 Compare comp;
00089 value_compare(Compare c) : comp(c) {}
00090 public:
00091 bool operator()(const value_type& x, const value_type& y) const
00092 {
00093 return comp(x.first, y.first);
00094 }
00095 };
00096
00097 public:
00098
00102 Oscl_Map(const Compare& comp = Compare()) : t(comp) {}
00103
00104
00105
00109 Oscl_Map(const self& x) : t(x.t) {}
00113 self& operator=(const self& x)
00114 {
00115 t = x.t;
00116 return *this;
00117 }
00121 key_compare key_comp() const
00122 {
00123 return t.key_comp();
00124 }
00128 value_compare value_comp() const
00129 {
00130 return value_compare(t.key_comp());
00131 }
00135 iterator begin()
00136 {
00137 return t.begin();
00138 }
00142 const_iterator begin() const
00143 {
00144 return t.begin();
00145 }
00149 iterator end()
00150 {
00151 return t.end();
00152 }
00156 const_iterator end() const
00157 {
00158 return t.end();
00159 }
00163 bool empty() const
00164 {
00165 return t.empty();
00166 }
00170 size_type size() const
00171 {
00172 return t.size();
00173 }
00177 size_type max_size() const
00178 {
00179 return t.max_size();
00180 }
00185 T& operator[](const key_type& k)
00186 {
00187 return (*((insert(value_type(k, T()))).first)).second;
00188 }
00189
00190
00191
00192 typedef Oscl_Pair<iterator, bool> pair_iterator_bool;
00196 pair_iterator_bool insert(const value_type& x)
00197 {
00198 return t.insert_unique(x);
00199 }
00203 iterator insert(iterator position, const value_type& x)
00204 {
00205 return t.insert_unique(position, x);
00206 }
00210 void insert(const value_type* first, const value_type* last)
00211 {
00212 t.insert_unique(first, last);
00213 }
00217 void erase(iterator position)
00218 {
00219 t.erase(position);
00220 }
00224 size_type erase(const key_type& x)
00225 {
00226 return t.erase(x);
00227 }
00231 void erase(iterator first, iterator last)
00232 {
00233 t.erase(first, last);
00234 }
00238 void clear()
00239 {
00240 t.clear();
00241 }
00245 iterator find(const key_type& x)
00246 {
00247 return t.find(x);
00248 }
00252 const_iterator find(const key_type& x) const
00253 {
00254 return t.find(x);
00255 }
00259 size_type count(const key_type& x) const
00260 {
00261 return t.count(x);
00262 }
00266 iterator lower_bound(const key_type& x)
00267 {
00268 return t.lower_bound(x);
00269 }
00273 const_iterator lower_bound(const key_type& x) const
00274 {
00275 return t.lower_bound(x);
00276 }
00280 iterator upper_bound(const key_type& x)
00281 {
00282 return t.upper_bound(x);
00283 }
00287 const_iterator upper_bound(const key_type& x) const
00288 {
00289 return t.upper_bound(x);
00290 }
00291 typedef Oscl_Pair<iterator, iterator> pair_iterator_iterator;
00295 pair_iterator_iterator equal_range(const key_type& x)
00296 {
00297 return t.equal_range(x);
00298 }
00299 typedef Oscl_Pair<const_iterator, const_iterator> pair_citerator_citerator;
00303 pair_citerator_citerator equal_range(const key_type& x) const
00304 {
00305 return t.equal_range(x);
00306 }
00307
00308 private:
00309
00310 };
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00328 #endif