99 ///\e |
95 ///\e |
100 |
96 |
101 /// \param _v The initial value of the map. |
97 /// \param _v The initial value of the map. |
102 /// |
98 /// |
103 ConstMap(const T &_v) : v(_v) {} |
99 ConstMap(const T &_v) : v(_v) {} |
104 |
100 |
|
101 ///\e |
105 T operator[](const K&) const { return v; } |
102 T operator[](const K&) const { return v; } |
106 void set(const K&, const T&) {} |
103 |
|
104 ///\e |
|
105 void setAll(const T &t) { |
|
106 v = t; |
|
107 } |
107 |
108 |
108 template<typename T1> |
109 template<typename T1> |
109 struct rebind { |
110 struct rebind { |
110 typedef ConstMap<K, T1> other; |
111 typedef ConstMap<K, T1> other; |
111 }; |
112 }; |
112 |
113 |
113 template<typename T1> |
114 template<typename T1> |
114 ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {} |
115 ConstMap(const ConstMap<K, T1> &, const T &_v) : v(_v) {} |
115 }; |
116 }; |
116 |
117 |
117 ///Returns a \ref ConstMap class |
118 ///Returns a \c ConstMap class |
118 |
119 |
119 ///This function just returns a \ref ConstMap class. |
120 ///This function just returns a \c ConstMap class. |
120 ///\relates ConstMap |
121 ///\relates ConstMap |
121 template<typename K, typename V> |
122 template<typename K, typename V> |
122 inline ConstMap<K, V> constMap(const V &v) { |
123 inline ConstMap<K, V> constMap(const V &v) { |
123 return ConstMap<K, V>(v); |
124 return ConstMap<K, V>(v); |
124 } |
125 } |
125 |
126 |
126 |
127 |
127 //\todo to document later |
|
128 template<typename T, T v> |
128 template<typename T, T v> |
129 struct Const { }; |
129 struct Const { }; |
130 |
130 |
131 //\todo to document later |
131 /// Constant map with inlined constant value. |
|
132 |
|
133 /// This is a readable map which assigns a specified value to each key. |
|
134 /// In other aspects it is equivalent to the \c NullMap. |
132 template<typename K, typename V, V v> |
135 template<typename K, typename V, V v> |
133 class ConstMap<K, Const<V, v> > : public MapBase<K, V> { |
136 class ConstMap<K, Const<V, v> > : public MapBase<K, V> { |
134 public: |
137 public: |
135 typedef MapBase<K, V> Parent; |
138 typedef MapBase<K, V> Parent; |
136 typedef typename Parent::Key Key; |
139 typedef typename Parent::Key Key; |
137 typedef typename Parent::Value Value; |
140 typedef typename Parent::Value Value; |
138 |
141 |
139 ConstMap() { } |
142 ConstMap() { } |
|
143 ///\e |
140 V operator[](const K&) const { return v; } |
144 V operator[](const K&) const { return v; } |
|
145 ///\e |
141 void set(const K&, const V&) { } |
146 void set(const K&, const V&) { } |
142 }; |
147 }; |
143 |
148 |
144 ///Returns a \ref ConstMap class |
149 ///Returns a \c ConstMap class |
145 |
150 |
146 ///This function just returns a \ref ConstMap class. |
151 ///This function just returns a \c ConstMap class with inlined value. |
147 ///\relates ConstMap |
152 ///\relates ConstMap |
148 template<typename K, typename V, V v> |
153 template<typename K, typename V, V v> |
149 inline ConstMap<K, Const<V, v> > constMap() { |
154 inline ConstMap<K, Const<V, v> > constMap() { |
150 return ConstMap<K, Const<V, v> >(); |
155 return ConstMap<K, Const<V, v> >(); |
151 } |
156 } |
152 |
157 |
153 /// \c std::map wrapper |
158 ///Map based on std::map |
154 |
159 |
155 /// This is essentially a wrapper for \c std::map. With addition that |
160 ///This is essentially a wrapper for \c std::map. With addition that |
156 /// you can specify a default value different from \c Value() . |
161 ///you can specify a default value different from \c Value() . |
157 /// |
|
158 /// \todo Provide allocator parameter... |
|
159 template <typename K, typename T, typename Compare = std::less<K> > |
162 template <typename K, typename T, typename Compare = std::less<K> > |
160 class StdMap : public std::map<K, T, Compare> { |
163 class StdMap { |
161 typedef std::map<K, T, Compare> parent; |
164 template <typename K1, typename T1, typename C1> |
162 T v; |
165 friend class StdMap; |
163 typedef typename parent::value_type PairType; |
166 public: |
164 |
167 |
165 public: |
168 typedef True ReferenceMapTag; |
166 ///\e |
169 ///\e |
167 typedef K Key; |
170 typedef K Key; |
168 ///\e |
171 ///\e |
169 typedef T Value; |
172 typedef T Value; |
170 ///\e |
173 ///\e |
171 typedef T& Reference; |
174 typedef T& Reference; |
172 ///\e |
175 ///\e |
173 typedef const T& ConstReference; |
176 typedef const T& ConstReference; |
174 |
177 |
175 |
178 private: |
176 StdMap() : v() {} |
179 |
|
180 typedef std::map<K, T, Compare> Map; |
|
181 Value _value; |
|
182 Map _map; |
|
183 |
|
184 public: |
|
185 |
177 /// Constructor with specified default value |
186 /// Constructor with specified default value |
178 StdMap(const T& _v) : v(_v) {} |
187 StdMap(const T& value = T()) : _value(value) {} |
179 |
|
180 /// \brief Constructs the map from an appropriate std::map. |
|
181 /// |
|
182 /// \warning Inefficient: copies the content of \c m ! |
|
183 StdMap(const parent &m) : parent(m) {} |
|
184 /// \brief Constructs the map from an appropriate std::map, and explicitly |
188 /// \brief Constructs the map from an appropriate std::map, and explicitly |
185 /// specifies a default value. |
189 /// specifies a default value. |
186 /// |
190 template <typename T1, typename Comp1> |
187 /// \warning Inefficient: copies the content of \c m ! |
191 StdMap(const std::map<Key, T1, Comp1> &map, const T& value = T()) |
188 StdMap(const parent &m, const T& _v) : parent(m), v(_v) {} |
192 : _map(map.begin(), map.end()), _value(value) {} |
189 |
193 |
|
194 /// \brief Constructs a map from an other StdMap. |
190 template<typename T1, typename Comp1> |
195 template<typename T1, typename Comp1> |
191 StdMap(const StdMap<Key, T1,Comp1> &m, const T &_v) { |
196 StdMap(const StdMap<Key, T1, Comp1> &c) |
192 //FIXME; |
197 : _map(c._map.begin(), c._map.end()), _value(c._value) {} |
|
198 |
|
199 private: |
|
200 |
|
201 StdMap& operator=(const StdMap&); |
|
202 |
|
203 public: |
|
204 |
|
205 ///\e |
|
206 Reference operator[](const Key &k) { |
|
207 typename Map::iterator it = _map.lower_bound(k); |
|
208 if (it != _map.end() && !_map.key_comp()(k, it->first)) |
|
209 return it->second; |
|
210 else |
|
211 return _map.insert(it, std::make_pair(k, _value))->second; |
193 } |
212 } |
194 |
213 |
195 Reference operator[](const Key &k) { |
214 /// \e |
196 return insert(PairType(k,v)).first -> second; |
215 ConstReference operator[](const Key &k) const { |
|
216 typename Map::const_iterator it = _map.find(k); |
|
217 if (it != _map.end()) |
|
218 return it->second; |
|
219 else |
|
220 return _value; |
197 } |
221 } |
198 |
222 |
199 ConstReference operator[](const Key &k) const { |
223 /// \e |
200 typename parent::iterator i = lower_bound(k); |
224 void set(const Key &k, const T &t) { |
201 if (i == parent::end() || parent::key_comp()(k, (*i).first)) |
225 typename Map::iterator it = _map.lower_bound(k); |
202 return v; |
226 if (it != _map.end() && !_map.key_comp()(k, it->first)) |
203 return (*i).second; |
227 it->second = t; |
|
228 else |
|
229 _map.insert(it, std::make_pair(k, t)); |
204 } |
230 } |
205 void set(const Key &k, const T &t) { |
231 |
206 parent::operator[](k) = t; |
232 /// \e |
207 } |
233 void setAll(const T &t) { |
208 |
234 _value = t; |
209 /// Changes the default value of the map. |
235 _map.clear(); |
210 /// \return Returns the previous default value. |
236 } |
211 /// |
237 |
212 /// \warning The value of some keys (which has already been queried, but |
238 template <typename T1, typename C1 = std::less<T1> > |
213 /// the value has been unchanged from the default) may change! |
|
214 T setDefault(const T &_v) { T old=v; v=_v; return old; } |
|
215 |
|
216 template<typename T1> |
|
217 struct rebind { |
239 struct rebind { |
218 typedef StdMap<Key, T1,Compare> other; |
240 typedef StdMap<Key, T1, C1> other; |
219 }; |
241 }; |
220 }; |
242 }; |
221 |
243 |
222 /// @} |
244 /// @} |
223 |
245 |
275 /// \param k The key |
298 /// \param k The key |
276 /// \return The target of the edge |
299 /// \return The target of the edge |
277 Value operator[](const Key& k) const {return m[k];} |
300 Value operator[](const Key& k) const {return m[k];} |
278 }; |
301 }; |
279 |
302 |
280 ///Returns an \ref ConvertMap class |
303 ///Returns an \c ConvertMap class |
281 |
304 |
282 ///This function just returns an \ref ConvertMap class. |
305 ///This function just returns an \c ConvertMap class. |
283 ///\relates ConvertMap |
306 ///\relates ConvertMap |
284 ///\todo The order of the template parameters are changed. |
|
285 template<typename T, typename M> |
307 template<typename T, typename M> |
286 inline ConvertMap<M, T> convertMap(const M &m) { |
308 inline ConvertMap<M, T> convertMap(const M &m) { |
287 return ConvertMap<M, T>(m); |
309 return ConvertMap<M, T>(m); |
288 } |
310 } |
289 |
311 |
290 ///Simple wrapping of the map |
312 ///Simple wrapping of the map |
291 |
313 |
292 ///This \ref concepts::ReadMap "read only map" returns the simple |
314 ///This \c concepts::ReadMap "read only map" returns the simple |
293 ///wrapping of the given map. Sometimes the reference maps cannot be |
315 ///wrapping of the given map. Sometimes the reference maps cannot be |
294 ///combined with simple read maps. This map adaptor wraps the given |
316 ///combined with simple read maps. This map adaptor wraps the given |
295 ///map to simple read map. |
317 ///map to simple read map. |
296 template<typename M> |
318 template<typename M> |
297 class SimpleMap : public MapBase<typename M::Key, typename M::Value> { |
319 class SimpleMap : public MapBase<typename M::Key, typename M::Value> { |
344 typedef typename Parent::Key Key; |
369 typedef typename Parent::Key Key; |
345 typedef typename Parent::Value Value; |
370 typedef typename Parent::Value Value; |
346 |
371 |
347 ///Constructor |
372 ///Constructor |
348 AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
373 AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
|
374 ///\e |
349 Value operator[](Key k) const {return m1[k]+m2[k];} |
375 Value operator[](Key k) const {return m1[k]+m2[k];} |
350 }; |
376 }; |
351 |
377 |
352 ///Returns an \ref AddMap class |
378 ///Returns an \c AddMap class |
353 |
379 |
354 ///This function just returns an \ref AddMap class. |
380 ///This function just returns an \c AddMap class. |
355 ///\todo How to call these type of functions? |
381 ///\todo How to call these type of functions? |
356 /// |
382 /// |
357 ///\relates AddMap |
383 ///\relates AddMap |
358 ///\todo Wrong scope in Doxygen when \c \\relates is used |
|
359 template<typename M1, typename M2> |
384 template<typename M1, typename M2> |
360 inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) { |
385 inline AddMap<M1, M2> addMap(const M1 &m1,const M2 &m2) { |
361 return AddMap<M1, M2>(m1,m2); |
386 return AddMap<M1, M2>(m1,m2); |
362 } |
387 } |
363 |
388 |
364 ///Shift a map with a constant. |
389 ///Shift a map with a constant. |
365 |
390 |
366 ///This \ref concepts::ReadMap "read only map" returns the sum of the |
391 ///This \c concepts::ReadMap "read only map" returns the sum of the |
367 ///given map and a constant value. |
392 ///given map and a constant value. |
368 ///Its \c Key and \c Value is inherited from \c M. |
393 ///Its \c Key and \c Value is inherited from \c M. |
369 /// |
394 /// |
370 ///Actually, |
395 ///Actually, |
371 ///\code |
396 ///\code |
459 typedef typename Parent::Key Key; |
486 typedef typename Parent::Key Key; |
460 typedef typename Parent::Value Value; |
487 typedef typename Parent::Value Value; |
461 |
488 |
462 ///Constructor |
489 ///Constructor |
463 SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
490 SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
|
491 /// \e |
464 Value operator[](Key k) const {return m1[k]-m2[k];} |
492 Value operator[](Key k) const {return m1[k]-m2[k];} |
465 }; |
493 }; |
466 |
494 |
467 ///Returns a \ref SubMap class |
495 ///Returns a \c SubMap class |
468 |
496 |
469 ///This function just returns a \ref SubMap class. |
497 ///This function just returns a \c SubMap class. |
470 /// |
498 /// |
471 ///\relates SubMap |
499 ///\relates SubMap |
472 template<typename M1, typename M2> |
500 template<typename M1, typename M2> |
473 inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) { |
501 inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) { |
474 return SubMap<M1, M2>(m1, m2); |
502 return SubMap<M1, M2>(m1, m2); |
475 } |
503 } |
476 |
504 |
477 ///Product of two maps |
505 ///Product of two maps |
478 |
506 |
479 ///This \ref concepts::ReadMap "read only map" returns the product of the |
507 ///This \c concepts::ReadMap "read only map" returns the product of the |
480 ///values of the two |
508 ///values of the two |
481 ///given |
509 ///given |
482 ///maps. Its \c Key and \c Value will be inherited from \c M1. |
510 ///maps. Its \c Key and \c Value will be inherited from \c M1. |
483 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
511 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
484 |
512 |
491 typedef typename Parent::Key Key; |
519 typedef typename Parent::Key Key; |
492 typedef typename Parent::Value Value; |
520 typedef typename Parent::Value Value; |
493 |
521 |
494 ///Constructor |
522 ///Constructor |
495 MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
523 MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {}; |
|
524 /// \e |
496 Value operator[](Key k) const {return m1[k]*m2[k];} |
525 Value operator[](Key k) const {return m1[k]*m2[k];} |
497 }; |
526 }; |
498 |
527 |
499 ///Returns a \ref MulMap class |
528 ///Returns a \c MulMap class |
500 |
529 |
501 ///This function just returns a \ref MulMap class. |
530 ///This function just returns a \c MulMap class. |
502 ///\relates MulMap |
531 ///\relates MulMap |
503 template<typename M1, typename M2> |
532 template<typename M1, typename M2> |
504 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { |
533 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { |
505 return MulMap<M1, M2>(m1,m2); |
534 return MulMap<M1, M2>(m1,m2); |
506 } |
535 } |
507 |
536 |
508 ///Scales a maps with a constant. |
537 ///Scales a maps with a constant. |
509 |
538 |
510 ///This \ref concepts::ReadMap "read only map" returns the value of the |
539 ///This \c concepts::ReadMap "read only map" returns the value of the |
511 ///given map multiplied from the left side with a constant value. |
540 ///given map multiplied from the left side with a constant value. |
512 ///Its \c Key and \c Value is inherited from \c M. |
541 ///Its \c Key and \c Value is inherited from \c M. |
513 /// |
542 /// |
514 ///Actually, |
543 ///Actually, |
515 ///\code |
544 ///\code |
670 ///Its \c Key is inherited from \c M1 and its \c Value is \c V. |
702 ///Its \c Key is inherited from \c M1 and its \c Value is \c V. |
671 ///The \c M2::Value and \c M1::Value must be convertible to the corresponding |
703 ///The \c M2::Value and \c M1::Value must be convertible to the corresponding |
672 ///input parameter of \c F and the return type of \c F must be convertible |
704 ///input parameter of \c F and the return type of \c F must be convertible |
673 ///to \c V. |
705 ///to \c V. |
674 ///\todo Check the requirements. |
706 ///\todo Check the requirements. |
675 |
|
676 template<typename M1, typename M2, typename F, |
707 template<typename M1, typename M2, typename F, |
677 typename V = typename F::result_type, |
708 typename V = typename F::result_type> |
678 typename NC = False> |
|
679 class CombineMap : public MapBase<typename M1::Key, V> { |
709 class CombineMap : public MapBase<typename M1::Key, V> { |
680 const M1& m1; |
710 const M1& m1; |
681 const M2& m2; |
711 const M2& m2; |
682 F f; |
712 F f; |
683 public: |
713 public: |
684 typedef MapBase<typename M1::Key, V> Parent; |
714 typedef MapBase<typename M1::Key, V> Parent; |
685 typedef typename Parent::Key Key; |
715 typedef typename Parent::Key Key; |
686 typedef typename Parent::Value Value; |
716 typedef typename Parent::Value Value; |
687 |
717 |
688 ///Constructor |
718 ///Constructor |
689 CombineMap(const M1 &_m1,const M2 &_m2,const F &_f) |
719 CombineMap(const M1 &_m1,const M2 &_m2,const F &_f = F()) |
690 : m1(_m1), m2(_m2), f(_f) {}; |
720 : m1(_m1), m2(_m2), f(_f) {}; |
|
721 /// \e |
691 Value operator[](Key k) const {return f(m1[k],m2[k]);} |
722 Value operator[](Key k) const {return f(m1[k],m2[k]);} |
692 }; |
723 }; |
693 |
724 |
694 ///Returns a \ref CombineMap class |
725 ///Returns a \c CombineMap class |
695 |
726 |
696 ///This function just returns a \ref CombineMap class. |
727 ///This function just returns a \c CombineMap class. |
697 /// |
|
698 ///Only the first template parameter (the value type) must be given. |
|
699 /// |
728 /// |
700 ///For example if \c m1 and \c m2 are both \c double valued maps, then |
729 ///For example if \c m1 and \c m2 are both \c double valued maps, then |
701 ///\code |
730 ///\code |
702 ///combineMap<double>(m1,m2,std::plus<double>) |
731 ///combineMap<double>(m1,m2,std::plus<double>()) |
703 ///\endcode |
732 ///\endcode |
704 ///is equivalent with |
733 ///is equivalent with |
705 ///\code |
734 ///\code |
706 ///addMap(m1,m2) |
735 ///addMap(m1,m2) |
707 ///\endcode |
736 ///\endcode |
|
737 /// |
|
738 ///This function is specialized for adaptable binary function |
|
739 ///classes and c++ functions. |
708 /// |
740 /// |
709 ///\relates CombineMap |
741 ///\relates CombineMap |
710 template<typename M1, typename M2, typename F, typename V> |
742 template<typename M1, typename M2, typename F, typename V> |
711 inline CombineMap<M1, M2, F, V> |
743 inline CombineMap<M1, M2, F, V> |
712 combineMap(const M1& m1,const M2& m2, const F& f) { |
744 combineMap(const M1& m1,const M2& m2, const F& f) { |
812 typedef typename Parent::Key Key; |
847 typedef typename Parent::Key Key; |
813 typedef typename Parent::Value Value; |
848 typedef typename Parent::Value Value; |
814 |
849 |
815 ///Constructor |
850 ///Constructor |
816 AbsMap(const M &_m) : m(_m) {}; |
851 AbsMap(const M &_m) : m(_m) {}; |
|
852 /// \e |
817 Value operator[](Key k) const { |
853 Value operator[](Key k) const { |
818 Value tmp = m[k]; |
854 Value tmp = m[k]; |
819 return tmp >= 0 ? tmp : -tmp; |
855 return tmp >= 0 ? tmp : -tmp; |
820 } |
856 } |
821 |
857 |
822 }; |
858 }; |
823 |
859 |
824 ///Returns a \ref AbsMap class |
860 ///Returns a \c AbsMap class |
825 |
861 |
826 ///This function just returns a \ref AbsMap class. |
862 ///This function just returns a \c AbsMap class. |
827 ///\relates AbsMap |
863 ///\relates AbsMap |
828 template<typename M> |
864 template<typename M> |
829 inline AbsMap<M> absMap(const M &m) { |
865 inline AbsMap<M> absMap(const M &m) { |
830 return AbsMap<M>(m); |
866 return AbsMap<M>(m); |
831 } |
867 } |
832 |
868 |
833 ///Converts an STL style functor to a map |
869 ///Converts an STL style functor to a map |
834 |
870 |
835 ///This \ref concepts::ReadMap "read only map" returns the value |
871 ///This \c concepts::ReadMap "read only map" returns the value |
836 ///of a |
872 ///of a |
837 ///given map. |
873 ///given map. |
838 /// |
874 /// |
839 ///Template parameters \c K and \c V will become its |
875 ///Template parameters \c K and \c V will become its |
840 ///\c Key and \c Value. They must be given explicitely |
876 ///\c Key and \c Value. They must be given explicitely |
841 ///because a functor does not provide such typedefs. |
877 ///because a functor does not provide such typedefs. |
842 /// |
878 /// |
843 ///Parameter \c F is the type of the used functor. |
879 ///Parameter \c F is the type of the used functor. |
844 |
|
845 |
|
846 template<typename F, |
880 template<typename F, |
847 typename K = typename F::argument_type, |
881 typename K = typename F::argument_type, |
848 typename V = typename F::result_type, |
882 typename V = typename F::result_type> |
849 typename NC = False> |
|
850 class FunctorMap : public MapBase<K, V> { |
883 class FunctorMap : public MapBase<K, V> { |
851 F f; |
884 F f; |
852 public: |
885 public: |
853 typedef MapBase<K, V> Parent; |
886 typedef MapBase<K, V> Parent; |
854 typedef typename Parent::Key Key; |
887 typedef typename Parent::Key Key; |
855 typedef typename Parent::Value Value; |
888 typedef typename Parent::Value Value; |
856 |
889 |
857 ///Constructor |
890 ///Constructor |
858 FunctorMap(const F &_f) : f(_f) {} |
891 FunctorMap(const F &_f = F()) : f(_f) {} |
859 |
892 /// \e |
860 Value operator[](Key k) const { return f(k);} |
893 Value operator[](Key k) const { return f(k);} |
861 }; |
894 }; |
862 |
895 |
863 ///Returns a \ref FunctorMap class |
896 ///Returns a \c FunctorMap class |
864 |
897 |
865 ///This function just returns a \ref FunctorMap class. |
898 ///This function just returns a \c FunctorMap class. |
866 /// |
899 /// |
867 ///The third template parameter isn't necessary to be given. |
900 ///It is specialized for adaptable function classes and |
|
901 ///c++ functions. |
868 ///\relates FunctorMap |
902 ///\relates FunctorMap |
869 template<typename K, typename V, typename F> inline |
903 template<typename K, typename V, typename F> inline |
870 FunctorMap<F, K, V> functorMap(const F &f) { |
904 FunctorMap<F, K, V> functorMap(const F &f) { |
871 return FunctorMap<F, K, V>(f); |
905 return FunctorMap<F, K, V>(f); |
872 } |
906 } |
888 |
922 |
889 ///This class Converts a map to an STL style (unary) functor. |
923 ///This class Converts a map to an STL style (unary) functor. |
890 ///that is it provides an <tt>operator()</tt> to read its values. |
924 ///that is it provides an <tt>operator()</tt> to read its values. |
891 /// |
925 /// |
892 ///For the sake of convenience it also works as |
926 ///For the sake of convenience it also works as |
893 ///a ususal \ref concepts::ReadMap "readable map", |
927 ///a ususal \c concepts::ReadMap "readable map", |
894 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. |
928 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. |
895 |
|
896 template <typename M> |
929 template <typename M> |
897 class MapFunctor : public MapBase<typename M::Key, typename M::Value> { |
930 class MapFunctor : public MapBase<typename M::Key, typename M::Value> { |
898 const M& m; |
931 const M& m; |
899 public: |
932 public: |
900 typedef MapBase<typename M::Key, typename M::Value> Parent; |
933 typedef MapBase<typename M::Key, typename M::Value> Parent; |
901 typedef typename Parent::Key Key; |
934 typedef typename Parent::Key Key; |
902 typedef typename Parent::Value Value; |
935 typedef typename Parent::Value Value; |
903 |
936 |
904 ///\e |
|
905 typedef typename M::Key argument_type; |
937 typedef typename M::Key argument_type; |
906 ///\e |
|
907 typedef typename M::Value result_type; |
938 typedef typename M::Value result_type; |
908 |
939 |
909 ///Constructor |
940 ///Constructor |
910 MapFunctor(const M &_m) : m(_m) {}; |
941 MapFunctor(const M &_m) : m(_m) {}; |
911 ///Returns a value of the map |
942 ///\e |
912 Value operator()(Key k) const {return m[k];} |
943 Value operator()(Key k) const {return m[k];} |
913 ///\e |
944 ///\e |
914 Value operator[](Key k) const {return m[k];} |
945 Value operator[](Key k) const {return m[k];} |
915 }; |
946 }; |
916 |
947 |
917 ///Returns a \ref MapFunctor class |
948 ///Returns a \c MapFunctor class |
918 |
949 |
919 ///This function just returns a \ref MapFunctor class. |
950 ///This function just returns a \c MapFunctor class. |
920 ///\relates MapFunctor |
951 ///\relates MapFunctor |
921 template<typename M> |
952 template<typename M> |
922 inline MapFunctor<M> mapFunctor(const M &m) { |
953 inline MapFunctor<M> mapFunctor(const M &m) { |
923 return MapFunctor<M>(m); |
954 return MapFunctor<M>(m); |
924 } |
955 } |
925 |
956 |
926 ///Applies all map setting operations to two maps |
957 ///Applies all map setting operations to two maps |
927 |
958 |
928 ///This map has two \ref concepts::ReadMap "readable map" |
959 ///This map has two \c concepts::ReadMap "readable map" |
929 ///parameters and each read request will be passed just to the |
960 ///parameters and each read request will be passed just to the |
930 ///first map. This class is the just readable map type of the ForkWriteMap. |
961 ///first map. This class is the just readable map type of the ForkWriteMap. |
931 /// |
962 /// |
932 ///The \c Key and \c Value will be inherited from \c M1. |
963 ///The \c Key and \c Value will be inherited from \c M1. |
933 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
964 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
934 |
|
935 template<typename M1, typename M2> |
965 template<typename M1, typename M2> |
936 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { |
966 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { |
937 const M1& m1; |
967 const M1& m1; |
938 const M2& m2; |
968 const M2& m2; |
939 public: |
969 public: |
941 typedef typename Parent::Key Key; |
971 typedef typename Parent::Key Key; |
942 typedef typename Parent::Value Value; |
972 typedef typename Parent::Value Value; |
943 |
973 |
944 ///Constructor |
974 ///Constructor |
945 ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {}; |
975 ForkMap(const M1 &_m1, const M2 &_m2) : m1(_m1), m2(_m2) {}; |
|
976 /// \e |
946 Value operator[](Key k) const {return m1[k];} |
977 Value operator[](Key k) const {return m1[k];} |
947 }; |
978 }; |
948 |
979 |
949 |
980 |
950 ///Applies all map setting operations to two maps |
981 ///Applies all map setting operations to two maps |
951 |
982 |
952 ///This map has two \ref concepts::WriteMap "writable map" |
983 ///This map has two \c concepts::WriteMap "writable map" |
953 ///parameters and each write request will be passed to both of them. |
984 ///parameters and each write request will be passed to both of them. |
954 ///If \c M1 is also \ref concepts::ReadMap "readable", |
985 ///If \c M1 is also \c concepts::ReadMap "readable", |
955 ///then the read operations will return the |
986 ///then the read operations will return the |
956 ///corresponding values of \c M1. |
987 ///corresponding values of \c M1. |
957 /// |
988 /// |
958 ///The \c Key and \c Value will be inherited from \c M1. |
989 ///The \c Key and \c Value will be inherited from \c M1. |
959 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
990 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
960 |
|
961 template<typename M1, typename M2> |
991 template<typename M1, typename M2> |
962 class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> { |
992 class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> { |
963 M1& m1; |
993 M1& m1; |
964 M2& m2; |
994 M2& m2; |
965 public: |
995 public: |
994 |
1024 |
995 /* ************* BOOL MAPS ******************* */ |
1025 /* ************* BOOL MAPS ******************* */ |
996 |
1026 |
997 ///Logical 'not' of a map |
1027 ///Logical 'not' of a map |
998 |
1028 |
999 ///This bool \ref concepts::ReadMap "read only map" returns the |
1029 ///This bool \c concepts::ReadMap "read only map" returns the |
1000 ///logical negation of |
1030 ///logical negation of |
1001 ///value returned by the |
1031 ///value returned by the |
1002 ///given map. Its \c Key and will be inherited from \c M, |
1032 ///given map. Its \c Key and will be inherited from \c M, |
1003 ///its Value is <tt>bool</tt>. |
1033 ///its Value is <tt>bool</tt>. |
1004 |
|
1005 template <typename M> |
1034 template <typename M> |
1006 class NotMap : public MapBase<typename M::Key, bool> { |
1035 class NotMap : public MapBase<typename M::Key, bool> { |
1007 const M& m; |
1036 const M& m; |
1008 public: |
1037 public: |
1009 typedef MapBase<typename M::Key, bool> Parent; |
1038 typedef MapBase<typename M::Key, bool> Parent; |
1010 typedef typename Parent::Key Key; |
1039 typedef typename Parent::Key Key; |
1011 typedef typename Parent::Value Value; |
1040 typedef typename Parent::Value Value; |
1012 |
1041 |
1013 /// Constructor |
1042 /// Constructor |
1014 NotMap(const M &_m) : m(_m) {}; |
1043 NotMap(const M &_m) : m(_m) {}; |
|
1044 ///\e |
1015 Value operator[](Key k) const {return !m[k];} |
1045 Value operator[](Key k) const {return !m[k];} |
1016 }; |
1046 }; |
1017 |
1047 |
1018 ///Logical 'not' of a map with writing possibility |
1048 ///Logical 'not' of a map with writing possibility |
1019 |
1049 |
1020 ///This bool \ref concepts::ReadWriteMap "read-write map" returns the |
1050 ///This bool \c concepts::ReadWriteMap "read-write map" returns the |
1021 ///logical negation of value returned by the given map. When it is set, |
1051 ///logical negation of value returned by the given map. When it is set, |
1022 ///the opposite value is set to the original map. |
1052 ///the opposite value is set to the original map. |
1023 ///Its \c Key and will be inherited from \c M, |
1053 ///Its \c Key and will be inherited from \c M, |
1024 ///its Value is <tt>bool</tt>. |
1054 ///its Value is <tt>bool</tt>. |
1025 template <typename M> |
1055 template <typename M> |