| ... | ... |
@@ -584,456 +584,384 @@ |
| 584 | 584 |
inline CombineMap<M1, M2, F, typename F::result_type> |
| 585 | 585 |
combineMap(const M1 &m1, const M2 &m2, const F &f) {
|
| 586 | 586 |
return combineMap<M1, M2, F, typename F::result_type>(m1,m2,f); |
| 587 | 587 |
} |
| 588 | 588 |
|
| 589 | 589 |
template<typename M1, typename M2, typename K1, typename K2, typename V> |
| 590 | 590 |
inline CombineMap<M1, M2, V (*)(K1, K2), V> |
| 591 | 591 |
combineMap(const M1 &m1, const M2 &m2, V (*f)(K1, K2)) {
|
| 592 | 592 |
return combineMap<M1, M2, V (*)(K1, K2), V>(m1,m2,f); |
| 593 | 593 |
} |
| 594 | 594 |
|
| 595 | 595 |
|
| 596 | 596 |
/// Converts an STL style (unary) functor to a map |
| 597 | 597 |
|
| 598 | 598 |
/// This \ref concepts::ReadMap "read only map" returns the value |
| 599 | 599 |
/// of a given functor. Actually, it just wraps the functor and |
| 600 | 600 |
/// provides the \c Key and \c Value typedefs. |
| 601 | 601 |
/// |
| 602 | 602 |
/// Template parameters \c K and \c V will become its \c Key and |
| 603 | 603 |
/// \c Value. In most cases they have to be given explicitly because |
| 604 | 604 |
/// a functor typically does not provide \c argument_type and |
| 605 | 605 |
/// \c result_type typedefs. |
| 606 | 606 |
/// Parameter \c F is the type of the used functor. |
| 607 | 607 |
/// |
| 608 | 608 |
/// The simplest way of using this map is through the functorToMap() |
| 609 | 609 |
/// function. |
| 610 | 610 |
/// |
| 611 | 611 |
/// \sa MapToFunctor |
| 612 | 612 |
template<typename F, |
| 613 | 613 |
typename K = typename F::argument_type, |
| 614 | 614 |
typename V = typename F::result_type> |
| 615 | 615 |
class FunctorToMap : public MapBase<K, V> {
|
| 616 | 616 |
const F &_f; |
| 617 | 617 |
public: |
| 618 | 618 |
typedef MapBase<K, V> Parent; |
| 619 | 619 |
typedef typename Parent::Key Key; |
| 620 | 620 |
typedef typename Parent::Value Value; |
| 621 | 621 |
|
| 622 | 622 |
/// Constructor |
| 623 | 623 |
FunctorToMap(const F &f = F()) : _f(f) {}
|
| 624 | 624 |
/// \e |
| 625 | 625 |
Value operator[](const Key &k) const { return _f(k); }
|
| 626 | 626 |
}; |
| 627 | 627 |
|
| 628 | 628 |
/// Returns a \ref FunctorToMap class |
| 629 | 629 |
|
| 630 | 630 |
/// This function just returns a \ref FunctorToMap class. |
| 631 | 631 |
/// |
| 632 | 632 |
/// This function is specialized for adaptable binary function |
| 633 | 633 |
/// classes and C++ functions. |
| 634 | 634 |
/// |
| 635 | 635 |
/// \relates FunctorToMap |
| 636 | 636 |
template<typename K, typename V, typename F> |
| 637 | 637 |
inline FunctorToMap<F, K, V> functorToMap(const F &f) {
|
| 638 | 638 |
return FunctorToMap<F, K, V>(f); |
| 639 | 639 |
} |
| 640 | 640 |
|
| 641 | 641 |
template <typename F> |
| 642 | 642 |
inline FunctorToMap<F, typename F::argument_type, typename F::result_type> |
| 643 | 643 |
functorToMap(const F &f) |
| 644 | 644 |
{
|
| 645 | 645 |
return FunctorToMap<F, typename F::argument_type, |
| 646 | 646 |
typename F::result_type>(f); |
| 647 | 647 |
} |
| 648 | 648 |
|
| 649 | 649 |
template <typename K, typename V> |
| 650 | 650 |
inline FunctorToMap<V (*)(K), K, V> functorToMap(V (*f)(K)) {
|
| 651 | 651 |
return FunctorToMap<V (*)(K), K, V>(f); |
| 652 | 652 |
} |
| 653 | 653 |
|
| 654 | 654 |
|
| 655 | 655 |
/// Converts a map to an STL style (unary) functor |
| 656 | 656 |
|
| 657 | 657 |
/// This class converts a map to an STL style (unary) functor. |
| 658 | 658 |
/// That is it provides an <tt>operator()</tt> to read its values. |
| 659 | 659 |
/// |
| 660 | 660 |
/// For the sake of convenience it also works as a usual |
| 661 | 661 |
/// \ref concepts::ReadMap "readable map", i.e. <tt>operator[]</tt> |
| 662 | 662 |
/// and the \c Key and \c Value typedefs also exist. |
| 663 | 663 |
/// |
| 664 | 664 |
/// The simplest way of using this map is through the mapToFunctor() |
| 665 | 665 |
/// function. |
| 666 | 666 |
/// |
| 667 | 667 |
///\sa FunctorToMap |
| 668 | 668 |
template <typename M> |
| 669 | 669 |
class MapToFunctor : public MapBase<typename M::Key, typename M::Value> {
|
| 670 | 670 |
const M &_m; |
| 671 | 671 |
public: |
| 672 | 672 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 673 | 673 |
typedef typename Parent::Key Key; |
| 674 | 674 |
typedef typename Parent::Value Value; |
| 675 | 675 |
|
| 676 | 676 |
typedef typename Parent::Key argument_type; |
| 677 | 677 |
typedef typename Parent::Value result_type; |
| 678 | 678 |
|
| 679 | 679 |
/// Constructor |
| 680 | 680 |
MapToFunctor(const M &m) : _m(m) {}
|
| 681 | 681 |
/// \e |
| 682 | 682 |
Value operator()(const Key &k) const { return _m[k]; }
|
| 683 | 683 |
/// \e |
| 684 | 684 |
Value operator[](const Key &k) const { return _m[k]; }
|
| 685 | 685 |
}; |
| 686 | 686 |
|
| 687 | 687 |
/// Returns a \ref MapToFunctor class |
| 688 | 688 |
|
| 689 | 689 |
/// This function just returns a \ref MapToFunctor class. |
| 690 | 690 |
/// \relates MapToFunctor |
| 691 | 691 |
template<typename M> |
| 692 | 692 |
inline MapToFunctor<M> mapToFunctor(const M &m) {
|
| 693 | 693 |
return MapToFunctor<M>(m); |
| 694 | 694 |
} |
| 695 | 695 |
|
| 696 | 696 |
|
| 697 | 697 |
/// \brief Map adaptor to convert the \c Value type of a map to |
| 698 | 698 |
/// another type using the default conversion. |
| 699 | 699 |
|
| 700 | 700 |
/// Map adaptor to convert the \c Value type of a \ref concepts::ReadMap |
| 701 | 701 |
/// "readable map" to another type using the default conversion. |
| 702 | 702 |
/// The \c Key type of it is inherited from \c M and the \c Value |
| 703 | 703 |
/// type is \c V. |
| 704 | 704 |
/// This type conforms the \ref concepts::ReadMap "ReadMap" concept. |
| 705 | 705 |
/// |
| 706 | 706 |
/// The simplest way of using this map is through the convertMap() |
| 707 | 707 |
/// function. |
| 708 | 708 |
template <typename M, typename V> |
| 709 | 709 |
class ConvertMap : public MapBase<typename M::Key, V> {
|
| 710 | 710 |
const M &_m; |
| 711 | 711 |
public: |
| 712 | 712 |
typedef MapBase<typename M::Key, V> Parent; |
| 713 | 713 |
typedef typename Parent::Key Key; |
| 714 | 714 |
typedef typename Parent::Value Value; |
| 715 | 715 |
|
| 716 | 716 |
/// Constructor |
| 717 | 717 |
|
| 718 | 718 |
/// Constructor. |
| 719 | 719 |
/// \param m The underlying map. |
| 720 | 720 |
ConvertMap(const M &m) : _m(m) {}
|
| 721 | 721 |
|
| 722 | 722 |
/// \e |
| 723 | 723 |
Value operator[](const Key &k) const { return _m[k]; }
|
| 724 | 724 |
}; |
| 725 | 725 |
|
| 726 | 726 |
/// Returns a \ref ConvertMap class |
| 727 | 727 |
|
| 728 | 728 |
/// This function just returns a \ref ConvertMap class. |
| 729 | 729 |
/// \relates ConvertMap |
| 730 | 730 |
template<typename V, typename M> |
| 731 | 731 |
inline ConvertMap<M, V> convertMap(const M &map) {
|
| 732 | 732 |
return ConvertMap<M, V>(map); |
| 733 | 733 |
} |
| 734 | 734 |
|
| 735 | 735 |
|
| 736 | 736 |
/// Applies all map setting operations to two maps |
| 737 | 737 |
|
| 738 | 738 |
/// This map has two \ref concepts::WriteMap "writable map" parameters |
| 739 | 739 |
/// and each write request will be passed to both of them. |
| 740 | 740 |
/// If \c M1 is also \ref concepts::ReadMap "readable", then the read |
| 741 | 741 |
/// operations will return the corresponding values of \c M1. |
| 742 | 742 |
/// |
| 743 | 743 |
/// The \c Key and \c Value types are inherited from \c M1. |
| 744 | 744 |
/// The \c Key and \c Value of \c M2 must be convertible from those |
| 745 | 745 |
/// of \c M1. |
| 746 | 746 |
/// |
| 747 | 747 |
/// The simplest way of using this map is through the forkMap() |
| 748 | 748 |
/// function. |
| 749 | 749 |
template<typename M1, typename M2> |
| 750 | 750 |
class ForkMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 751 | 751 |
M1 &_m1; |
| 752 | 752 |
M2 &_m2; |
| 753 | 753 |
public: |
| 754 | 754 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 755 | 755 |
typedef typename Parent::Key Key; |
| 756 | 756 |
typedef typename Parent::Value Value; |
| 757 | 757 |
|
| 758 | 758 |
/// Constructor |
| 759 | 759 |
ForkMap(M1 &m1, M2 &m2) : _m1(m1), _m2(m2) {}
|
| 760 | 760 |
/// Returns the value associated with the given key in the first map. |
| 761 | 761 |
Value operator[](const Key &k) const { return _m1[k]; }
|
| 762 | 762 |
/// Sets the value associated with the given key in both maps. |
| 763 | 763 |
void set(const Key &k, const Value &v) { _m1.set(k,v); _m2.set(k,v); }
|
| 764 | 764 |
}; |
| 765 | 765 |
|
| 766 | 766 |
/// Returns a \ref ForkMap class |
| 767 | 767 |
|
| 768 | 768 |
/// This function just returns a \ref ForkMap class. |
| 769 | 769 |
/// \relates ForkMap |
| 770 | 770 |
template <typename M1, typename M2> |
| 771 | 771 |
inline ForkMap<M1,M2> forkMap(M1 &m1, M2 &m2) {
|
| 772 | 772 |
return ForkMap<M1,M2>(m1,m2); |
| 773 | 773 |
} |
| 774 | 774 |
|
| 775 | 775 |
|
| 776 |
/// Simple wrapping of a map |
|
| 777 |
|
|
| 778 |
/// This \ref concepts::ReadMap "read only map" returns the simple |
|
| 779 |
/// wrapping of the given map. Sometimes the reference maps cannot be |
|
| 780 |
/// combined with simple read maps. This map adaptor wraps the given |
|
| 781 |
/// map to simple read map. |
|
| 782 |
/// |
|
| 783 |
/// The simplest way of using this map is through the wrapMap() |
|
| 784 |
/// function. |
|
| 785 |
/// |
|
| 786 |
/// \sa WrapWriteMap |
|
| 787 |
template<typename M> |
|
| 788 |
class WrapMap : public MapBase<typename M::Key, typename M::Value> {
|
|
| 789 |
const M &_m; |
|
| 790 |
public: |
|
| 791 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
|
| 792 |
typedef typename Parent::Key Key; |
|
| 793 |
typedef typename Parent::Value Value; |
|
| 794 |
|
|
| 795 |
/// Constructor |
|
| 796 |
WrapMap(const M &m) : _m(m) {}
|
|
| 797 |
/// \e |
|
| 798 |
Value operator[](const Key &k) const { return _m[k]; }
|
|
| 799 |
}; |
|
| 800 |
|
|
| 801 |
/// Returns a \ref WrapMap class |
|
| 802 |
|
|
| 803 |
/// This function just returns a \ref WrapMap class. |
|
| 804 |
/// \relates WrapMap |
|
| 805 |
template<typename M> |
|
| 806 |
inline WrapMap<M> wrapMap(const M &map) {
|
|
| 807 |
return WrapMap<M>(map); |
|
| 808 |
} |
|
| 809 |
|
|
| 810 |
|
|
| 811 |
/// Simple writable wrapping of a map |
|
| 812 |
|
|
| 813 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the simple |
|
| 814 |
/// wrapping of the given map. Sometimes the reference maps cannot be |
|
| 815 |
/// combined with simple read-write maps. This map adaptor wraps the |
|
| 816 |
/// given map to simple read-write map. |
|
| 817 |
/// |
|
| 818 |
/// The simplest way of using this map is through the wrapWriteMap() |
|
| 819 |
/// function. |
|
| 820 |
/// |
|
| 821 |
/// \sa WrapMap |
|
| 822 |
template<typename M> |
|
| 823 |
class WrapWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
|
| 824 |
M &_m; |
|
| 825 |
public: |
|
| 826 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
|
| 827 |
typedef typename Parent::Key Key; |
|
| 828 |
typedef typename Parent::Value Value; |
|
| 829 |
|
|
| 830 |
/// Constructor |
|
| 831 |
WrapWriteMap(M &m) : _m(m) {}
|
|
| 832 |
/// \e |
|
| 833 |
Value operator[](const Key &k) const { return _m[k]; }
|
|
| 834 |
/// \e |
|
| 835 |
void set(const Key &k, const Value &c) { _m.set(k, c); }
|
|
| 836 |
}; |
|
| 837 |
|
|
| 838 |
///Returns a \ref WrapWriteMap class |
|
| 839 |
|
|
| 840 |
///This function just returns a \ref WrapWriteMap class. |
|
| 841 |
///\relates WrapWriteMap |
|
| 842 |
template<typename M> |
|
| 843 |
inline WrapWriteMap<M> wrapWriteMap(M &map) {
|
|
| 844 |
return WrapWriteMap<M>(map); |
|
| 845 |
} |
|
| 846 |
|
|
| 847 |
|
|
| 848 | 776 |
/// Sum of two maps |
| 849 | 777 |
|
| 850 | 778 |
/// This \ref concepts::ReadMap "read only map" returns the sum |
| 851 | 779 |
/// of the values of the two given maps. |
| 852 | 780 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 853 | 781 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 854 | 782 |
/// \c M1. |
| 855 | 783 |
/// |
| 856 | 784 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 857 | 785 |
/// \code |
| 858 | 786 |
/// AddMap<M1,M2> am(m1,m2); |
| 859 | 787 |
/// \endcode |
| 860 | 788 |
/// <tt>am[x]</tt> will be equal to <tt>m1[x]+m2[x]</tt>. |
| 861 | 789 |
/// |
| 862 | 790 |
/// The simplest way of using this map is through the addMap() |
| 863 | 791 |
/// function. |
| 864 | 792 |
/// |
| 865 | 793 |
/// \sa SubMap, MulMap, DivMap |
| 866 | 794 |
/// \sa ShiftMap, ShiftWriteMap |
| 867 | 795 |
template<typename M1, typename M2> |
| 868 | 796 |
class AddMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 869 | 797 |
const M1 &_m1; |
| 870 | 798 |
const M2 &_m2; |
| 871 | 799 |
public: |
| 872 | 800 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 873 | 801 |
typedef typename Parent::Key Key; |
| 874 | 802 |
typedef typename Parent::Value Value; |
| 875 | 803 |
|
| 876 | 804 |
/// Constructor |
| 877 | 805 |
AddMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 878 | 806 |
/// \e |
| 879 | 807 |
Value operator[](const Key &k) const { return _m1[k]+_m2[k]; }
|
| 880 | 808 |
}; |
| 881 | 809 |
|
| 882 | 810 |
/// Returns an \ref AddMap class |
| 883 | 811 |
|
| 884 | 812 |
/// This function just returns an \ref AddMap class. |
| 885 | 813 |
/// |
| 886 | 814 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 887 | 815 |
/// values, then <tt>addMap(m1,m2)[x]</tt> will be equal to |
| 888 | 816 |
/// <tt>m1[x]+m2[x]</tt>. |
| 889 | 817 |
/// |
| 890 | 818 |
/// \relates AddMap |
| 891 | 819 |
template<typename M1, typename M2> |
| 892 | 820 |
inline AddMap<M1, M2> addMap(const M1 &m1, const M2 &m2) {
|
| 893 | 821 |
return AddMap<M1, M2>(m1,m2); |
| 894 | 822 |
} |
| 895 | 823 |
|
| 896 | 824 |
|
| 897 | 825 |
/// Difference of two maps |
| 898 | 826 |
|
| 899 | 827 |
/// This \ref concepts::ReadMap "read only map" returns the difference |
| 900 | 828 |
/// of the values of the two given maps. |
| 901 | 829 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 902 | 830 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 903 | 831 |
/// \c M1. |
| 904 | 832 |
/// |
| 905 | 833 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 906 | 834 |
/// \code |
| 907 | 835 |
/// SubMap<M1,M2> sm(m1,m2); |
| 908 | 836 |
/// \endcode |
| 909 | 837 |
/// <tt>sm[x]</tt> will be equal to <tt>m1[x]-m2[x]</tt>. |
| 910 | 838 |
/// |
| 911 | 839 |
/// The simplest way of using this map is through the subMap() |
| 912 | 840 |
/// function. |
| 913 | 841 |
/// |
| 914 | 842 |
/// \sa AddMap, MulMap, DivMap |
| 915 | 843 |
template<typename M1, typename M2> |
| 916 | 844 |
class SubMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 917 | 845 |
const M1 &_m1; |
| 918 | 846 |
const M2 &_m2; |
| 919 | 847 |
public: |
| 920 | 848 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 921 | 849 |
typedef typename Parent::Key Key; |
| 922 | 850 |
typedef typename Parent::Value Value; |
| 923 | 851 |
|
| 924 | 852 |
/// Constructor |
| 925 | 853 |
SubMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 926 | 854 |
/// \e |
| 927 | 855 |
Value operator[](const Key &k) const { return _m1[k]-_m2[k]; }
|
| 928 | 856 |
}; |
| 929 | 857 |
|
| 930 | 858 |
/// Returns a \ref SubMap class |
| 931 | 859 |
|
| 932 | 860 |
/// This function just returns a \ref SubMap class. |
| 933 | 861 |
/// |
| 934 | 862 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 935 | 863 |
/// values, then <tt>subMap(m1,m2)[x]</tt> will be equal to |
| 936 | 864 |
/// <tt>m1[x]-m2[x]</tt>. |
| 937 | 865 |
/// |
| 938 | 866 |
/// \relates SubMap |
| 939 | 867 |
template<typename M1, typename M2> |
| 940 | 868 |
inline SubMap<M1, M2> subMap(const M1 &m1, const M2 &m2) {
|
| 941 | 869 |
return SubMap<M1, M2>(m1,m2); |
| 942 | 870 |
} |
| 943 | 871 |
|
| 944 | 872 |
|
| 945 | 873 |
/// Product of two maps |
| 946 | 874 |
|
| 947 | 875 |
/// This \ref concepts::ReadMap "read only map" returns the product |
| 948 | 876 |
/// of the values of the two given maps. |
| 949 | 877 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 950 | 878 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 951 | 879 |
/// \c M1. |
| 952 | 880 |
/// |
| 953 | 881 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 954 | 882 |
/// \code |
| 955 | 883 |
/// MulMap<M1,M2> mm(m1,m2); |
| 956 | 884 |
/// \endcode |
| 957 | 885 |
/// <tt>mm[x]</tt> will be equal to <tt>m1[x]*m2[x]</tt>. |
| 958 | 886 |
/// |
| 959 | 887 |
/// The simplest way of using this map is through the mulMap() |
| 960 | 888 |
/// function. |
| 961 | 889 |
/// |
| 962 | 890 |
/// \sa AddMap, SubMap, DivMap |
| 963 | 891 |
/// \sa ScaleMap, ScaleWriteMap |
| 964 | 892 |
template<typename M1, typename M2> |
| 965 | 893 |
class MulMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 966 | 894 |
const M1 &_m1; |
| 967 | 895 |
const M2 &_m2; |
| 968 | 896 |
public: |
| 969 | 897 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 970 | 898 |
typedef typename Parent::Key Key; |
| 971 | 899 |
typedef typename Parent::Value Value; |
| 972 | 900 |
|
| 973 | 901 |
/// Constructor |
| 974 | 902 |
MulMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 975 | 903 |
/// \e |
| 976 | 904 |
Value operator[](const Key &k) const { return _m1[k]*_m2[k]; }
|
| 977 | 905 |
}; |
| 978 | 906 |
|
| 979 | 907 |
/// Returns a \ref MulMap class |
| 980 | 908 |
|
| 981 | 909 |
/// This function just returns a \ref MulMap class. |
| 982 | 910 |
/// |
| 983 | 911 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 984 | 912 |
/// values, then <tt>mulMap(m1,m2)[x]</tt> will be equal to |
| 985 | 913 |
/// <tt>m1[x]*m2[x]</tt>. |
| 986 | 914 |
/// |
| 987 | 915 |
/// \relates MulMap |
| 988 | 916 |
template<typename M1, typename M2> |
| 989 | 917 |
inline MulMap<M1, M2> mulMap(const M1 &m1,const M2 &m2) {
|
| 990 | 918 |
return MulMap<M1, M2>(m1,m2); |
| 991 | 919 |
} |
| 992 | 920 |
|
| 993 | 921 |
|
| 994 | 922 |
/// Quotient of two maps |
| 995 | 923 |
|
| 996 | 924 |
/// This \ref concepts::ReadMap "read only map" returns the quotient |
| 997 | 925 |
/// of the values of the two given maps. |
| 998 | 926 |
/// Its \c Key and \c Value types are inherited from \c M1. |
| 999 | 927 |
/// The \c Key and \c Value of \c M2 must be convertible to those of |
| 1000 | 928 |
/// \c M1. |
| 1001 | 929 |
/// |
| 1002 | 930 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 1003 | 931 |
/// \code |
| 1004 | 932 |
/// DivMap<M1,M2> dm(m1,m2); |
| 1005 | 933 |
/// \endcode |
| 1006 | 934 |
/// <tt>dm[x]</tt> will be equal to <tt>m1[x]/m2[x]</tt>. |
| 1007 | 935 |
/// |
| 1008 | 936 |
/// The simplest way of using this map is through the divMap() |
| 1009 | 937 |
/// function. |
| 1010 | 938 |
/// |
| 1011 | 939 |
/// \sa AddMap, SubMap, MulMap |
| 1012 | 940 |
template<typename M1, typename M2> |
| 1013 | 941 |
class DivMap : public MapBase<typename M1::Key, typename M1::Value> {
|
| 1014 | 942 |
const M1 &_m1; |
| 1015 | 943 |
const M2 &_m2; |
| 1016 | 944 |
public: |
| 1017 | 945 |
typedef MapBase<typename M1::Key, typename M1::Value> Parent; |
| 1018 | 946 |
typedef typename Parent::Key Key; |
| 1019 | 947 |
typedef typename Parent::Value Value; |
| 1020 | 948 |
|
| 1021 | 949 |
/// Constructor |
| 1022 | 950 |
DivMap(const M1 &m1,const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 1023 | 951 |
/// \e |
| 1024 | 952 |
Value operator[](const Key &k) const { return _m1[k]/_m2[k]; }
|
| 1025 | 953 |
}; |
| 1026 | 954 |
|
| 1027 | 955 |
/// Returns a \ref DivMap class |
| 1028 | 956 |
|
| 1029 | 957 |
/// This function just returns a \ref DivMap class. |
| 1030 | 958 |
/// |
| 1031 | 959 |
/// For example, if \c m1 and \c m2 are both maps with \c double |
| 1032 | 960 |
/// values, then <tt>divMap(m1,m2)[x]</tt> will be equal to |
| 1033 | 961 |
/// <tt>m1[x]/m2[x]</tt>. |
| 1034 | 962 |
/// |
| 1035 | 963 |
/// \relates DivMap |
| 1036 | 964 |
template<typename M1, typename M2> |
| 1037 | 965 |
inline DivMap<M1, M2> divMap(const M1 &m1,const M2 &m2) {
|
| 1038 | 966 |
return DivMap<M1, M2>(m1,m2); |
| 1039 | 967 |
} |
| ... | ... |
@@ -1274,572 +1202,196 @@ |
| 1274 | 1202 |
/// \e |
| 1275 | 1203 |
Value operator[](const Key &k) const { return -_m[k]; }
|
| 1276 | 1204 |
}; |
| 1277 | 1205 |
|
| 1278 | 1206 |
/// Negative of a map (read-write version) |
| 1279 | 1207 |
|
| 1280 | 1208 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the |
| 1281 | 1209 |
/// negative of the values of the given map (using the unary \c - |
| 1282 | 1210 |
/// operator). |
| 1283 | 1211 |
/// Its \c Key and \c Value are inherited from \c M. |
| 1284 | 1212 |
/// It makes also possible to write the map. |
| 1285 | 1213 |
/// |
| 1286 | 1214 |
/// If M::Value is \c int, \c double etc., then |
| 1287 | 1215 |
/// \code |
| 1288 | 1216 |
/// NegWriteMap<M> neg(m); |
| 1289 | 1217 |
/// \endcode |
| 1290 | 1218 |
/// is equivalent to |
| 1291 | 1219 |
/// \code |
| 1292 | 1220 |
/// ScaleWriteMap<M> neg(m,-1); |
| 1293 | 1221 |
/// \endcode |
| 1294 | 1222 |
/// |
| 1295 | 1223 |
/// The simplest way of using this map is through the negWriteMap() |
| 1296 | 1224 |
/// function. |
| 1297 | 1225 |
/// |
| 1298 | 1226 |
/// \sa NegMap |
| 1299 | 1227 |
template<typename M> |
| 1300 | 1228 |
class NegWriteMap : public MapBase<typename M::Key, typename M::Value> {
|
| 1301 | 1229 |
M &_m; |
| 1302 | 1230 |
public: |
| 1303 | 1231 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 1304 | 1232 |
typedef typename Parent::Key Key; |
| 1305 | 1233 |
typedef typename Parent::Value Value; |
| 1306 | 1234 |
|
| 1307 | 1235 |
/// Constructor |
| 1308 | 1236 |
NegWriteMap(M &m) : _m(m) {}
|
| 1309 | 1237 |
/// \e |
| 1310 | 1238 |
Value operator[](const Key &k) const { return -_m[k]; }
|
| 1311 | 1239 |
/// \e |
| 1312 | 1240 |
void set(const Key &k, const Value &v) { _m.set(k, -v); }
|
| 1313 | 1241 |
}; |
| 1314 | 1242 |
|
| 1315 | 1243 |
/// Returns a \ref NegMap class |
| 1316 | 1244 |
|
| 1317 | 1245 |
/// This function just returns a \ref NegMap class. |
| 1318 | 1246 |
/// |
| 1319 | 1247 |
/// For example, if \c m is a map with \c double values, then |
| 1320 | 1248 |
/// <tt>negMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>. |
| 1321 | 1249 |
/// |
| 1322 | 1250 |
/// \relates NegMap |
| 1323 | 1251 |
template <typename M> |
| 1324 | 1252 |
inline NegMap<M> negMap(const M &m) {
|
| 1325 | 1253 |
return NegMap<M>(m); |
| 1326 | 1254 |
} |
| 1327 | 1255 |
|
| 1328 | 1256 |
/// Returns a \ref NegWriteMap class |
| 1329 | 1257 |
|
| 1330 | 1258 |
/// This function just returns a \ref NegWriteMap class. |
| 1331 | 1259 |
/// |
| 1332 | 1260 |
/// For example, if \c m is a map with \c double values, then |
| 1333 | 1261 |
/// <tt>negWriteMap(m)[x]</tt> will be equal to <tt>-m[x]</tt>. |
| 1334 | 1262 |
/// Moreover it makes also possible to write the map. |
| 1335 | 1263 |
/// |
| 1336 | 1264 |
/// \relates NegWriteMap |
| 1337 | 1265 |
template <typename M> |
| 1338 | 1266 |
inline NegWriteMap<M> negWriteMap(M &m) {
|
| 1339 | 1267 |
return NegWriteMap<M>(m); |
| 1340 | 1268 |
} |
| 1341 | 1269 |
|
| 1342 | 1270 |
|
| 1343 | 1271 |
/// Absolute value of a map |
| 1344 | 1272 |
|
| 1345 | 1273 |
/// This \ref concepts::ReadMap "read only map" returns the absolute |
| 1346 | 1274 |
/// value of the values of the given map. |
| 1347 | 1275 |
/// Its \c Key and \c Value are inherited from \c M. |
| 1348 | 1276 |
/// \c Value must be comparable to \c 0 and the unary \c - |
| 1349 | 1277 |
/// operator must be defined for it, of course. |
| 1350 | 1278 |
/// |
| 1351 | 1279 |
/// The simplest way of using this map is through the absMap() |
| 1352 | 1280 |
/// function. |
| 1353 | 1281 |
template<typename M> |
| 1354 | 1282 |
class AbsMap : public MapBase<typename M::Key, typename M::Value> {
|
| 1355 | 1283 |
const M &_m; |
| 1356 | 1284 |
public: |
| 1357 | 1285 |
typedef MapBase<typename M::Key, typename M::Value> Parent; |
| 1358 | 1286 |
typedef typename Parent::Key Key; |
| 1359 | 1287 |
typedef typename Parent::Value Value; |
| 1360 | 1288 |
|
| 1361 | 1289 |
/// Constructor |
| 1362 | 1290 |
AbsMap(const M &m) : _m(m) {}
|
| 1363 | 1291 |
/// \e |
| 1364 | 1292 |
Value operator[](const Key &k) const {
|
| 1365 | 1293 |
Value tmp = _m[k]; |
| 1366 | 1294 |
return tmp >= 0 ? tmp : -tmp; |
| 1367 | 1295 |
} |
| 1368 | 1296 |
|
| 1369 | 1297 |
}; |
| 1370 | 1298 |
|
| 1371 | 1299 |
/// Returns an \ref AbsMap class |
| 1372 | 1300 |
|
| 1373 | 1301 |
/// This function just returns an \ref AbsMap class. |
| 1374 | 1302 |
/// |
| 1375 | 1303 |
/// For example, if \c m is a map with \c double values, then |
| 1376 | 1304 |
/// <tt>absMap(m)[x]</tt> will be equal to <tt>m[x]</tt> if |
| 1377 | 1305 |
/// it is positive or zero and <tt>-m[x]</tt> if <tt>m[x]</tt> is |
| 1378 | 1306 |
/// negative. |
| 1379 | 1307 |
/// |
| 1380 | 1308 |
/// \relates AbsMap |
| 1381 | 1309 |
template<typename M> |
| 1382 | 1310 |
inline AbsMap<M> absMap(const M &m) {
|
| 1383 | 1311 |
return AbsMap<M>(m); |
| 1384 | 1312 |
} |
| 1385 | 1313 |
|
| 1386 | 1314 |
|
| 1387 | 1315 |
/// Logical 'not' of a map |
| 1388 | 1316 |
|
| 1389 | 1317 |
/// This \ref concepts::ReadMap "read only map" returns the logical |
| 1390 | 1318 |
/// negation of the values of the given map. |
| 1391 | 1319 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1392 | 1320 |
/// |
| 1393 | 1321 |
/// The simplest way of using this map is through the notMap() |
| 1394 | 1322 |
/// function. |
| 1395 | 1323 |
/// |
| 1396 | 1324 |
/// \sa NotWriteMap |
| 1397 | 1325 |
template <typename M> |
| 1398 | 1326 |
class NotMap : public MapBase<typename M::Key, bool> {
|
| 1399 | 1327 |
const M &_m; |
| 1400 | 1328 |
public: |
| 1401 | 1329 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1402 | 1330 |
typedef typename Parent::Key Key; |
| 1403 | 1331 |
typedef typename Parent::Value Value; |
| 1404 | 1332 |
|
| 1405 | 1333 |
/// Constructor |
| 1406 | 1334 |
NotMap(const M &m) : _m(m) {}
|
| 1407 | 1335 |
/// \e |
| 1408 | 1336 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1409 | 1337 |
}; |
| 1410 | 1338 |
|
| 1411 | 1339 |
/// Logical 'not' of a map (read-write version) |
| 1412 | 1340 |
|
| 1413 | 1341 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the |
| 1414 | 1342 |
/// logical negation of the values of the given map. |
| 1415 | 1343 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1416 | 1344 |
/// It makes also possible to write the map. When a value is set, |
| 1417 | 1345 |
/// the opposite value is set to the original map. |
| 1418 | 1346 |
/// |
| 1419 | 1347 |
/// The simplest way of using this map is through the notWriteMap() |
| 1420 | 1348 |
/// function. |
| 1421 | 1349 |
/// |
| 1422 | 1350 |
/// \sa NotMap |
| 1423 | 1351 |
template <typename M> |
| 1424 | 1352 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1425 | 1353 |
M &_m; |
| 1426 | 1354 |
public: |
| 1427 | 1355 |
typedef MapBase<typename M::Key, bool> Parent; |
| 1428 | 1356 |
typedef typename Parent::Key Key; |
| 1429 | 1357 |
typedef typename Parent::Value Value; |
| 1430 | 1358 |
|
| 1431 | 1359 |
/// Constructor |
| 1432 | 1360 |
NotWriteMap(M &m) : _m(m) {}
|
| 1433 | 1361 |
/// \e |
| 1434 | 1362 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1435 | 1363 |
/// \e |
| 1436 | 1364 |
void set(const Key &k, bool v) { _m.set(k, !v); }
|
| 1437 | 1365 |
}; |
| 1438 | 1366 |
|
| 1439 | 1367 |
/// Returns a \ref NotMap class |
| 1440 | 1368 |
|
| 1441 | 1369 |
/// This function just returns a \ref NotMap class. |
| 1442 | 1370 |
/// |
| 1443 | 1371 |
/// For example, if \c m is a map with \c bool values, then |
| 1444 | 1372 |
/// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1445 | 1373 |
/// |
| 1446 | 1374 |
/// \relates NotMap |
| 1447 | 1375 |
template <typename M> |
| 1448 | 1376 |
inline NotMap<M> notMap(const M &m) {
|
| 1449 | 1377 |
return NotMap<M>(m); |
| 1450 | 1378 |
} |
| 1451 | 1379 |
|
| 1452 | 1380 |
/// Returns a \ref NotWriteMap class |
| 1453 | 1381 |
|
| 1454 | 1382 |
/// This function just returns a \ref NotWriteMap class. |
| 1455 | 1383 |
/// |
| 1456 | 1384 |
/// For example, if \c m is a map with \c bool values, then |
| 1457 | 1385 |
/// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1458 | 1386 |
/// Moreover it makes also possible to write the map. |
| 1459 | 1387 |
/// |
| 1460 | 1388 |
/// \relates NotWriteMap |
| 1461 | 1389 |
template <typename M> |
| 1462 | 1390 |
inline NotWriteMap<M> notWriteMap(M &m) {
|
| 1463 | 1391 |
return NotWriteMap<M>(m); |
| 1464 | 1392 |
} |
| 1465 | 1393 |
|
| 1466 |
|
|
| 1467 |
namespace _maps_bits {
|
|
| 1468 |
|
|
| 1469 |
template <typename Value> |
|
| 1470 |
struct Identity {
|
|
| 1471 |
typedef Value argument_type; |
|
| 1472 |
typedef Value result_type; |
|
| 1473 |
Value operator()(const Value& val) const {
|
|
| 1474 |
return val; |
|
| 1475 |
} |
|
| 1476 |
}; |
|
| 1477 |
|
|
| 1478 |
template <typename _Iterator, typename Enable = void> |
|
| 1479 |
struct IteratorTraits {
|
|
| 1480 |
typedef typename std::iterator_traits<_Iterator>::value_type Value; |
|
| 1481 |
}; |
|
| 1482 |
|
|
| 1483 |
template <typename _Iterator> |
|
| 1484 |
struct IteratorTraits<_Iterator, |
|
| 1485 |
typename exists<typename _Iterator::container_type>::type> |
|
| 1486 |
{
|
|
| 1487 |
typedef typename _Iterator::container_type::value_type Value; |
|
| 1488 |
}; |
|
| 1489 |
|
|
| 1490 |
} |
|
| 1491 |
|
|
| 1492 |
|
|
| 1493 |
/// \brief Writable bool map for logging each \c true assigned element |
|
| 1494 |
/// |
|
| 1495 |
/// A \ref concepts::ReadWriteMap "read-write" bool map for logging |
|
| 1496 |
/// each \c true assigned element, i.e it copies all the keys set |
|
| 1497 |
/// to \c true to the given iterator. |
|
| 1498 |
/// |
|
| 1499 |
/// \note The container of the iterator should contain space |
|
| 1500 |
/// for each element. |
|
| 1501 |
/// |
|
| 1502 |
/// The following example shows how you can write the edges found by |
|
| 1503 |
/// the \ref Prim algorithm directly to the standard output. |
|
| 1504 |
/// \code |
|
| 1505 |
/// typedef IdMap<Graph, Edge> EdgeIdMap; |
|
| 1506 |
/// EdgeIdMap edgeId(graph); |
|
| 1507 |
/// |
|
| 1508 |
/// typedef MapToFunctor<EdgeIdMap> EdgeIdFunctor; |
|
| 1509 |
/// EdgeIdFunctor edgeIdFunctor(edgeId); |
|
| 1510 |
/// |
|
| 1511 |
/// StoreBoolMap<ostream_iterator<int>, EdgeIdFunctor> |
|
| 1512 |
/// writerMap(ostream_iterator<int>(cout, " "), edgeIdFunctor); |
|
| 1513 |
/// |
|
| 1514 |
/// prim(graph, cost, writerMap); |
|
| 1515 |
/// \endcode |
|
| 1516 |
/// |
|
| 1517 |
/// \sa BackInserterBoolMap |
|
| 1518 |
/// \sa FrontInserterBoolMap |
|
| 1519 |
/// \sa InserterBoolMap |
|
| 1520 |
/// |
|
| 1521 |
/// \todo Revise the name of this class and the related ones. |
|
| 1522 |
template <typename _Iterator, |
|
| 1523 |
typename _Functor = |
|
| 1524 |
_maps_bits::Identity<typename _maps_bits:: |
|
| 1525 |
IteratorTraits<_Iterator>::Value> > |
|
| 1526 |
class StoreBoolMap {
|
|
| 1527 |
public: |
|
| 1528 |
typedef _Iterator Iterator; |
|
| 1529 |
|
|
| 1530 |
typedef typename _Functor::argument_type Key; |
|
| 1531 |
typedef bool Value; |
|
| 1532 |
|
|
| 1533 |
typedef _Functor Functor; |
|
| 1534 |
|
|
| 1535 |
/// Constructor |
|
| 1536 |
StoreBoolMap(Iterator it, const Functor& functor = Functor()) |
|
| 1537 |
: _begin(it), _end(it), _functor(functor) {}
|
|
| 1538 |
|
|
| 1539 |
/// Gives back the given iterator set for the first key |
|
| 1540 |
Iterator begin() const {
|
|
| 1541 |
return _begin; |
|
| 1542 |
} |
|
| 1543 |
|
|
| 1544 |
/// Gives back the the 'after the last' iterator |
|
| 1545 |
Iterator end() const {
|
|
| 1546 |
return _end; |
|
| 1547 |
} |
|
| 1548 |
|
|
| 1549 |
/// The set function of the map |
|
| 1550 |
void set(const Key& key, Value value) const {
|
|
| 1551 |
if (value) {
|
|
| 1552 |
*_end++ = _functor(key); |
|
| 1553 |
} |
|
| 1554 |
} |
|
| 1555 |
|
|
| 1556 |
private: |
|
| 1557 |
Iterator _begin; |
|
| 1558 |
mutable Iterator _end; |
|
| 1559 |
Functor _functor; |
|
| 1560 |
}; |
|
| 1561 |
|
|
| 1562 |
/// \brief Writable bool map for logging each \c true assigned element in |
|
| 1563 |
/// a back insertable container. |
|
| 1564 |
/// |
|
| 1565 |
/// Writable bool map for logging each \c true assigned element by pushing |
|
| 1566 |
/// them into a back insertable container. |
|
| 1567 |
/// It can be used to retrieve the items into a standard |
|
| 1568 |
/// container. The next example shows how you can store the |
|
| 1569 |
/// edges found by the Prim algorithm in a vector. |
|
| 1570 |
/// |
|
| 1571 |
/// \code |
|
| 1572 |
/// vector<Edge> span_tree_edges; |
|
| 1573 |
/// BackInserterBoolMap<vector<Edge> > inserter_map(span_tree_edges); |
|
| 1574 |
/// prim(graph, cost, inserter_map); |
|
| 1575 |
/// \endcode |
|
| 1576 |
/// |
|
| 1577 |
/// \sa StoreBoolMap |
|
| 1578 |
/// \sa FrontInserterBoolMap |
|
| 1579 |
/// \sa InserterBoolMap |
|
| 1580 |
template <typename Container, |
|
| 1581 |
typename Functor = |
|
| 1582 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1583 |
class BackInserterBoolMap {
|
|
| 1584 |
public: |
|
| 1585 |
typedef typename Functor::argument_type Key; |
|
| 1586 |
typedef bool Value; |
|
| 1587 |
|
|
| 1588 |
/// Constructor |
|
| 1589 |
BackInserterBoolMap(Container& _container, |
|
| 1590 |
const Functor& _functor = Functor()) |
|
| 1591 |
: container(_container), functor(_functor) {}
|
|
| 1592 |
|
|
| 1593 |
/// The set function of the map |
|
| 1594 |
void set(const Key& key, Value value) {
|
|
| 1595 |
if (value) {
|
|
| 1596 |
container.push_back(functor(key)); |
|
| 1597 |
} |
|
| 1598 |
} |
|
| 1599 |
|
|
| 1600 |
private: |
|
| 1601 |
Container& container; |
|
| 1602 |
Functor functor; |
|
| 1603 |
}; |
|
| 1604 |
|
|
| 1605 |
/// \brief Writable bool map for logging each \c true assigned element in |
|
| 1606 |
/// a front insertable container. |
|
| 1607 |
/// |
|
| 1608 |
/// Writable bool map for logging each \c true assigned element by pushing |
|
| 1609 |
/// them into a front insertable container. |
|
| 1610 |
/// It can be used to retrieve the items into a standard |
|
| 1611 |
/// container. For example see \ref BackInserterBoolMap. |
|
| 1612 |
/// |
|
| 1613 |
/// \sa BackInserterBoolMap |
|
| 1614 |
/// \sa InserterBoolMap |
|
| 1615 |
template <typename Container, |
|
| 1616 |
typename Functor = |
|
| 1617 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1618 |
class FrontInserterBoolMap {
|
|
| 1619 |
public: |
|
| 1620 |
typedef typename Functor::argument_type Key; |
|
| 1621 |
typedef bool Value; |
|
| 1622 |
|
|
| 1623 |
/// Constructor |
|
| 1624 |
FrontInserterBoolMap(Container& _container, |
|
| 1625 |
const Functor& _functor = Functor()) |
|
| 1626 |
: container(_container), functor(_functor) {}
|
|
| 1627 |
|
|
| 1628 |
/// The set function of the map |
|
| 1629 |
void set(const Key& key, Value value) {
|
|
| 1630 |
if (value) {
|
|
| 1631 |
container.push_front(functor(key)); |
|
| 1632 |
} |
|
| 1633 |
} |
|
| 1634 |
|
|
| 1635 |
private: |
|
| 1636 |
Container& container; |
|
| 1637 |
Functor functor; |
|
| 1638 |
}; |
|
| 1639 |
|
|
| 1640 |
/// \brief Writable bool map for storing each \c true assigned element in |
|
| 1641 |
/// an insertable container. |
|
| 1642 |
/// |
|
| 1643 |
/// Writable bool map for storing each \c true assigned element in an |
|
| 1644 |
/// insertable container. It will insert all the keys set to \c true into |
|
| 1645 |
/// the container. |
|
| 1646 |
/// |
|
| 1647 |
/// For example, if you want to store the cut arcs of the strongly |
|
| 1648 |
/// connected components in a set you can use the next code: |
|
| 1649 |
/// |
|
| 1650 |
/// \code |
|
| 1651 |
/// set<Arc> cut_arcs; |
|
| 1652 |
/// InserterBoolMap<set<Arc> > inserter_map(cut_arcs); |
|
| 1653 |
/// stronglyConnectedCutArcs(digraph, cost, inserter_map); |
|
| 1654 |
/// \endcode |
|
| 1655 |
/// |
|
| 1656 |
/// \sa BackInserterBoolMap |
|
| 1657 |
/// \sa FrontInserterBoolMap |
|
| 1658 |
template <typename Container, |
|
| 1659 |
typename Functor = |
|
| 1660 |
_maps_bits::Identity<typename Container::value_type> > |
|
| 1661 |
class InserterBoolMap {
|
|
| 1662 |
public: |
|
| 1663 |
typedef typename Container::value_type Key; |
|
| 1664 |
typedef bool Value; |
|
| 1665 |
|
|
| 1666 |
/// Constructor with specified iterator |
|
| 1667 |
|
|
| 1668 |
/// Constructor with specified iterator. |
|
| 1669 |
/// \param _container The container for storing the elements. |
|
| 1670 |
/// \param _it The elements will be inserted before this iterator. |
|
| 1671 |
/// \param _functor The functor that is used when an element is stored. |
|
| 1672 |
InserterBoolMap(Container& _container, typename Container::iterator _it, |
|
| 1673 |
const Functor& _functor = Functor()) |
|
| 1674 |
: container(_container), it(_it), functor(_functor) {}
|
|
| 1675 |
|
|
| 1676 |
/// Constructor |
|
| 1677 |
|
|
| 1678 |
/// Constructor without specified iterator. |
|
| 1679 |
/// The elements will be inserted before <tt>_container.end()</tt>. |
|
| 1680 |
/// \param _container The container for storing the elements. |
|
| 1681 |
/// \param _functor The functor that is used when an element is stored. |
|
| 1682 |
InserterBoolMap(Container& _container, const Functor& _functor = Functor()) |
|
| 1683 |
: container(_container), it(_container.end()), functor(_functor) {}
|
|
| 1684 |
|
|
| 1685 |
/// The set function of the map |
|
| 1686 |
void set(const Key& key, Value value) {
|
|
| 1687 |
if (value) {
|
|
| 1688 |
it = container.insert(it, functor(key)); |
|
| 1689 |
++it; |
|
| 1690 |
} |
|
| 1691 |
} |
|
| 1692 |
|
|
| 1693 |
private: |
|
| 1694 |
Container& container; |
|
| 1695 |
typename Container::iterator it; |
|
| 1696 |
Functor functor; |
|
| 1697 |
}; |
|
| 1698 |
|
|
| 1699 |
/// \brief Writable bool map for filling each \c true assigned element with a |
|
| 1700 |
/// given value. |
|
| 1701 |
/// |
|
| 1702 |
/// Writable bool map for filling each \c true assigned element with a |
|
| 1703 |
/// given value. The value can set the container. |
|
| 1704 |
/// |
|
| 1705 |
/// The following code finds the connected components of a graph |
|
| 1706 |
/// and stores it in the \c comp map: |
|
| 1707 |
/// \code |
|
| 1708 |
/// typedef Graph::NodeMap<int> ComponentMap; |
|
| 1709 |
/// ComponentMap comp(graph); |
|
| 1710 |
/// typedef FillBoolMap<Graph::NodeMap<int> > ComponentFillerMap; |
|
| 1711 |
/// ComponentFillerMap filler(comp, 0); |
|
| 1712 |
/// |
|
| 1713 |
/// Dfs<Graph>::DefProcessedMap<ComponentFillerMap>::Create dfs(graph); |
|
| 1714 |
/// dfs.processedMap(filler); |
|
| 1715 |
/// dfs.init(); |
|
| 1716 |
/// for (NodeIt it(graph); it != INVALID; ++it) {
|
|
| 1717 |
/// if (!dfs.reached(it)) {
|
|
| 1718 |
/// dfs.addSource(it); |
|
| 1719 |
/// dfs.start(); |
|
| 1720 |
/// ++filler.fillValue(); |
|
| 1721 |
/// } |
|
| 1722 |
/// } |
|
| 1723 |
/// \endcode |
|
| 1724 |
template <typename Map> |
|
| 1725 |
class FillBoolMap {
|
|
| 1726 |
public: |
|
| 1727 |
typedef typename Map::Key Key; |
|
| 1728 |
typedef bool Value; |
|
| 1729 |
|
|
| 1730 |
/// Constructor |
|
| 1731 |
FillBoolMap(Map& _map, const typename Map::Value& _fill) |
|
| 1732 |
: map(_map), fill(_fill) {}
|
|
| 1733 |
|
|
| 1734 |
/// Constructor |
|
| 1735 |
FillBoolMap(Map& _map) |
|
| 1736 |
: map(_map), fill() {}
|
|
| 1737 |
|
|
| 1738 |
/// Gives back the current fill value |
|
| 1739 |
const typename Map::Value& fillValue() const {
|
|
| 1740 |
return fill; |
|
| 1741 |
} |
|
| 1742 |
|
|
| 1743 |
/// Gives back the current fill value |
|
| 1744 |
typename Map::Value& fillValue() {
|
|
| 1745 |
return fill; |
|
| 1746 |
} |
|
| 1747 |
|
|
| 1748 |
/// Sets the current fill value |
|
| 1749 |
void fillValue(const typename Map::Value& _fill) {
|
|
| 1750 |
fill = _fill; |
|
| 1751 |
} |
|
| 1752 |
|
|
| 1753 |
/// The set function of the map |
|
| 1754 |
void set(const Key& key, Value value) {
|
|
| 1755 |
if (value) {
|
|
| 1756 |
map.set(key, fill); |
|
| 1757 |
} |
|
| 1758 |
} |
|
| 1759 |
|
|
| 1760 |
private: |
|
| 1761 |
Map& map; |
|
| 1762 |
typename Map::Value fill; |
|
| 1763 |
}; |
|
| 1764 |
|
|
| 1765 |
|
|
| 1766 |
/// \brief Writable bool map for storing the sequence number of |
|
| 1767 |
/// \c true assignments. |
|
| 1768 |
/// |
|
| 1769 |
/// Writable bool map that stores for each \c true assigned elements |
|
| 1770 |
/// the sequence number of this setting. |
|
| 1771 |
/// It makes it easy to calculate the leaving |
|
| 1772 |
/// order of the nodes in the \ref Dfs algorithm. |
|
| 1773 |
/// |
|
| 1774 |
/// \code |
|
| 1775 |
/// typedef Digraph::NodeMap<int> OrderMap; |
|
| 1776 |
/// OrderMap order(digraph); |
|
| 1777 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
|
| 1778 |
/// OrderSetterMap setter(order); |
|
| 1779 |
/// Dfs<Digraph>::DefProcessedMap<OrderSetterMap>::Create dfs(digraph); |
|
| 1780 |
/// dfs.processedMap(setter); |
|
| 1781 |
/// dfs.init(); |
|
| 1782 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
|
| 1783 |
/// if (!dfs.reached(it)) {
|
|
| 1784 |
/// dfs.addSource(it); |
|
| 1785 |
/// dfs.start(); |
|
| 1786 |
/// } |
|
| 1787 |
/// } |
|
| 1788 |
/// \endcode |
|
| 1789 |
/// |
|
| 1790 |
/// The storing of the discovering order is more difficult because the |
|
| 1791 |
/// ReachedMap should be readable in the dfs algorithm but the setting |
|
| 1792 |
/// order map is not readable. Thus we must use the fork map: |
|
| 1793 |
/// |
|
| 1794 |
/// \code |
|
| 1795 |
/// typedef Digraph::NodeMap<int> OrderMap; |
|
| 1796 |
/// OrderMap order(digraph); |
|
| 1797 |
/// typedef SettingOrderBoolMap<OrderMap> OrderSetterMap; |
|
| 1798 |
/// OrderSetterMap setter(order); |
|
| 1799 |
/// typedef Digraph::NodeMap<bool> StoreMap; |
|
| 1800 |
/// StoreMap store(digraph); |
|
| 1801 |
/// |
|
| 1802 |
/// typedef ForkMap<StoreMap, OrderSetterMap> ReachedMap; |
|
| 1803 |
/// ReachedMap reached(store, setter); |
|
| 1804 |
/// |
|
| 1805 |
/// Dfs<Digraph>::DefReachedMap<ReachedMap>::Create dfs(digraph); |
|
| 1806 |
/// dfs.reachedMap(reached); |
|
| 1807 |
/// dfs.init(); |
|
| 1808 |
/// for (NodeIt it(digraph); it != INVALID; ++it) {
|
|
| 1809 |
/// if (!dfs.reached(it)) {
|
|
| 1810 |
/// dfs.addSource(it); |
|
| 1811 |
/// dfs.start(); |
|
| 1812 |
/// } |
|
| 1813 |
/// } |
|
| 1814 |
/// \endcode |
|
| 1815 |
template <typename Map> |
|
| 1816 |
class SettingOrderBoolMap {
|
|
| 1817 |
public: |
|
| 1818 |
typedef typename Map::Key Key; |
|
| 1819 |
typedef bool Value; |
|
| 1820 |
|
|
| 1821 |
/// Constructor |
|
| 1822 |
SettingOrderBoolMap(Map& _map) |
|
| 1823 |
: map(_map), counter(0) {}
|
|
| 1824 |
|
|
| 1825 |
/// Number of set operations. |
|
| 1826 |
int num() const {
|
|
| 1827 |
return counter; |
|
| 1828 |
} |
|
| 1829 |
|
|
| 1830 |
/// The set function of the map |
|
| 1831 |
void set(const Key& key, Value value) {
|
|
| 1832 |
if (value) {
|
|
| 1833 |
map.set(key, counter++); |
|
| 1834 |
} |
|
| 1835 |
} |
|
| 1836 |
|
|
| 1837 |
private: |
|
| 1838 |
Map& map; |
|
| 1839 |
int counter; |
|
| 1840 |
}; |
|
| 1841 |
|
|
| 1842 | 1394 |
/// @} |
| 1843 | 1395 |
} |
| 1844 | 1396 |
|
| 1845 | 1397 |
#endif // LEMON_MAPS_H |
0 comments (0 inline)