1.1 --- a/src/work/marci/bipartite_graph_wrapper.h Mon May 03 09:44:00 2004 +0000
1.2 +++ b/src/work/marci/bipartite_graph_wrapper.h Mon May 03 10:04:27 2004 +0000
1.3 @@ -310,7 +310,7 @@
1.4 //(invalid, 2, vmi)
1.5 //invalid, 3, invalid)
1.6 template <typename T> class NodeMap;
1.7 - template <typename T, typename Parent> class EdgeMap;
1.8 + template <typename T> class EdgeMap;
1.9
1.10 // template <typename T> friend class NodeMap;
1.11 // template <typename T> friend class EdgeMap;
1.12 @@ -385,7 +385,7 @@
1.13 class Edge : public Graph::Edge {
1.14 friend class GraphWrapper<Graph>;
1.15 friend class stGraphWrapper<Graph>;
1.16 - template <typename T, typename Parent> friend class EdgeMap;
1.17 + template <typename T> friend class EdgeMap;
1.18 int spec;
1.19 typename Graph::Node n;
1.20 public:
1.21 @@ -412,6 +412,7 @@
1.22 // operator<<(std::ostream& os, const typename stGraphWrapper<G>::Edge& i);
1.23 friend std::ostream& operator<< (std::ostream& os, const Edge& i);
1.24 int getSpec() const { return spec; }
1.25 + typename Graph::Node getNode() const { return n; }
1.26 };
1.27
1.28 class OutEdgeIt {
1.29 @@ -702,6 +703,7 @@
1.30
1.31 template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> {
1.32 typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
1.33 + protected:
1.34 T s_value, t_value;
1.35 public:
1.36 NodeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
1.37 @@ -714,14 +716,11 @@
1.38 switch (n.spec) {
1.39 case 0:
1.40 return Parent::operator[](n);
1.41 - break;
1.42 case 1:
1.43 return s_value;
1.44 - break;
1.45 case 2:
1.46 default:
1.47 return t_value;
1.48 - break;
1.49 }
1.50 }
1.51 void set(const Node& n, T t) {
1.52 @@ -740,11 +739,50 @@
1.53 }
1.54 };
1.55
1.56 - template<typename T,
1.57 - typename Parent=
1.58 - typename GraphWrapper<Graph>::template EdgeMap<T> >
1.59 - class EdgeMap : public Parent {
1.60 - //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
1.61 + /// This class is to wrap a node-map of \c Graph and two variables
1.62 + /// storing values for \c S_NODE and \c T_NODE to a node-map of
1.63 + /// stGraphWrapper<Graph>.
1.64 + template<typename NM> class NodeMapWrapper {
1.65 + public:
1.66 + typedef Node KeyType;
1.67 + typedef typename NM::ValueType ValueType;
1.68 + protected:
1.69 + NM* nm;
1.70 + ValueType* s_value, t_value;
1.71 + public:
1.72 + NodeMapWrapper(NM& _nm, ValueType& _s_value, ValueType& _t_value) :
1.73 + nm(&_nm), s_value(&_s_value), t_value(&_t_value) { }
1.74 + ValueType operator[](const Node& n) const {
1.75 + switch (n.getSpec()) {
1.76 + case 0:
1.77 + return (*nm)[n];
1.78 + case 1:
1.79 + return *s_value;
1.80 + case 2:
1.81 + default:
1.82 + return *t_value;
1.83 + }
1.84 + }
1.85 + void set(const Node& n, ValueType t) {
1.86 + switch (n.getSpec()) {
1.87 + case 0:
1.88 + nm->set(n, t);
1.89 + break;
1.90 + case 1:
1.91 + *s_value=t;
1.92 + break;
1.93 + case 2:
1.94 + default:
1.95 + *t_value=t;
1.96 + break;
1.97 + }
1.98 + }
1.99 + };
1.100 +
1.101 + template<typename T>
1.102 + class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> {
1.103 + typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
1.104 + protected:
1.105 typename GraphWrapper<Graph>::template NodeMap<T> node_value;
1.106 public:
1.107 EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
1.108 @@ -755,14 +793,11 @@
1.109 switch (e.spec) {
1.110 case 0:
1.111 return Parent::operator[](e);
1.112 - break;
1.113 case 1:
1.114 return node_value[e.n];
1.115 - break;
1.116 case 2:
1.117 default:
1.118 return node_value[e.n];
1.119 - break;
1.120 }
1.121 }
1.122 void set(const Edge& e, T t) {
1.123 @@ -781,43 +816,45 @@
1.124 }
1.125 };
1.126
1.127 -// template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> {
1.128 -// typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
1.129 -// typename GraphWrapper<Graph>::template NodeMap<T> node_value;
1.130 -// public:
1.131 -// EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
1.132 -// node_value(_G) { }
1.133 -// EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a),
1.134 -// node_value(_G, a) { }
1.135 -// T operator[](const Edge& e) const {
1.136 -// switch (e.spec) {
1.137 -// case 0:
1.138 -// return Parent::operator[](e);
1.139 -// break;
1.140 -// case 1:
1.141 -// return node_value[e.n];
1.142 -// break;
1.143 -// case 2:
1.144 -// default:
1.145 -// return node_value[e.n];
1.146 -// break;
1.147 -// }
1.148 -// }
1.149 -// void set(const Edge& e, T t) {
1.150 -// switch (e.spec) {
1.151 -// case 0:
1.152 -// GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
1.153 -// break;
1.154 -// case 1:
1.155 -// node_value.set(e.n, t);
1.156 -// break;
1.157 -// case 2:
1.158 -// default:
1.159 -// node_value.set(e.n, t);
1.160 -// break;
1.161 -// }
1.162 -// }
1.163 -// };
1.164 + /// This class is to wrap an edge-map and a node-map of \c Graph
1.165 + /// to an edge-map of stGraphWrapper<Graph>.
1.166 + template<typename EM, typename NM>
1.167 + class EdgeMapWrapper {
1.168 + public:
1.169 + typedef Edge KeyType;
1.170 + typedef typename EM::ValueType ValueType;
1.171 + protected:
1.172 + EM* em;
1.173 + NM* nm;
1.174 + public:
1.175 + EdgeMapWrapper(EM& _em, NM& _nm) : em(&_em), nm(&_nm) { }
1.176 + ValueType operator[](const Edge& e) const {
1.177 + switch (e.getSpec()) {
1.178 + case 0:
1.179 + return (*em)[e];
1.180 + case 1:
1.181 + return (*nm)[e.getNode()];
1.182 + case 2:
1.183 + default:
1.184 + return (*nm)[e.getNode()];
1.185 + }
1.186 + }
1.187 + void set(const Edge& e, ValueType t) {
1.188 + switch (e.getSpec()) {
1.189 + case 0:
1.190 + em->set(e, t);
1.191 + break;
1.192 + case 1:
1.193 + nm->set(e.getNode(), t);
1.194 + break;
1.195 + case 2:
1.196 + default:
1.197 + nm->set(e.getNode(), t);
1.198 + break;
1.199 + }
1.200 + }
1.201 + };
1.202 +
1.203
1.204 // template<typename G>
1.205 friend std::ostream&
1.206 @@ -840,5 +877,5 @@
1.207 } //namespace hugo
1.208
1.209
1.210 -#endif //HUGO_GRAPH_WRAPPER_H
1.211 +#endif //HUGO_BIPARTITE_GRAPH_WRAPPER_H
1.212