Changeset 510:72143568cadc in lemon-0.x for src/work/marci/bipartite_graph_wrapper.h
- Timestamp:
- 05/03/04 12:04:27 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@670
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/bipartite_graph_wrapper.h
r502 r510 311 311 //invalid, 3, invalid) 312 312 template <typename T> class NodeMap; 313 template <typename T , typename Parent> class EdgeMap;313 template <typename T> class EdgeMap; 314 314 315 315 // template <typename T> friend class NodeMap; … … 386 386 friend class GraphWrapper<Graph>; 387 387 friend class stGraphWrapper<Graph>; 388 template <typename T , typename Parent> friend class EdgeMap;388 template <typename T> friend class EdgeMap; 389 389 int spec; 390 390 typename Graph::Node n; … … 413 413 friend std::ostream& operator<< (std::ostream& os, const Edge& i); 414 414 int getSpec() const { return spec; } 415 typename Graph::Node getNode() const { return n; } 415 416 }; 416 417 … … 703 704 template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 704 705 typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent; 706 protected: 705 707 T s_value, t_value; 706 708 public: … … 715 717 case 0: 716 718 return Parent::operator[](n); 717 break;718 719 case 1: 719 720 return s_value; 720 break;721 721 case 2: 722 722 default: 723 723 return t_value; 724 break;725 724 } 726 725 } … … 741 740 }; 742 741 743 template<typename T, 744 typename Parent= 745 typename GraphWrapper<Graph>::template EdgeMap<T> > 746 class EdgeMap : public Parent { 747 //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent; 742 /// This class is to wrap a node-map of \c Graph and two variables 743 /// storing values for \c S_NODE and \c T_NODE to a node-map of 744 /// stGraphWrapper<Graph>. 745 template<typename NM> class NodeMapWrapper { 746 public: 747 typedef Node KeyType; 748 typedef typename NM::ValueType ValueType; 749 protected: 750 NM* nm; 751 ValueType* s_value, t_value; 752 public: 753 NodeMapWrapper(NM& _nm, ValueType& _s_value, ValueType& _t_value) : 754 nm(&_nm), s_value(&_s_value), t_value(&_t_value) { } 755 ValueType operator[](const Node& n) const { 756 switch (n.getSpec()) { 757 case 0: 758 return (*nm)[n]; 759 case 1: 760 return *s_value; 761 case 2: 762 default: 763 return *t_value; 764 } 765 } 766 void set(const Node& n, ValueType t) { 767 switch (n.getSpec()) { 768 case 0: 769 nm->set(n, t); 770 break; 771 case 1: 772 *s_value=t; 773 break; 774 case 2: 775 default: 776 *t_value=t; 777 break; 778 } 779 } 780 }; 781 782 template<typename T> 783 class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 784 typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent; 785 protected: 748 786 typename GraphWrapper<Graph>::template NodeMap<T> node_value; 749 787 public: … … 756 794 case 0: 757 795 return Parent::operator[](e); 758 break;759 796 case 1: 760 797 return node_value[e.n]; 761 break;762 798 case 2: 763 799 default: 764 800 return node_value[e.n]; 765 break;766 801 } 767 802 } … … 782 817 }; 783 818 784 // template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 785 // typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent; 786 // typename GraphWrapper<Graph>::template NodeMap<T> node_value; 787 // public: 788 // EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 789 // node_value(_G) { } 790 // EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 791 // node_value(_G, a) { } 792 // T operator[](const Edge& e) const { 793 // switch (e.spec) { 794 // case 0: 795 // return Parent::operator[](e); 796 // break; 797 // case 1: 798 // return node_value[e.n]; 799 // break; 800 // case 2: 801 // default: 802 // return node_value[e.n]; 803 // break; 804 // } 805 // } 806 // void set(const Edge& e, T t) { 807 // switch (e.spec) { 808 // case 0: 809 // GraphWrapper<Graph>::template EdgeMap<T>::set(e, t); 810 // break; 811 // case 1: 812 // node_value.set(e.n, t); 813 // break; 814 // case 2: 815 // default: 816 // node_value.set(e.n, t); 817 // break; 818 // } 819 // } 820 // }; 819 /// This class is to wrap an edge-map and a node-map of \c Graph 820 /// to an edge-map of stGraphWrapper<Graph>. 821 template<typename EM, typename NM> 822 class EdgeMapWrapper { 823 public: 824 typedef Edge KeyType; 825 typedef typename EM::ValueType ValueType; 826 protected: 827 EM* em; 828 NM* nm; 829 public: 830 EdgeMapWrapper(EM& _em, NM& _nm) : em(&_em), nm(&_nm) { } 831 ValueType operator[](const Edge& e) const { 832 switch (e.getSpec()) { 833 case 0: 834 return (*em)[e]; 835 case 1: 836 return (*nm)[e.getNode()]; 837 case 2: 838 default: 839 return (*nm)[e.getNode()]; 840 } 841 } 842 void set(const Edge& e, ValueType t) { 843 switch (e.getSpec()) { 844 case 0: 845 em->set(e, t); 846 break; 847 case 1: 848 nm->set(e.getNode(), t); 849 break; 850 case 2: 851 default: 852 nm->set(e.getNode(), t); 853 break; 854 } 855 } 856 }; 857 821 858 822 859 // template<typename G> … … 841 878 842 879 843 #endif //HUGO_ GRAPH_WRAPPER_H844 880 #endif //HUGO_BIPARTITE_GRAPH_WRAPPER_H 881
Note: See TracChangeset
for help on using the changeset viewer.