00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #ifndef OW_MAP_HPP_INCLUDE_GUARD_
00037 #define OW_MAP_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_COWReference.hpp"
00040 #include <map>
00041 #include <functional>
00042
00043
00044 namespace OW_NAMESPACE
00045 {
00046
00047
00048
00049 template<class Key, class T, class Compare > class Map;
00050
00051 template<class Key, class T, class Compare>
00052 inline bool operator==(const Map<Key, T, Compare>& x,
00053 const Map<Key, T, Compare>& y);
00054
00055 template<class Key, class T, class Compare>
00056 inline bool operator<(const Map<Key, T, Compare>& x,
00057 const Map<Key, T, Compare>& y);
00058
00059
00060 template<class Key, class T, class Compare = std::less<Key> > class Map
00061 {
00062 typedef std::map<Key, T, Compare > M;
00063 COWReference<M> m_impl;
00064 public:
00065 typedef typename M::key_type key_type;
00066 typedef typename M::mapped_type mapped_type;
00067 typedef typename M::value_type value_type;
00068 typedef typename M::key_compare key_compare;
00069 typedef typename M::value_compare value_compare;
00070 typedef typename M::pointer pointer;
00071 typedef typename M::const_pointer const_pointer;
00072 typedef typename M::reference reference;
00073 typedef typename M::const_reference const_reference;
00074 typedef typename M::iterator iterator;
00075 typedef typename M::const_iterator const_iterator;
00076 typedef typename M::reverse_iterator reverse_iterator;
00077 typedef typename M::const_reverse_iterator const_reverse_iterator;
00078 typedef typename M::size_type size_type;
00079 typedef typename M::difference_type difference_type;
00080 Map() : m_impl(new M) { }
00081 explicit Map(M* toWrap) : m_impl(toWrap)
00082 { }
00083 explicit Map(const Compare& comp)
00084 : m_impl(new M(comp)) { }
00085 template <class InputIterator>
00086 Map(InputIterator first, InputIterator last) :
00087 m_impl(new M(first, last))
00088 {
00089 }
00090 template <class InputIterator>
00091 Map(InputIterator first, InputIterator last, const Compare& comp) :
00092 m_impl(new M(first, last, comp))
00093 {
00094 }
00095 M* getImpl()
00096 {
00097 return &*m_impl;
00098 }
00099 key_compare key_comp() const
00100 {
00101 return m_impl->key_comp();
00102 }
00103 value_compare value_comp() const
00104 {
00105 return m_impl->value_comp();
00106 }
00107 iterator begin()
00108 {
00109 return m_impl->begin();
00110 }
00111 const_iterator begin() const
00112 {
00113 return m_impl->begin();
00114 }
00115 iterator end()
00116 {
00117 return m_impl->end();
00118 }
00119 const_iterator end() const
00120 {
00121 return m_impl->end();
00122 }
00123 reverse_iterator rbegin()
00124 {
00125 return m_impl->rbegin();
00126 }
00127 const_reverse_iterator rbegin() const
00128 {
00129 return m_impl->rbegin();
00130 }
00131 reverse_iterator rend()
00132 {
00133 return m_impl->rend();
00134 }
00135 const_reverse_iterator rend() const
00136 {
00137 return m_impl->rend();
00138 }
00139 bool empty() const
00140 {
00141 return m_impl->empty();
00142 }
00143 size_type size() const
00144 {
00145 return m_impl->size();
00146 }
00147 size_type max_size() const
00148 {
00149 return m_impl->max_size();
00150 }
00151 T& operator[](const key_type& k)
00152 {
00153 return m_impl->operator[](k);
00154 }
00155 void swap(Map<Key, T, Compare>& x)
00156 {
00157 m_impl.swap(x.m_impl);
00158 }
00159 std::pair<iterator, bool> insert(const value_type& x)
00160 {
00161 return m_impl->insert(x);
00162 }
00163 iterator insert(iterator position, const value_type& x)
00164 {
00165 return m_impl->insert(position, x);
00166 }
00167 template <class InputIterator>
00168 void insert(InputIterator first, InputIterator last)
00169 {
00170 m_impl->insert(first, last);
00171 }
00172 void erase(iterator position)
00173 {
00174 m_impl->erase(position);
00175 }
00176 size_type erase(const key_type& x)
00177 {
00178 return m_impl->erase(x);
00179 }
00180 void erase(iterator first, iterator last)
00181 {
00182 m_impl->erase(first, last);
00183 }
00184 void clear()
00185 {
00186 m_impl->clear();
00187 }
00188 iterator find(const key_type& x)
00189 {
00190 return m_impl->find(x);
00191 }
00192 const_iterator find(const key_type& x) const
00193 {
00194 return m_impl->find(x);
00195 }
00196 size_type count(const key_type& x) const
00197 {
00198 return m_impl->count(x);
00199 }
00200 iterator lower_bound(const key_type& x)
00201 {
00202 return m_impl->lower_bound(x);
00203 }
00204 const_iterator lower_bound(const key_type& x) const
00205 {
00206 return m_impl->lower_bound(x);
00207 }
00208 iterator upper_bound(const key_type& x)
00209 {
00210 return m_impl->upper_bound(x);
00211 }
00212 const_iterator upper_bound(const key_type& x) const
00213 {
00214 return m_impl->upper_bound(x);
00215 }
00216 std::pair<iterator, iterator> equal_range(const key_type& x)
00217 {
00218 return m_impl->equal_range(x);
00219 }
00220 std::pair<const_iterator, const_iterator>
00221 equal_range(const key_type& x) const
00222 {
00223 return m_impl->equal_range(x);
00224 }
00225 friend bool operator== <>(const Map<Key, T, Compare>& x,
00226 const Map<Key, T, Compare>& y);
00227 friend bool operator< <>(const Map<Key, T, Compare>& x,
00228 const Map<Key, T, Compare>& y);
00229 };
00230 template <class Key, class T, class Compare>
00231 std::map<Key, T, Compare>* COWReferenceClone(std::map<Key, T, Compare>* obj)
00232 {
00233 return new std::map<Key, T, Compare>(*obj);
00234 }
00235 template<class Key, class T, class Compare>
00236 inline bool operator==(const Map<Key, T, Compare>& x,
00237 const Map<Key, T, Compare>& y)
00238 {
00239 return *x.m_impl == *y.m_impl;
00240 }
00241 template<class Key, class T, class Compare>
00242 inline bool operator<(const Map<Key, T, Compare>& x,
00243 const Map<Key, T, Compare>& y)
00244 {
00245 return *x.m_impl < *y.m_impl;
00246 }
00247 template <class Key, class T, class Compare>
00248 inline void swap(Map<Key, T, Compare>& x,
00249 Map<Key, T, Compare>& y)
00250 {
00251 x.swap(y);
00252 }
00253
00254 }
00255
00256 #endif