|
AndroMeta
2.0.0
|
00001 /* 00002 * Copyright 2009-2012 AndroMeta LLC. All rights reserved. 00003 * 00004 * AndroMeta LLC retains all intellectual property and proprietary 00005 * rights to this software and related documentation and any modifications 00006 * thereto. Any use, reproduction, disclosure, or distribution of this 00007 * software and related documentation without an express license agreement 00008 * from AndroMeta LLC is strictly prohibited. 00009 * 00010 */ 00011 00019 #include <map> 00020 #include <ostream> 00021 00022 #ifndef ANDROMETA_M_MULTI_MAP_H 00023 #define ANDROMETA_M_MULTI_MAP_H 00024 00025 namespace Meta{ 00026 00037 template<class Key, class T, class Compare = std::less<Key>, 00038 class Allocator = std::allocator<std::pair<const Key,T> > > 00039 class MMultiMap{ 00040 public: 00041 typedef std::multimap<Key, T, Compare, Allocator> Map_; 00042 00043 typedef typename Map_::iterator iterator; 00044 typedef typename Map_::const_iterator const_iterator; 00045 typedef typename Map_::key_type key_type; 00046 typedef typename Map_::allocator_type allocator_type; 00047 typedef typename Map_::value_type value_type; 00048 typedef typename Map_::key_compare key_compare; 00049 typedef typename Map_::reverse_iterator reverse_iterator; 00050 typedef typename Map_::const_reverse_iterator const_reverse_iterator; 00051 typedef typename Map_::value_compare value_compare; 00052 00053 explicit MMultiMap(const Compare& comp=Compare(), 00054 const Allocator& allocator=Allocator()) 00055 : map_(comp, allocator){ 00056 } 00057 00058 template<class InputIterator> 00059 MMultiMap(InputIterator first, InputIterator last, 00060 const Compare& comp=Compare(), 00061 const Allocator& allocator=Allocator()) 00062 : map_(first, last, comp, allocator){ 00063 } 00064 00065 MMultiMap(const MMultiMap<Key,T,Compare,Allocator>& x) 00066 : map_(x.map_){ 00067 00068 } 00069 00070 virtual ~MMultiMap(){ 00071 00072 } 00073 00074 iterator begin(){ 00075 return map_.begin(); 00076 } 00077 00078 const_iterator begin() const{ 00079 return map_.begin(); 00080 } 00081 00082 void clear(){ 00083 map_.clear(); 00084 } 00085 00086 size_t count(const key_type& x) const{ 00087 return map_.count(x); 00088 } 00089 00090 bool empty() const{ 00091 return map_.empty(); 00092 } 00093 00094 iterator end(){ 00095 return map_.end(); 00096 } 00097 00098 const_iterator end() const{ 00099 return map_.end(); 00100 } 00101 00102 std::pair<iterator,iterator> 00103 equal_range(const key_type& x){ 00104 return map_.equal_range(x); 00105 } 00106 00107 std::pair<const_iterator,const_iterator> 00108 equal_range(const key_type& x) const{ 00109 return map_.equal_range(x); 00110 } 00111 00112 void erase(iterator position){ 00113 map_.erase(position); 00114 } 00115 00116 size_t erase(const key_type& x){ 00117 return map_.erase(x); 00118 } 00119 00120 void erase(iterator first, iterator last){ 00121 map_.erase(first, last); 00122 } 00123 00124 iterator find(const key_type& x){ 00125 return map_.find(x); 00126 } 00127 00128 const_iterator find(const key_type& x) const{ 00129 return map_.find(x); 00130 } 00131 00132 allocator_type get_allocator() const{ 00133 return map_.get_allocator(); 00134 } 00135 00136 allocator_type getAllocator() const{ 00137 return map_.get_allocator(); 00138 } 00139 00140 iterator insert(const value_type& x){ 00141 return map_.insert(x); 00142 } 00143 00144 iterator insert(iterator position, const value_type& x){ 00145 return map_.insert(position, x); 00146 } 00147 00148 template<class InputIterator> 00149 void insert(InputIterator first, InputIterator last){ 00150 map_.insert(first, last); 00151 } 00152 00153 MMultiMap<Key,T,Compare,Allocator>& 00154 add(const Key& k, const T& t){ 00155 map_.insert(std::make_pair(k, t)); 00156 return *this; 00157 } 00158 00159 void merge(const MMultiMap<Key,T,Compare,Allocator>& m){ 00160 map_.insert(m.begin(), m.end()); 00161 } 00162 00163 key_compare key_comp() const{ 00164 return map_.key_comp(); 00165 } 00166 00167 key_compare keyCompare() const{ 00168 return map_.key_comp(); 00169 } 00170 00171 iterator lower_bound(const key_type& x){ 00172 return map_.lower_bound(x); 00173 } 00174 00175 iterator lowerBound(const key_type& x){ 00176 return map_.lower_bound(x); 00177 } 00178 00179 const_iterator lower_bound(const key_type& x) const{ 00180 return map_.lower_bound(x); 00181 } 00182 00183 const_iterator lowerBound(const key_type& x) const{ 00184 return map_.lower_bound(x); 00185 } 00186 00187 size_t max_size() const{ 00188 return map_.max_size(); 00189 } 00190 00191 size_t maxSize() const{ 00192 return map_.max_size(); 00193 } 00194 00195 MMultiMap<Key,T,Compare,Allocator>& 00196 operator=(const MMultiMap<Key,T,Compare,Allocator>& x){ 00197 map_ = x.map_; 00198 return *this; 00199 } 00200 00201 reverse_iterator rbegin(){ 00202 return map_.rbegin(); 00203 } 00204 00205 const_reverse_iterator rbegin() const{ 00206 return map_.rbegin(); 00207 } 00208 00209 reverse_iterator rend(){ 00210 return map_.rend(); 00211 } 00212 00213 const_reverse_iterator rend() const{ 00214 return map_.rend(); 00215 } 00216 00217 size_t size() const{ 00218 return map_.size(); 00219 } 00220 00221 void swap(MMultiMap<Key,T,Compare,Allocator>& m){ 00222 map_.swap(m.map_); 00223 } 00224 00225 iterator upper_bound(const key_type& x){ 00226 return map_.upper_bound(x); 00227 } 00228 00229 iterator upperBound(const key_type& x){ 00230 return map_.upper_bound(x); 00231 } 00232 00233 const_iterator upper_bound(const key_type& x) const{ 00234 return map_.upper_bound(x); 00235 } 00236 00237 const_iterator upperBound(const key_type& x) const{ 00238 return map_.upper_bound(x); 00239 } 00240 00241 value_compare value_comp() const{ 00242 return map_.value_comp(); 00243 } 00244 00245 value_compare valueCompare() const{ 00246 return map_.value_comp(); 00247 } 00248 00249 const Map_& map() const{ 00250 return map_; 00251 } 00252 00253 Map_& map(){ 00254 return map_; 00255 } 00256 00257 private: 00258 Map_ map_; 00259 }; 00260 00261 template <class Key, class T, class Compare, class Allocator> 00262 bool operator==(const MMultiMap<Key,T,Compare,Allocator>& x, 00263 const MMultiMap<Key,T,Compare,Allocator>& y){ 00264 return x.map() == y.map(); 00265 } 00266 00267 template <class Key, class T, class Compare, class Allocator> 00268 bool operator<(const MMultiMap<Key,T,Compare,Allocator>& x, 00269 const MMultiMap<Key,T,Compare,Allocator>& y){ 00270 return x.map() < y.map(); 00271 } 00272 00273 template <class Key, class T, class Compare, class Allocator> 00274 bool operator!=(const MMultiMap<Key,T,Compare,Allocator>& x, 00275 const MMultiMap<Key,T,Compare,Allocator>& y){ 00276 return x.map() != y.map(); 00277 } 00278 00279 template <class Key, class T, class Compare, class Allocator> 00280 bool operator>(const MMultiMap<Key,T,Compare,Allocator>& x, 00281 const MMultiMap<Key,T,Compare,Allocator>& y){ 00282 return x.map() > y.map(); 00283 } 00284 00285 template <class Key, class T, class Compare, class Allocator> 00286 bool operator>=(const MMultiMap<Key,T,Compare,Allocator>& x, 00287 const MMultiMap<Key,T,Compare,Allocator>& y){ 00288 return x.map() >= y.map(); 00289 } 00290 00291 template <class Key, class T, class Compare, class Allocator> 00292 bool operator<=(const MMultiMap<Key,T,Compare,Allocator>& x, 00293 const MMultiMap<Key,T,Compare,Allocator>& y){ 00294 return x.map() <= y.map(); 00295 } 00296 00297 template<typename K, typename T> 00298 std::ostream& operator<<(std::ostream& ostr, const MMultiMap<K,T>& m){ 00299 typename MMultiMap<K,T>::const_iterator itr = m.begin(); 00300 ostr << "["; 00301 while(itr != m.end()){ 00302 if(itr != m.begin()){ 00303 ostr << ", "; 00304 } 00305 ostr << itr->first << ":"; 00306 ostr << itr->second; 00307 ++itr; 00308 } 00309 ostr << "]"; 00310 return ostr; 00311 } 00312 00313 } // end namespace Meta 00314 00315 #endif // ANDROMETA_M_MULTI_MAP_H 00316
1.7.6.1