50 typedef T Value; |
50 typedef T Value; |
51 }; |
51 }; |
52 |
52 |
53 /// Null map. (a.k.a. DoNothingMap) |
53 /// Null map. (a.k.a. DoNothingMap) |
54 |
54 |
55 /// If you have to provide a map only for its type definitions, |
55 /// This map can be used if you have to provide a map only for |
56 /// or if you have to provide a writable map, but |
56 /// its type definitions, or if you have to provide a writable map, |
57 /// data written to it will sent to <tt>/dev/null</tt>... |
57 /// but data written to it is not required (i.e. it will be sent to |
|
58 /// <tt>/dev/null</tt>). |
58 template<typename K, typename T> |
59 template<typename K, typename T> |
59 class NullMap : public MapBase<K, T> { |
60 class NullMap : public MapBase<K, T> { |
60 public: |
61 public: |
61 typedef MapBase<K, T> Parent; |
62 typedef MapBase<K, T> Parent; |
62 typedef typename Parent::Key Key; |
63 typedef typename Parent::Key Key; |
66 T operator[](const K&) const { return T(); } |
67 T operator[](const K&) const { return T(); } |
67 /// Absorbs the value. |
68 /// Absorbs the value. |
68 void set(const K&, const T&) {} |
69 void set(const K&, const T&) {} |
69 }; |
70 }; |
70 |
71 |
|
72 ///Returns a \c NullMap class |
|
73 |
|
74 ///This function just returns a \c NullMap class. |
|
75 ///\relates NullMap |
71 template <typename K, typename V> |
76 template <typename K, typename V> |
72 NullMap<K, V> nullMap() { |
77 NullMap<K, V> nullMap() { |
73 return NullMap<K, V>(); |
78 return NullMap<K, V>(); |
74 } |
79 } |
75 |
80 |
88 typedef typename Parent::Key Key; |
93 typedef typename Parent::Key Key; |
89 typedef typename Parent::Value Value; |
94 typedef typename Parent::Value Value; |
90 |
95 |
91 /// Default constructor |
96 /// Default constructor |
92 |
97 |
|
98 /// Default constructor. |
93 /// The value of the map will be uninitialized. |
99 /// The value of the map will be uninitialized. |
94 /// (More exactly it will be default constructed.) |
100 /// (More exactly it will be default constructed.) |
95 ConstMap() {} |
101 ConstMap() {} |
96 ///\e |
102 |
97 |
103 /// Constructor with specified initial value |
98 /// \param _v The initial value of the map. |
104 |
99 /// |
105 /// Constructor with specified initial value. |
|
106 /// \param _v is the initial value of the map. |
100 ConstMap(const T &_v) : v(_v) {} |
107 ConstMap(const T &_v) : v(_v) {} |
101 |
108 |
102 ///\e |
109 ///\e |
103 T operator[](const K&) const { return v; } |
110 T operator[](const K&) const { return v; } |
104 |
111 |
156 return ConstMap<K, Const<V, v> >(); |
163 return ConstMap<K, Const<V, v> >(); |
157 } |
164 } |
158 |
165 |
159 ///Map based on std::map |
166 ///Map based on std::map |
160 |
167 |
161 ///This is essentially a wrapper for \c std::map. With addition that |
168 ///This is essentially a wrapper for \c std::map with addition that |
162 ///you can specify a default value different from \c Value() . |
169 ///you can specify a default value different from \c Value(). |
163 template <typename K, typename T, typename Compare = std::less<K> > |
170 template <typename K, typename T, typename Compare = std::less<K> > |
164 class StdMap { |
171 class StdMap { |
165 template <typename K1, typename T1, typename C1> |
172 template <typename K1, typename T1, typename C1> |
166 friend class StdMap; |
173 friend class StdMap; |
167 public: |
174 public: |
319 /// @} |
326 /// @} |
320 |
327 |
321 /// \addtogroup map_adaptors |
328 /// \addtogroup map_adaptors |
322 /// @{ |
329 /// @{ |
323 |
330 |
324 /// \brief Identity mapping. |
331 /// \brief Identity map. |
325 /// |
332 /// |
326 /// This mapping gives back the given key as value without any |
333 /// This map gives back the given key as value without any |
327 /// modification. |
334 /// modification. |
328 template <typename T> |
335 template <typename T> |
329 class IdentityMap : public MapBase<T, T> { |
336 class IdentityMap : public MapBase<T, T> { |
330 public: |
337 public: |
331 typedef MapBase<T, T> Parent; |
338 typedef MapBase<T, T> Parent; |
350 |
357 |
351 ///\brief Convert the \c Value of a map to another type using |
358 ///\brief Convert the \c Value of a map to another type using |
352 ///the default conversion. |
359 ///the default conversion. |
353 /// |
360 /// |
354 ///This \c concepts::ReadMap "read only map" |
361 ///This \c concepts::ReadMap "read only map" |
355 ///converts the \c Value of a maps to type \c T. |
362 ///converts the \c Value of a map to type \c T. |
356 ///Its \c Key is inherited from \c M. |
363 ///Its \c Key is inherited from \c M. |
357 template <typename M, typename T> |
364 template <typename M, typename T> |
358 class ConvertMap : public MapBase<typename M::Key, T> { |
365 class ConvertMap : public MapBase<typename M::Key, T> { |
359 const M& m; |
366 const M& m; |
360 public: |
367 public: |
362 typedef typename Parent::Key Key; |
369 typedef typename Parent::Key Key; |
363 typedef typename Parent::Value Value; |
370 typedef typename Parent::Value Value; |
364 |
371 |
365 ///Constructor |
372 ///Constructor |
366 |
373 |
367 ///Constructor |
374 ///Constructor. |
368 ///\param _m is the underlying map |
375 ///\param _m is the underlying map. |
369 ConvertMap(const M &_m) : m(_m) {}; |
376 ConvertMap(const M &_m) : m(_m) {}; |
370 |
377 |
371 /// \brief The subscript operator. |
378 /// \brief The subscript operator. |
372 /// |
379 /// |
373 /// The subscript operator. |
380 /// The subscript operator. |
374 Value operator[](const Key& k) const {return m[k];} |
381 Value operator[](const Key& k) const {return m[k];} |
375 }; |
382 }; |
376 |
383 |
377 ///Returns an \c ConvertMap class |
384 ///Returns a \c ConvertMap class |
378 |
385 |
379 ///This function just returns an \c ConvertMap class. |
386 ///This function just returns a \c ConvertMap class. |
380 ///\relates ConvertMap |
387 ///\relates ConvertMap |
381 template<typename T, typename M> |
388 template<typename T, typename M> |
382 inline ConvertMap<M, T> convertMap(const M &m) { |
389 inline ConvertMap<M, T> convertMap(const M &m) { |
383 return ConvertMap<M, T>(m); |
390 return ConvertMap<M, T>(m); |
384 } |
391 } |
385 |
392 |
386 ///Simple wrapping of the map |
393 ///Simple wrapping of a map |
387 |
394 |
388 ///This \c concepts::ReadMap "read only map" returns the simple |
395 ///This \c concepts::ReadMap "read only map" returns the simple |
389 ///wrapping of the given map. Sometimes the reference maps cannot be |
396 ///wrapping of the given map. Sometimes the reference maps cannot be |
390 ///combined with simple read maps. This map adaptor wraps the given |
397 ///combined with simple read maps. This map adaptor wraps the given |
391 ///map to simple read map. |
398 ///map to simple read map. |
392 /// |
399 /// |
393 /// \todo Revise the misleading name |
400 ///\sa SimpleWriteMap |
|
401 /// |
|
402 /// \todo Revise the misleading name |
394 template<typename M> |
403 template<typename M> |
395 class SimpleMap : public MapBase<typename M::Key, typename M::Value> { |
404 class SimpleMap : public MapBase<typename M::Key, typename M::Value> { |
396 const M& m; |
405 const M& m; |
397 |
406 |
398 public: |
407 public: |
404 SimpleMap(const M &_m) : m(_m) {}; |
413 SimpleMap(const M &_m) : m(_m) {}; |
405 ///\e |
414 ///\e |
406 Value operator[](Key k) const {return m[k];} |
415 Value operator[](Key k) const {return m[k];} |
407 }; |
416 }; |
408 |
417 |
409 ///Simple writeable wrapping of the map |
418 ///Simple writable wrapping of the map |
410 |
419 |
411 ///This \c concepts::WriteMap "write map" returns the simple |
420 ///This \c concepts::WriteMap "write map" returns the simple |
412 ///wrapping of the given map. Sometimes the reference maps cannot be |
421 ///wrapping of the given map. Sometimes the reference maps cannot be |
413 ///combined with simple read-write maps. This map adaptor wraps the |
422 ///combined with simple read-write maps. This map adaptor wraps the |
414 ///given map to simple read-write map. |
423 ///given map to simple read-write map. |
415 /// |
424 /// |
|
425 ///\sa SimpleMap |
|
426 /// |
416 /// \todo Revise the misleading name |
427 /// \todo Revise the misleading name |
417 template<typename M> |
428 template<typename M> |
418 class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> { |
429 class SimpleWriteMap : public MapBase<typename M::Key, typename M::Value> { |
419 M& m; |
430 M& m; |
420 |
431 |
466 |
477 |
467 ///Shift a map with a constant. |
478 ///Shift a map with a constant. |
468 |
479 |
469 ///This \c concepts::ReadMap "read only map" returns the sum of the |
480 ///This \c concepts::ReadMap "read only map" returns the sum of the |
470 ///given map and a constant value. |
481 ///given map and a constant value. |
471 ///Its \c Key and \c Value is inherited from \c M. |
482 ///Its \c Key and \c Value are inherited from \c M. |
472 /// |
483 /// |
473 ///Actually, |
484 ///Actually, |
474 ///\code |
485 ///\code |
475 /// ShiftMap<X> sh(x,v); |
486 /// ShiftMap<X> sh(x,v); |
476 ///\endcode |
487 ///\endcode |
477 ///is equivalent with |
488 ///is equivalent to |
478 ///\code |
489 ///\code |
479 /// ConstMap<X::Key, X::Value> c_tmp(v); |
490 /// ConstMap<X::Key, X::Value> c_tmp(v); |
480 /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); |
491 /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); |
481 ///\endcode |
492 ///\endcode |
|
493 /// |
|
494 ///\sa ShiftWriteMap |
482 template<typename M, typename C = typename M::Value> |
495 template<typename M, typename C = typename M::Value> |
483 class ShiftMap : public MapBase<typename M::Key, typename M::Value> { |
496 class ShiftMap : public MapBase<typename M::Key, typename M::Value> { |
484 const M& m; |
497 const M& m; |
485 C v; |
498 C v; |
486 public: |
499 public: |
488 typedef typename Parent::Key Key; |
501 typedef typename Parent::Key Key; |
489 typedef typename Parent::Value Value; |
502 typedef typename Parent::Value Value; |
490 |
503 |
491 ///Constructor |
504 ///Constructor |
492 |
505 |
493 ///Constructor |
506 ///Constructor. |
494 ///\param _m is the undelying map |
507 ///\param _m is the undelying map. |
495 ///\param _v is the shift value |
508 ///\param _v is the shift value. |
496 ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {}; |
509 ShiftMap(const M &_m, const C &_v ) : m(_m), v(_v) {}; |
497 ///\e |
510 ///\e |
498 Value operator[](Key k) const {return m[k] + v;} |
511 Value operator[](Key k) const {return m[k] + v;} |
499 }; |
512 }; |
500 |
513 |
501 ///Shift a map with a constant. This map is also writable. |
514 ///Shift a map with a constant (ReadWrite version). |
502 |
515 |
503 ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the |
516 ///This \c concepts::ReadWriteMap "read-write map" returns the sum of the |
504 ///given map and a constant value. It makes also possible to write the map. |
517 ///given map and a constant value. It makes also possible to write the map. |
505 ///Its \c Key and \c Value is inherited from \c M. |
518 ///Its \c Key and \c Value are inherited from \c M. |
506 /// |
519 /// |
507 ///Actually, |
520 ///\sa ShiftMap |
508 ///\code |
|
509 /// ShiftMap<X> sh(x,v); |
|
510 ///\endcode |
|
511 ///is equivalent with |
|
512 ///\code |
|
513 /// ConstMap<X::Key, X::Value> c_tmp(v); |
|
514 /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v); |
|
515 ///\endcode |
|
516 template<typename M, typename C = typename M::Value> |
521 template<typename M, typename C = typename M::Value> |
517 class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> { |
522 class ShiftWriteMap : public MapBase<typename M::Key, typename M::Value> { |
518 M& m; |
523 M& m; |
519 C v; |
524 C v; |
520 public: |
525 public: |
522 typedef typename Parent::Key Key; |
527 typedef typename Parent::Key Key; |
523 typedef typename Parent::Value Value; |
528 typedef typename Parent::Value Value; |
524 |
529 |
525 ///Constructor |
530 ///Constructor |
526 |
531 |
527 ///Constructor |
532 ///Constructor. |
528 ///\param _m is the undelying map |
533 ///\param _m is the undelying map. |
529 ///\param _v is the shift value |
534 ///\param _v is the shift value. |
530 ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {}; |
535 ShiftWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {}; |
531 /// \e |
536 /// \e |
532 Value operator[](Key k) const {return m[k] + v;} |
537 Value operator[](Key k) const {return m[k] + v;} |
533 /// \e |
538 /// \e |
534 void set(Key k, const Value& c) { m.set(k, c - v); } |
539 void set(Key k, const Value& c) { m.set(k, c - v); } |
535 }; |
540 }; |
536 |
541 |
537 ///Returns an \c ShiftMap class |
542 ///Returns a \c ShiftMap class |
538 |
543 |
539 ///This function just returns an \c ShiftMap class. |
544 ///This function just returns a \c ShiftMap class. |
540 ///\relates ShiftMap |
545 ///\relates ShiftMap |
541 template<typename M, typename C> |
546 template<typename M, typename C> |
542 inline ShiftMap<M, C> shiftMap(const M &m,const C &v) { |
547 inline ShiftMap<M, C> shiftMap(const M &m,const C &v) { |
543 return ShiftMap<M, C>(m,v); |
548 return ShiftMap<M, C>(m,v); |
544 } |
549 } |
545 |
550 |
|
551 ///Returns a \c ShiftWriteMap class |
|
552 |
|
553 ///This function just returns a \c ShiftWriteMap class. |
|
554 ///\relates ShiftWriteMap |
546 template<typename M, typename C> |
555 template<typename M, typename C> |
547 inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) { |
556 inline ShiftWriteMap<M, C> shiftMap(M &m,const C &v) { |
548 return ShiftWriteMap<M, C>(m,v); |
557 return ShiftWriteMap<M, C>(m,v); |
549 } |
558 } |
550 |
559 |
551 ///Difference of two maps |
560 ///Difference of two maps |
552 |
561 |
553 ///This \c concepts::ReadMap "read only map" returns the difference |
562 ///This \c concepts::ReadMap "read only map" returns the difference |
554 ///of the values of the two |
563 ///of the values of the two given maps. |
555 ///given maps. Its \c Key and \c Value will be inherited from \c M1. |
564 ///Its \c Key and \c Value are inherited from \c M1. |
556 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
565 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
557 /// |
566 /// |
558 /// \todo Revise the misleading name |
567 /// \todo Revise the misleading name |
559 template<typename M1, typename M2> |
568 template<typename M1, typename M2> |
560 class SubMap : public MapBase<typename M1::Key, typename M1::Value> { |
569 class SubMap : public MapBase<typename M1::Key, typename M1::Value> { |
582 } |
591 } |
583 |
592 |
584 ///Product of two maps |
593 ///Product of two maps |
585 |
594 |
586 ///This \c concepts::ReadMap "read only map" returns the product of the |
595 ///This \c concepts::ReadMap "read only map" returns the product of the |
587 ///values of the two |
596 ///values of the two given maps. |
588 ///given |
597 ///Its \c Key and \c Value are inherited from \c M1. |
589 ///maps. Its \c Key and \c Value will be inherited from \c M1. |
|
590 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
598 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
591 |
|
592 template<typename M1, typename M2> |
599 template<typename M1, typename M2> |
593 class MulMap : public MapBase<typename M1::Key, typename M1::Value> { |
600 class MulMap : public MapBase<typename M1::Key, typename M1::Value> { |
594 const M1& m1; |
601 const M1& m1; |
595 const M2& m2; |
602 const M2& m2; |
596 public: |
603 public: |
611 template<typename M1, typename M2> |
618 template<typename M1, typename M2> |
612 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { |
619 inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) { |
613 return MulMap<M1, M2>(m1,m2); |
620 return MulMap<M1, M2>(m1,m2); |
614 } |
621 } |
615 |
622 |
616 ///Scales a maps with a constant. |
623 ///Scales a map with a constant. |
617 |
624 |
618 ///This \c concepts::ReadMap "read only map" returns the value of the |
625 ///This \c concepts::ReadMap "read only map" returns the value of the |
619 ///given map multiplied from the left side with a constant value. |
626 ///given map multiplied from the left side with a constant value. |
620 ///Its \c Key and \c Value is inherited from \c M. |
627 ///Its \c Key and \c Value are inherited from \c M. |
621 /// |
628 /// |
622 ///Actually, |
629 ///Actually, |
623 ///\code |
630 ///\code |
624 /// ScaleMap<X> sc(x,v); |
631 /// ScaleMap<X> sc(x,v); |
625 ///\endcode |
632 ///\endcode |
626 ///is equivalent with |
633 ///is equivalent to |
627 ///\code |
634 ///\code |
628 /// ConstMap<X::Key, X::Value> c_tmp(v); |
635 /// ConstMap<X::Key, X::Value> c_tmp(v); |
629 /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v); |
636 /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v); |
630 ///\endcode |
637 ///\endcode |
|
638 /// |
|
639 ///\sa ScaleWriteMap |
631 template<typename M, typename C = typename M::Value> |
640 template<typename M, typename C = typename M::Value> |
632 class ScaleMap : public MapBase<typename M::Key, typename M::Value> { |
641 class ScaleMap : public MapBase<typename M::Key, typename M::Value> { |
633 const M& m; |
642 const M& m; |
634 C v; |
643 C v; |
635 public: |
644 public: |
637 typedef typename Parent::Key Key; |
646 typedef typename Parent::Key Key; |
638 typedef typename Parent::Value Value; |
647 typedef typename Parent::Value Value; |
639 |
648 |
640 ///Constructor |
649 ///Constructor |
641 |
650 |
642 ///Constructor |
651 ///Constructor. |
643 ///\param _m is the undelying map |
652 ///\param _m is the undelying map. |
644 ///\param _v is the scaling value |
653 ///\param _v is the scaling value. |
645 ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {}; |
654 ScaleMap(const M &_m, const C &_v ) : m(_m), v(_v) {}; |
646 /// \e |
655 /// \e |
647 Value operator[](Key k) const {return v * m[k];} |
656 Value operator[](Key k) const {return v * m[k];} |
648 }; |
657 }; |
649 |
658 |
650 ///Scales a maps with a constant (ReadWrite version). |
659 ///Scales a map with a constant (ReadWrite version). |
651 |
660 |
652 ///This \c concepts::ReadWriteMap "read-write map" returns the value of the |
661 ///This \c concepts::ReadWriteMap "read-write map" returns the value of the |
653 ///given map multiplied from the left side with a constant value. It can |
662 ///given map multiplied from the left side with a constant value. It can |
654 ///be used as write map also if the given multiplier is not zero. |
663 ///also be used as write map if the \c / operator is defined between |
655 ///Its \c Key and \c Value is inherited from \c M. |
664 ///\c Value and \c C and the given multiplier is not zero. |
|
665 ///Its \c Key and \c Value are inherited from \c M. |
|
666 /// |
|
667 ///\sa ScaleMap |
656 template<typename M, typename C = typename M::Value> |
668 template<typename M, typename C = typename M::Value> |
657 class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> { |
669 class ScaleWriteMap : public MapBase<typename M::Key, typename M::Value> { |
658 M& m; |
670 M& m; |
659 C v; |
671 C v; |
660 public: |
672 public: |
662 typedef typename Parent::Key Key; |
674 typedef typename Parent::Key Key; |
663 typedef typename Parent::Value Value; |
675 typedef typename Parent::Value Value; |
664 |
676 |
665 ///Constructor |
677 ///Constructor |
666 |
678 |
667 ///Constructor |
679 ///Constructor. |
668 ///\param _m is the undelying map |
680 ///\param _m is the undelying map. |
669 ///\param _v is the scaling value |
681 ///\param _v is the scaling value. |
670 ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {}; |
682 ScaleWriteMap(M &_m, const C &_v ) : m(_m), v(_v) {}; |
671 /// \e |
683 /// \e |
672 Value operator[](Key k) const {return v * m[k];} |
684 Value operator[](Key k) const {return v * m[k];} |
673 /// \e |
685 /// \e |
674 void set(Key k, const Value& c) { m.set(k, c / v);} |
686 void set(Key k, const Value& c) { m.set(k, c / v);} |
675 }; |
687 }; |
676 |
688 |
677 ///Returns an \c ScaleMap class |
689 ///Returns a \c ScaleMap class |
678 |
690 |
679 ///This function just returns an \c ScaleMap class. |
691 ///This function just returns a \c ScaleMap class. |
680 ///\relates ScaleMap |
692 ///\relates ScaleMap |
681 template<typename M, typename C> |
693 template<typename M, typename C> |
682 inline ScaleMap<M, C> scaleMap(const M &m,const C &v) { |
694 inline ScaleMap<M, C> scaleMap(const M &m,const C &v) { |
683 return ScaleMap<M, C>(m,v); |
695 return ScaleMap<M, C>(m,v); |
684 } |
696 } |
685 |
697 |
|
698 ///Returns a \c ScaleWriteMap class |
|
699 |
|
700 ///This function just returns a \c ScaleWriteMap class. |
|
701 ///\relates ScaleWriteMap |
686 template<typename M, typename C> |
702 template<typename M, typename C> |
687 inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) { |
703 inline ScaleWriteMap<M, C> scaleMap(M &m,const C &v) { |
688 return ScaleWriteMap<M, C>(m,v); |
704 return ScaleWriteMap<M, C>(m,v); |
689 } |
705 } |
690 |
706 |
691 ///Quotient of two maps |
707 ///Quotient of two maps |
692 |
708 |
693 ///This \c concepts::ReadMap "read only map" returns the quotient of the |
709 ///This \c concepts::ReadMap "read only map" returns the quotient of the |
694 ///values of the two |
710 ///values of the two given maps. |
695 ///given maps. Its \c Key and \c Value will be inherited from \c M1. |
711 ///Its \c Key and \c Value are inherited from \c M1. |
696 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
712 ///The \c Key and \c Value of \c M2 must be convertible to those of \c M1. |
697 |
|
698 template<typename M1, typename M2> |
713 template<typename M1, typename M2> |
699 class DivMap : public MapBase<typename M1::Key, typename M1::Value> { |
714 class DivMap : public MapBase<typename M1::Key, typename M1::Value> { |
700 const M1& m1; |
715 const M1& m1; |
701 const M2& m2; |
716 const M2& m2; |
702 public: |
717 public: |
720 } |
735 } |
721 |
736 |
722 ///Composition of two maps |
737 ///Composition of two maps |
723 |
738 |
724 ///This \c concepts::ReadMap "read only map" returns the composition of |
739 ///This \c concepts::ReadMap "read only map" returns the composition of |
725 ///two |
740 ///two given maps. |
726 ///given maps. That is to say, if \c m1 is of type \c M1 and \c m2 is |
741 ///That is to say, if \c m1 is of type \c M1 and \c m2 is of \c M2, |
727 ///of \c M2, |
|
728 ///then for |
742 ///then for |
729 ///\code |
743 ///\code |
730 /// ComposeMap<M1, M2> cm(m1,m2); |
744 /// ComposeMap<M1, M2> cm(m1,m2); |
731 ///\endcode |
745 ///\endcode |
732 /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt> |
746 /// <tt>cm[x]</tt> will be equal to <tt>m1[m2[x]]</tt>. |
733 /// |
747 /// |
734 ///Its \c Key is inherited from \c M2 and its \c Value is from |
748 ///Its \c Key is inherited from \c M2 and its \c Value is from \c M1. |
735 ///\c M1. |
749 ///\c M2::Value must be convertible to \c M1::Key. |
736 ///The \c M2::Value must be convertible to \c M1::Key. |
750 /// |
|
751 ///\sa CombineMap |
|
752 /// |
737 ///\todo Check the requirements. |
753 ///\todo Check the requirements. |
738 template <typename M1, typename M2> |
754 template <typename M1, typename M2> |
739 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> { |
755 class ComposeMap : public MapBase<typename M2::Key, typename M1::Value> { |
740 const M1& m1; |
756 const M1& m1; |
741 const M2& m2; |
757 const M2& m2; |
755 |
771 |
756 //typename MapTraits<M1>::ConstReturnValue |
772 //typename MapTraits<M1>::ConstReturnValue |
757 typename M1::Value |
773 typename M1::Value |
758 operator[](Key k) const {return m1[m2[k]];} |
774 operator[](Key k) const {return m1[m2[k]];} |
759 }; |
775 }; |
|
776 |
760 ///Returns a \c ComposeMap class |
777 ///Returns a \c ComposeMap class |
761 |
778 |
762 ///This function just returns a \c ComposeMap class. |
779 ///This function just returns a \c ComposeMap class. |
763 /// |
|
764 ///\relates ComposeMap |
780 ///\relates ComposeMap |
765 template <typename M1, typename M2> |
781 template <typename M1, typename M2> |
766 inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) { |
782 inline ComposeMap<M1, M2> composeMap(const M1 &m1,const M2 &m2) { |
767 return ComposeMap<M1, M2>(m1,m2); |
783 return ComposeMap<M1, M2>(m1,m2); |
768 } |
784 } |
769 |
785 |
770 ///Combines of two maps using an STL (binary) functor. |
786 ///Combine of two maps using an STL (binary) functor. |
771 |
787 |
772 ///Combines of two maps using an STL (binary) functor. |
788 ///Combine of two maps using an STL (binary) functor. |
773 /// |
|
774 /// |
789 /// |
775 ///This \c concepts::ReadMap "read only map" takes two maps and a |
790 ///This \c concepts::ReadMap "read only map" takes two maps and a |
776 ///binary functor and returns the composition of |
791 ///binary functor and returns the composition of the two |
777 ///the two |
|
778 ///given maps unsing the functor. |
792 ///given maps unsing the functor. |
779 ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2 |
793 ///That is to say, if \c m1 and \c m2 is of type \c M1 and \c M2 |
780 ///and \c f is of \c F, |
794 ///and \c f is of \c F, then for |
781 ///then for |
|
782 ///\code |
795 ///\code |
783 /// CombineMap<M1, M2,F,V> cm(m1,m2,f); |
796 /// CombineMap<M1,M2,F,V> cm(m1,m2,f); |
784 ///\endcode |
797 ///\endcode |
785 /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt> |
798 /// <tt>cm[x]</tt> will be equal to <tt>f(m1[x],m2[x])</tt> |
786 /// |
799 /// |
787 ///Its \c Key is inherited from \c M1 and its \c Value is \c V. |
800 ///Its \c Key is inherited from \c M1 and its \c Value is \c V. |
788 ///The \c M2::Value and \c M1::Value must be convertible to the corresponding |
801 ///\c M2::Value and \c M1::Value must be convertible to the corresponding |
789 ///input parameter of \c F and the return type of \c F must be convertible |
802 ///input parameter of \c F and the return type of \c F must be convertible |
790 ///to \c V. |
803 ///to \c V. |
|
804 /// |
|
805 ///\sa ComposeMap |
|
806 /// |
791 ///\todo Check the requirements. |
807 ///\todo Check the requirements. |
792 template<typename M1, typename M2, typename F, |
808 template<typename M1, typename M2, typename F, |
793 typename V = typename F::result_type> |
809 typename V = typename F::result_type> |
794 class CombineMap : public MapBase<typename M1::Key, V> { |
810 class CombineMap : public MapBase<typename M1::Key, V> { |
795 const M1& m1; |
811 const M1& m1; |
813 /// |
829 /// |
814 ///For example if \c m1 and \c m2 are both \c double valued maps, then |
830 ///For example if \c m1 and \c m2 are both \c double valued maps, then |
815 ///\code |
831 ///\code |
816 ///combineMap<double>(m1,m2,std::plus<double>()) |
832 ///combineMap<double>(m1,m2,std::plus<double>()) |
817 ///\endcode |
833 ///\endcode |
818 ///is equivalent with |
834 ///is equivalent to |
819 ///\code |
835 ///\code |
820 ///addMap(m1,m2) |
836 ///addMap(m1,m2) |
821 ///\endcode |
837 ///\endcode |
822 /// |
838 /// |
823 ///This function is specialized for adaptable binary function |
839 ///This function is specialized for adaptable binary function |
824 ///classes and c++ functions. |
840 ///classes and C++ functions. |
825 /// |
841 /// |
826 ///\relates CombineMap |
842 ///\relates CombineMap |
827 template<typename M1, typename M2, typename F, typename V> |
843 template<typename M1, typename M2, typename F, typename V> |
828 inline CombineMap<M1, M2, F, V> |
844 inline CombineMap<M1, M2, F, V> |
829 combineMap(const M1& m1,const M2& m2, const F& f) { |
845 combineMap(const M1& m1,const M2& m2, const F& f) { |
843 } |
859 } |
844 |
860 |
845 ///Negative value of a map |
861 ///Negative value of a map |
846 |
862 |
847 ///This \c concepts::ReadMap "read only map" returns the negative |
863 ///This \c concepts::ReadMap "read only map" returns the negative |
848 ///value of the |
864 ///value of the value returned by the given map. |
849 ///value returned by the |
865 ///Its \c Key and \c Value are inherited from \c M. |
850 ///given map. Its \c Key and \c Value will be inherited from \c M. |
|
851 ///The unary \c - operator must be defined for \c Value, of course. |
866 ///The unary \c - operator must be defined for \c Value, of course. |
852 |
867 /// |
|
868 ///\sa NegWriteMap |
853 template<typename M> |
869 template<typename M> |
854 class NegMap : public MapBase<typename M::Key, typename M::Value> { |
870 class NegMap : public MapBase<typename M::Key, typename M::Value> { |
855 const M& m; |
871 const M& m; |
856 public: |
872 public: |
857 typedef MapBase<typename M::Key, typename M::Value> Parent; |
873 typedef MapBase<typename M::Key, typename M::Value> Parent; |
865 }; |
881 }; |
866 |
882 |
867 ///Negative value of a map (ReadWrite version) |
883 ///Negative value of a map (ReadWrite version) |
868 |
884 |
869 ///This \c concepts::ReadWriteMap "read-write map" returns the negative |
885 ///This \c concepts::ReadWriteMap "read-write map" returns the negative |
870 ///value of the value returned by the |
886 ///value of the value returned by the given map. |
871 ///given map. Its \c Key and \c Value will be inherited from \c M. |
887 ///Its \c Key and \c Value are inherited from \c M. |
872 ///The unary \c - operator must be defined for \c Value, of course. |
888 ///The unary \c - operator must be defined for \c Value, of course. |
873 |
889 /// |
|
890 /// \sa NegMap |
874 template<typename M> |
891 template<typename M> |
875 class NegWriteMap : public MapBase<typename M::Key, typename M::Value> { |
892 class NegWriteMap : public MapBase<typename M::Key, typename M::Value> { |
876 M& m; |
893 M& m; |
877 public: |
894 public: |
878 typedef MapBase<typename M::Key, typename M::Value> Parent; |
895 typedef MapBase<typename M::Key, typename M::Value> Parent; |
894 template <typename M> |
911 template <typename M> |
895 inline NegMap<M> negMap(const M &m) { |
912 inline NegMap<M> negMap(const M &m) { |
896 return NegMap<M>(m); |
913 return NegMap<M>(m); |
897 } |
914 } |
898 |
915 |
|
916 ///Returns a \c NegWriteMap class |
|
917 |
|
918 ///This function just returns a \c NegWriteMap class. |
|
919 ///\relates NegWriteMap |
899 template <typename M> |
920 template <typename M> |
900 inline NegWriteMap<M> negMap(M &m) { |
921 inline NegWriteMap<M> negMap(M &m) { |
901 return NegWriteMap<M>(m); |
922 return NegWriteMap<M>(m); |
902 } |
923 } |
903 |
924 |
904 ///Absolute value of a map |
925 ///Absolute value of a map |
905 |
926 |
906 ///This \c concepts::ReadMap "read only map" returns the absolute value |
927 ///This \c concepts::ReadMap "read only map" returns the absolute value |
907 ///of the |
928 ///of the value returned by the given map. |
908 ///value returned by the |
929 ///Its \c Key and \c Value are inherited from \c M. |
909 ///given map. Its \c Key and \c Value will be inherited |
930 ///\c Value must be comparable to \c 0 and the unary \c - |
910 ///from <tt>M</tt>. <tt>Value</tt> |
|
911 ///must be comparable to <tt>0</tt> and the unary <tt>-</tt> |
|
912 ///operator must be defined for it, of course. |
931 ///operator must be defined for it, of course. |
913 /// |
|
914 |
|
915 template<typename M> |
932 template<typename M> |
916 class AbsMap : public MapBase<typename M::Key, typename M::Value> { |
933 class AbsMap : public MapBase<typename M::Key, typename M::Value> { |
917 const M& m; |
934 const M& m; |
918 public: |
935 public: |
919 typedef MapBase<typename M::Key, typename M::Value> Parent; |
936 typedef MapBase<typename M::Key, typename M::Value> Parent; |
928 return tmp >= 0 ? tmp : -tmp; |
945 return tmp >= 0 ? tmp : -tmp; |
929 } |
946 } |
930 |
947 |
931 }; |
948 }; |
932 |
949 |
933 ///Returns a \c AbsMap class |
950 ///Returns an \c AbsMap class |
934 |
951 |
935 ///This function just returns a \c AbsMap class. |
952 ///This function just returns an \c AbsMap class. |
936 ///\relates AbsMap |
953 ///\relates AbsMap |
937 template<typename M> |
954 template<typename M> |
938 inline AbsMap<M> absMap(const M &m) { |
955 inline AbsMap<M> absMap(const M &m) { |
939 return AbsMap<M>(m); |
956 return AbsMap<M>(m); |
940 } |
957 } |
941 |
958 |
942 ///Converts an STL style functor to a map |
959 ///Converts an STL style functor to a map |
943 |
960 |
944 ///This \c concepts::ReadMap "read only map" returns the value |
961 ///This \c concepts::ReadMap "read only map" returns the value |
945 ///of a |
962 ///of a given functor. |
946 ///given map. |
|
947 /// |
963 /// |
948 ///Template parameters \c K and \c V will become its |
964 ///Template parameters \c K and \c V will become its |
949 ///\c Key and \c Value. They must be given explicitely |
965 ///\c Key and \c Value. They must be given explicitly |
950 ///because a functor does not provide such typedefs. |
966 ///because a functor does not provide such typedefs. |
951 /// |
967 /// |
952 ///Parameter \c F is the type of the used functor. |
968 ///Parameter \c F is the type of the used functor. |
|
969 /// |
|
970 ///\sa MapFunctor |
953 template<typename F, |
971 template<typename F, |
954 typename K = typename F::argument_type, |
972 typename K = typename F::argument_type, |
955 typename V = typename F::result_type> |
973 typename V = typename F::result_type> |
956 class FunctorMap : public MapBase<K, V> { |
974 class FunctorMap : public MapBase<K, V> { |
957 F f; |
975 F f; |
969 ///Returns a \c FunctorMap class |
987 ///Returns a \c FunctorMap class |
970 |
988 |
971 ///This function just returns a \c FunctorMap class. |
989 ///This function just returns a \c FunctorMap class. |
972 /// |
990 /// |
973 ///It is specialized for adaptable function classes and |
991 ///It is specialized for adaptable function classes and |
974 ///c++ functions. |
992 ///C++ functions. |
975 ///\relates FunctorMap |
993 ///\relates FunctorMap |
976 template<typename K, typename V, typename F> inline |
994 template<typename K, typename V, typename F> inline |
977 FunctorMap<F, K, V> functorMap(const F &f) { |
995 FunctorMap<F, K, V> functorMap(const F &f) { |
978 return FunctorMap<F, K, V>(f); |
996 return FunctorMap<F, K, V>(f); |
979 } |
997 } |
997 ///that is it provides an <tt>operator()</tt> to read its values. |
1015 ///that is it provides an <tt>operator()</tt> to read its values. |
998 /// |
1016 /// |
999 ///For the sake of convenience it also works as |
1017 ///For the sake of convenience it also works as |
1000 ///a ususal \c concepts::ReadMap "readable map", |
1018 ///a ususal \c concepts::ReadMap "readable map", |
1001 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. |
1019 ///i.e. <tt>operator[]</tt> and the \c Key and \c Value typedefs also exist. |
|
1020 /// |
|
1021 ///\sa FunctorMap |
1002 template <typename M> |
1022 template <typename M> |
1003 class MapFunctor : public MapBase<typename M::Key, typename M::Value> { |
1023 class MapFunctor : public MapBase<typename M::Key, typename M::Value> { |
1004 const M& m; |
1024 const M& m; |
1005 public: |
1025 public: |
1006 typedef MapBase<typename M::Key, typename M::Value> Parent; |
1026 typedef MapBase<typename M::Key, typename M::Value> Parent; |
1031 |
1051 |
1032 ///This map has two \c concepts::ReadMap "readable map" |
1052 ///This map has two \c concepts::ReadMap "readable map" |
1033 ///parameters and each read request will be passed just to the |
1053 ///parameters and each read request will be passed just to the |
1034 ///first map. This class is the just readable map type of the ForkWriteMap. |
1054 ///first map. This class is the just readable map type of the ForkWriteMap. |
1035 /// |
1055 /// |
1036 ///The \c Key and \c Value will be inherited from \c M1. |
1056 ///The \c Key and \c Value are inherited from \c M1. |
1037 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
1057 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
|
1058 /// |
|
1059 ///\sa ForkWriteMap |
1038 /// |
1060 /// |
1039 /// \todo Why is it needed? |
1061 /// \todo Why is it needed? |
1040 template<typename M1, typename M2> |
1062 template<typename M1, typename M2> |
1041 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { |
1063 class ForkMap : public MapBase<typename M1::Key, typename M1::Value> { |
1042 const M1& m1; |
1064 const M1& m1; |
1059 ///parameters and each write request will be passed to both of them. |
1081 ///parameters and each write request will be passed to both of them. |
1060 ///If \c M1 is also \c concepts::ReadMap "readable", |
1082 ///If \c M1 is also \c concepts::ReadMap "readable", |
1061 ///then the read operations will return the |
1083 ///then the read operations will return the |
1062 ///corresponding values of \c M1. |
1084 ///corresponding values of \c M1. |
1063 /// |
1085 /// |
1064 ///The \c Key and \c Value will be inherited from \c M1. |
1086 ///The \c Key and \c Value are inherited from \c M1. |
1065 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
1087 ///The \c Key and \c Value of M2 must be convertible from those of \c M1. |
|
1088 /// |
|
1089 ///\sa ForkMap |
1066 template<typename M1, typename M2> |
1090 template<typename M1, typename M2> |
1067 class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> { |
1091 class ForkWriteMap : public MapBase<typename M1::Key, typename M1::Value> { |
1068 M1& m1; |
1092 M1& m1; |
1069 M2& m2; |
1093 M2& m2; |
1070 public: |
1094 public: |
1078 Value operator[](Key k) const {return m1[k];} |
1102 Value operator[](Key k) const {return m1[k];} |
1079 ///\e |
1103 ///\e |
1080 void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);} |
1104 void set(Key k, const Value &v) {m1.set(k,v); m2.set(k,v);} |
1081 }; |
1105 }; |
1082 |
1106 |
1083 ///Returns an \c ForkMap class |
1107 ///Returns a \c ForkMap class |
1084 |
1108 |
1085 ///This function just returns an \c ForkMap class. |
1109 ///This function just returns a \c ForkMap class. |
1086 /// |
|
1087 ///\relates ForkMap |
1110 ///\relates ForkMap |
1088 template <typename M1, typename M2> |
1111 template <typename M1, typename M2> |
1089 inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) { |
1112 inline ForkMap<M1, M2> forkMap(const M1 &m1, const M2 &m2) { |
1090 return ForkMap<M1, M2>(m1,m2); |
1113 return ForkMap<M1, M2>(m1,m2); |
1091 } |
1114 } |
1092 |
1115 |
|
1116 ///Returns a \c ForkWriteMap class |
|
1117 |
|
1118 ///This function just returns a \c ForkWriteMap class. |
|
1119 ///\relates ForkWriteMap |
1093 template <typename M1, typename M2> |
1120 template <typename M1, typename M2> |
1094 inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) { |
1121 inline ForkWriteMap<M1, M2> forkMap(M1 &m1, M2 &m2) { |
1095 return ForkWriteMap<M1, M2>(m1,m2); |
1122 return ForkWriteMap<M1, M2>(m1,m2); |
1096 } |
1123 } |
1097 |
1124 |
1100 /* ************* BOOL MAPS ******************* */ |
1127 /* ************* BOOL MAPS ******************* */ |
1101 |
1128 |
1102 ///Logical 'not' of a map |
1129 ///Logical 'not' of a map |
1103 |
1130 |
1104 ///This bool \c concepts::ReadMap "read only map" returns the |
1131 ///This bool \c concepts::ReadMap "read only map" returns the |
1105 ///logical negation of |
1132 ///logical negation of the value returned by the given map. |
1106 ///value returned by the |
1133 ///Its \c Key is inherited from \c M, its Value is \c bool. |
1107 ///given map. Its \c Key and will be inherited from \c M, |
1134 /// |
1108 ///its Value is <tt>bool</tt>. |
1135 ///\sa NotWriteMap |
1109 template <typename M> |
1136 template <typename M> |
1110 class NotMap : public MapBase<typename M::Key, bool> { |
1137 class NotMap : public MapBase<typename M::Key, bool> { |
1111 const M& m; |
1138 const M& m; |
1112 public: |
1139 public: |
1113 typedef MapBase<typename M::Key, bool> Parent; |
1140 typedef MapBase<typename M::Key, bool> Parent; |
1121 }; |
1148 }; |
1122 |
1149 |
1123 ///Logical 'not' of a map (ReadWrie version) |
1150 ///Logical 'not' of a map (ReadWrie version) |
1124 |
1151 |
1125 ///This bool \c concepts::ReadWriteMap "read-write map" returns the |
1152 ///This bool \c concepts::ReadWriteMap "read-write map" returns the |
1126 ///logical negation of value returned by the given map. When it is set, |
1153 ///logical negation of the value returned by the given map. When it is set, |
1127 ///the opposite value is set to the original map. |
1154 ///the opposite value is set to the original map. |
1128 ///Its \c Key and will be inherited from \c M, |
1155 ///Its \c Key is inherited from \c M, its Value is \c bool. |
1129 ///its Value is <tt>bool</tt>. |
1156 /// |
|
1157 ///\sa NotMap |
1130 template <typename M> |
1158 template <typename M> |
1131 class NotWriteMap : public MapBase<typename M::Key, bool> { |
1159 class NotWriteMap : public MapBase<typename M::Key, bool> { |
1132 M& m; |
1160 M& m; |
1133 public: |
1161 public: |
1134 typedef MapBase<typename M::Key, bool> Parent; |
1162 typedef MapBase<typename M::Key, bool> Parent; |
1150 template <typename M> |
1178 template <typename M> |
1151 inline NotMap<M> notMap(const M &m) { |
1179 inline NotMap<M> notMap(const M &m) { |
1152 return NotMap<M>(m); |
1180 return NotMap<M>(m); |
1153 } |
1181 } |
1154 |
1182 |
|
1183 ///Returns a \c NotWriteMap class |
|
1184 |
|
1185 ///This function just returns a \c NotWriteMap class. |
|
1186 ///\relates NotWriteMap |
1155 template <typename M> |
1187 template <typename M> |
1156 inline NotWriteMap<M> notMap(M &m) { |
1188 inline NotWriteMap<M> notMap(M &m) { |
1157 return NotWriteMap<M>(m); |
1189 return NotWriteMap<M>(m); |
1158 } |
1190 } |
1159 |
1191 |
1181 }; |
1213 }; |
1182 |
1214 |
1183 } |
1215 } |
1184 |
1216 |
1185 |
1217 |
1186 /// \brief Writable bool map for logging each true assigned elements |
1218 /// \brief Writable bool map for logging each \c true assigned element |
1187 /// |
1219 /// |
1188 /// Writable bool map for logging each true assigned elements, i.e it |
1220 /// Writable bool map for logging each \c true assigned element, i.e it |
1189 /// copies all the keys set to true to the given iterator. |
1221 /// copies all the keys set to \c true to the given iterator. |
1190 /// |
1222 /// |
1191 /// \note The container of the iterator should contain space |
1223 /// \note The container of the iterator should contain space |
1192 /// for each element. |
1224 /// for each element. |
1193 /// |
1225 /// |
1194 /// The following example shows how you can write the edges found by the Prim |
1226 /// The following example shows how you can write the edges found by the Prim |
1205 /// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
1237 /// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
1206 /// |
1238 /// |
1207 /// prim(graph, cost, writerMap); |
1239 /// prim(graph, cost, writerMap); |
1208 ///\endcode |
1240 ///\endcode |
1209 /// |
1241 /// |
1210 ///\todo Revise the name of this class and the relates ones. |
1242 ///\sa BackInserterBoolMap |
|
1243 /// |
|
1244 ///\todo Revise the name of this class and the related ones. |
1211 template <typename _Iterator, |
1245 template <typename _Iterator, |
1212 typename _Functor = |
1246 typename _Functor = |
1213 _maps_bits::Identity<typename _maps_bits:: |
1247 _maps_bits::Identity<typename _maps_bits:: |
1214 IteratorTraits<_Iterator>::Value> > |
1248 IteratorTraits<_Iterator>::Value> > |
1215 class StoreBoolMap { |
1249 class StoreBoolMap { |
1246 Iterator _begin; |
1280 Iterator _begin; |
1247 mutable Iterator _end; |
1281 mutable Iterator _end; |
1248 Functor _functor; |
1282 Functor _functor; |
1249 }; |
1283 }; |
1250 |
1284 |
1251 /// \brief Writable bool map for logging each true assigned elements in |
1285 /// \brief Writable bool map for logging each \c true assigned element in |
1252 /// a back insertable container |
1286 /// a back insertable container. |
1253 /// |
1287 /// |
1254 /// Writable bool map for logging each true assigned elements by pushing |
1288 /// Writable bool map for logging each \c true assigned element by pushing |
1255 /// back them into a back insertable container. |
1289 /// them into a back insertable container. |
1256 /// It can be used to retrieve the items into a standard |
1290 /// It can be used to retrieve the items into a standard |
1257 /// container. The next example shows how you can store the |
1291 /// container. The next example shows how you can store the |
1258 /// edges found by the Prim algorithm in a vector. |
1292 /// edges found by the Prim algorithm in a vector. |
1259 /// |
1293 /// |
1260 ///\code |
1294 ///\code |
1261 /// vector<Edge> span_tree_edges; |
1295 /// vector<Edge> span_tree_edges; |
1262 /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges); |
1296 /// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges); |
1263 /// prim(graph, cost, inserter_map); |
1297 /// prim(graph, cost, inserter_map); |
1264 ///\endcode |
1298 ///\endcode |
|
1299 /// |
|
1300 ///\sa StoreBoolMap |
|
1301 ///\sa FrontInserterBoolMap |
|
1302 ///\sa InserterBoolMap |
1265 template <typename Container, |
1303 template <typename Container, |
1266 typename Functor = |
1304 typename Functor = |
1267 _maps_bits::Identity<typename Container::value_type> > |
1305 _maps_bits::Identity<typename Container::value_type> > |
1268 class BackInserterBoolMap { |
1306 class BackInserterBoolMap { |
1269 public: |
1307 public: |
1273 /// Constructor |
1311 /// Constructor |
1274 BackInserterBoolMap(Container& _container, |
1312 BackInserterBoolMap(Container& _container, |
1275 const Functor& _functor = Functor()) |
1313 const Functor& _functor = Functor()) |
1276 : container(_container), functor(_functor) {} |
1314 : container(_container), functor(_functor) {} |
1277 |
1315 |
1278 /// Setter function of the map |
1316 /// The \c set function of the map |
1279 void set(const Key& key, Value value) { |
1317 void set(const Key& key, Value value) { |
1280 if (value) { |
1318 if (value) { |
1281 container.push_back(functor(key)); |
1319 container.push_back(functor(key)); |
1282 } |
1320 } |
1283 } |
1321 } |
1285 private: |
1323 private: |
1286 Container& container; |
1324 Container& container; |
1287 Functor functor; |
1325 Functor functor; |
1288 }; |
1326 }; |
1289 |
1327 |
1290 /// \brief Writable bool map for storing each true assignments in |
1328 /// \brief Writable bool map for logging each \c true assigned element in |
1291 /// a front insertable container. |
1329 /// a front insertable container. |
1292 /// |
1330 /// |
1293 /// Writable bool map for storing each true assignment in a front |
1331 /// Writable bool map for logging each \c true assigned element by pushing |
1294 /// insertable container. It will push front all the keys set to \c true into |
1332 /// them into a front insertable container. |
1295 /// the container. For example see the BackInserterBoolMap. |
1333 /// It can be used to retrieve the items into a standard |
|
1334 /// container. For example see \ref BackInserterBoolMap. |
|
1335 /// |
|
1336 ///\sa BackInserterBoolMap |
|
1337 ///\sa InserterBoolMap |
1296 template <typename Container, |
1338 template <typename Container, |
1297 typename Functor = |
1339 typename Functor = |
1298 _maps_bits::Identity<typename Container::value_type> > |
1340 _maps_bits::Identity<typename Container::value_type> > |
1299 class FrontInserterBoolMap { |
1341 class FrontInserterBoolMap { |
1300 public: |
1342 public: |
1304 /// Constructor |
1346 /// Constructor |
1305 FrontInserterBoolMap(Container& _container, |
1347 FrontInserterBoolMap(Container& _container, |
1306 const Functor& _functor = Functor()) |
1348 const Functor& _functor = Functor()) |
1307 : container(_container), functor(_functor) {} |
1349 : container(_container), functor(_functor) {} |
1308 |
1350 |
1309 /// Setter function of the map |
1351 /// The \c set function of the map |
1310 void set(const Key& key, Value value) { |
1352 void set(const Key& key, Value value) { |
1311 if (value) { |
1353 if (value) { |
1312 container.push_front(key); |
1354 container.push_front(key); |
1313 } |
1355 } |
1314 } |
1356 } |
1316 private: |
1358 private: |
1317 Container& container; |
1359 Container& container; |
1318 Functor functor; |
1360 Functor functor; |
1319 }; |
1361 }; |
1320 |
1362 |
1321 /// \brief Writable bool map for storing each true assigned elements in |
1363 /// \brief Writable bool map for storing each \c true assigned element in |
1322 /// an insertable container. |
1364 /// an insertable container. |
1323 /// |
1365 /// |
1324 /// Writable bool map for storing each true assigned elements in an |
1366 /// Writable bool map for storing each \c true assigned element in an |
1325 /// insertable container. It will insert all the keys set to \c true into |
1367 /// insertable container. It will insert all the keys set to \c true into |
1326 /// the container. |
1368 /// the container. |
1327 /// |
1369 /// |
1328 /// For example, if you want to store the cut arcs of the strongly |
1370 /// For example, if you want to store the cut arcs of the strongly |
1329 /// connected components in a set you can use the next code: |
1371 /// connected components in a set you can use the next code: |
1331 ///\code |
1373 ///\code |
1332 /// set<Arc> cut_arcs; |
1374 /// set<Arc> cut_arcs; |
1333 /// InserterBoolMap<set<Arc> > inserter_map(cut_arcs); |
1375 /// InserterBoolMap<set<Arc> > inserter_map(cut_arcs); |
1334 /// stronglyConnectedCutArcs(digraph, cost, inserter_map); |
1376 /// stronglyConnectedCutArcs(digraph, cost, inserter_map); |
1335 ///\endcode |
1377 ///\endcode |
|
1378 /// |
|
1379 ///\sa BackInserterBoolMap |
|
1380 ///\sa FrontInserterBoolMap |
1336 template <typename Container, |
1381 template <typename Container, |
1337 typename Functor = |
1382 typename Functor = |
1338 _maps_bits::Identity<typename Container::value_type> > |
1383 _maps_bits::Identity<typename Container::value_type> > |
1339 class InserterBoolMap { |
1384 class InserterBoolMap { |
1340 public: |
1385 public: |
1341 typedef typename Container::value_type Key; |
1386 typedef typename Container::value_type Key; |
1342 typedef bool Value; |
1387 typedef bool Value; |
1343 |
1388 |
1344 /// Constructor |
1389 /// Constructor with specified iterator |
|
1390 |
|
1391 /// Constructor with specified iterator. |
|
1392 /// \param _container The container for storing the elements. |
|
1393 /// \param _it The elements will be inserted before this iterator. |
|
1394 /// \param _functor The functor that is used when an element is stored. |
1345 InserterBoolMap(Container& _container, typename Container::iterator _it, |
1395 InserterBoolMap(Container& _container, typename Container::iterator _it, |
1346 const Functor& _functor = Functor()) |
1396 const Functor& _functor = Functor()) |
1347 : container(_container), it(_it), functor(_functor) {} |
1397 : container(_container), it(_it), functor(_functor) {} |
1348 |
1398 |
1349 /// Constructor |
1399 /// Constructor |
|
1400 |
|
1401 /// Constructor without specified iterator. |
|
1402 /// The elements will be inserted before <tt>_container.end()</tt>. |
|
1403 /// \param _container The container for storing the elements. |
|
1404 /// \param _functor The functor that is used when an element is stored. |
1350 InserterBoolMap(Container& _container, const Functor& _functor = Functor()) |
1405 InserterBoolMap(Container& _container, const Functor& _functor = Functor()) |
1351 : container(_container), it(_container.end()), functor(_functor) {} |
1406 : container(_container), it(_container.end()), functor(_functor) {} |
1352 |
1407 |
1353 /// Setter function of the map |
1408 /// The \c set function of the map |
1354 void set(const Key& key, Value value) { |
1409 void set(const Key& key, Value value) { |
1355 if (value) { |
1410 if (value) { |
1356 it = container.insert(it, key); |
1411 it = container.insert(it, key); |
1357 ++it; |
1412 ++it; |
1358 } |
1413 } |
1362 Container& container; |
1417 Container& container; |
1363 typename Container::iterator it; |
1418 typename Container::iterator it; |
1364 Functor functor; |
1419 Functor functor; |
1365 }; |
1420 }; |
1366 |
1421 |
1367 /// \brief Fill the true set elements with a given value. |
1422 /// \brief Writable bool map for filling each \c true assigned element with a |
1368 /// |
1423 /// given value. |
1369 /// Writable bool map to fill the elements set to \c true with a given value. |
1424 /// |
1370 /// The value can set |
1425 /// Writable bool map for filling each \c true assigned element with a |
1371 /// the container. |
1426 /// given value. The value can set the container. |
1372 /// |
1427 /// |
1373 /// The following code finds the connected components of a graph |
1428 /// The following code finds the connected components of a graph |
1374 /// and stores it in the \c comp map: |
1429 /// and stores it in the \c comp map: |
1375 ///\code |
1430 ///\code |
1376 /// typedef Graph::NodeMap<int> ComponentMap; |
1431 /// typedef Graph::NodeMap<int> ComponentMap; |
1429 Map& map; |
1484 Map& map; |
1430 typename Map::Value fill; |
1485 typename Map::Value fill; |
1431 }; |
1486 }; |
1432 |
1487 |
1433 |
1488 |
1434 /// \brief Writable bool map which stores the sequence number of |
1489 /// \brief Writable bool map for storing the sequence number of |
1435 /// true assignments. |
1490 /// \c true assignments. |
1436 /// |
1491 /// |
1437 /// Writable bool map which stores for each true assigned elements |
1492 /// Writable bool map that stores for each \c true assigned elements |
1438 /// the sequence number of this setting. |
1493 /// the sequence number of this setting. |
1439 /// It makes it easy to calculate the leaving |
1494 /// It makes it easy to calculate the leaving |
1440 /// order of the nodes in the \c Dfs algorithm. |
1495 /// order of the nodes in the \c Dfs algorithm. |
1441 /// |
1496 /// |
1442 ///\code |
1497 ///\code |