1.1 --- a/src/work/iterator_bfs_demo.cc Mon Mar 22 17:05:08 2004 +0000
1.2 +++ b/src/work/iterator_bfs_demo.cc Mon Mar 22 17:27:20 2004 +0000
1.3 @@ -244,7 +244,8 @@
1.4 }
1.5
1.6 {
1.7 - typedef UndirGraphWrapper<const Graph> GW;
1.8 + //typedef UndirGraphWrapper<const Graph> GW;
1.9 + typedef UndirGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
1.10 GW gw(G);
1.11
1.12 EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
2.1 --- a/src/work/marci/graph_wrapper.h Mon Mar 22 17:05:08 2004 +0000
2.2 +++ b/src/work/marci/graph_wrapper.h Mon Mar 22 17:27:20 2004 +0000
2.3 @@ -336,16 +336,176 @@
2.4 };
2.5
2.6
2.7 - template<typename Graph>
2.8 +
2.9 +// template<typename Graph>
2.10 +// class UndirGraphWrapper {
2.11 +// protected:
2.12 +// Graph* graph;
2.13 +
2.14 +// public:
2.15 +// typedef Graph BaseGraph;
2.16 +
2.17 +// typedef typename Graph::Node Node;
2.18 +// typedef typename Graph::NodeIt NodeIt;
2.19 +
2.20 +// //typedef typename Graph::Edge Edge;
2.21 +// //typedef typename Graph::OutEdgeIt OutEdgeIt;
2.22 +// //typedef typename Graph::InEdgeIt InEdgeIt;
2.23 +// //typedef typename Graph::SymEdgeIt SymEdgeIt;
2.24 +// //typedef typename Graph::EdgeIt EdgeIt;
2.25 +
2.26 +// //private:
2.27 +// typedef typename Graph::Edge GraphEdge;
2.28 +// typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
2.29 +// typedef typename Graph::InEdgeIt GraphInEdgeIt;
2.30 +// //public:
2.31 +
2.32 +// //UndirGraphWrapper() : graph(0) { }
2.33 +// UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
2.34 +
2.35 +// void setGraph(Graph& _graph) { graph = &_graph; }
2.36 +// Graph& getGraph() const { return (*graph); }
2.37 +
2.38 +// class Edge {
2.39 +// friend class UndirGraphWrapper<Graph>;
2.40 +// bool out_or_in; //true iff out
2.41 +// GraphOutEdgeIt out;
2.42 +// GraphInEdgeIt in;
2.43 +// public:
2.44 +// Edge() : out_or_in(), out(), in() { }
2.45 +// Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
2.46 +// operator GraphEdge() const {
2.47 +// if (out_or_in) return(out); else return(in);
2.48 +// }
2.49 +// friend bool operator==(const Edge& u, const Edge& v) {
2.50 +// if (v.out_or_in)
2.51 +// return (u.out_or_in && u.out==v.out);
2.52 +// else
2.53 +// return (!u.out_or_in && u.in==v.in);
2.54 +// }
2.55 +// friend bool operator!=(const Edge& u, const Edge& v) {
2.56 +// if (v.out_or_in)
2.57 +// return (!u.out_or_in || u.out!=v.out);
2.58 +// else
2.59 +// return (u.out_or_in || u.in!=v.in);
2.60 +// }
2.61 +// };
2.62 +
2.63 +// class OutEdgeIt : public Edge {
2.64 +// friend class UndirGraphWrapper<Graph>;
2.65 +// public:
2.66 +// OutEdgeIt() : Edge() { }
2.67 +// OutEdgeIt(const Invalid& i) : Edge(i) { }
2.68 +// OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
2.69 +// out_or_in=true;
2.70 +// _G.graph->first(out, n);
2.71 +// if (!(_G.graph->valid(out))) {
2.72 +// out_or_in=false;
2.73 +// _G.graph->first(in, n);
2.74 +// }
2.75 +// }
2.76 +// };
2.77 +
2.78 +// OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
2.79 +// e.out_or_in=true;
2.80 +// graph->first(e.out, n);
2.81 +// if (!(graph->valid(e.out))) {
2.82 +// e.out_or_in=false;
2.83 +// graph->first(e.in, n);
2.84 +// }
2.85 +// return e;
2.86 +// }
2.87 +
2.88 +// OutEdgeIt& next(OutEdgeIt& e) const {
2.89 +// if (e.out_or_in) {
2.90 +// Node n=graph->tail(e.out);
2.91 +// graph->next(e.out);
2.92 +// if (!graph->valid(e.out)) {
2.93 +// e.out_or_in=false;
2.94 +// graph->first(e.in, n);
2.95 +// }
2.96 +// } else {
2.97 +// graph->next(e.in);
2.98 +// }
2.99 +// return e;
2.100 +// }
2.101 +
2.102 +// Node aNode(const OutEdgeIt& e) const {
2.103 +// if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
2.104 +// Node bNode(const OutEdgeIt& e) const {
2.105 +// if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
2.106 +
2.107 +// typedef OutEdgeIt InEdgeIt;
2.108 +
2.109 +// template<typename I> I& first(I& i) const { return graph->first(i); }
2.110 +// // template<typename I, typename P> I& first(I& i, const P& p) const {
2.111 +// // return graph->first(i, p); }
2.112 +
2.113 +// template<typename I> I getNext(const I& i) const {
2.114 +// return graph->getNext(i); }
2.115 +// template<typename I> I& next(I &i) const { return graph->next(i); }
2.116 +
2.117 +// template< typename It > It first() const {
2.118 +// It e; first(e); return e; }
2.119 +
2.120 +// template< typename It > It first(const Node& v) const {
2.121 +// It e; first(e, v); return e; }
2.122 +
2.123 +// Node head(const Edge& e) const { return graph->head(e); }
2.124 +// Node tail(const Edge& e) const { return graph->tail(e); }
2.125 +
2.126 +// template<typename I> bool valid(const I& i) const
2.127 +// { return graph->valid(i); }
2.128 +
2.129 +// //template<typename I> void setInvalid(const I &i);
2.130 +// //{ return graph->setInvalid(i); }
2.131 +
2.132 +// int nodeNum() const { return graph->nodeNum(); }
2.133 +// int edgeNum() const { return graph->edgeNum(); }
2.134 +
2.135 +// // template<typename I> Node aNode(const I& e) const {
2.136 +// // return graph->aNode(e); }
2.137 +// // template<typename I> Node bNode(const I& e) const {
2.138 +// // return graph->bNode(e); }
2.139 +
2.140 +// Node addNode() const { return graph->addNode(); }
2.141 +// // FIXME: ez igy nem jo, mert nem
2.142 +// // Edge addEdge(const Node& tail, const Node& head) const {
2.143 +// // return graph->addEdge(tail, head); }
2.144 +
2.145 +// template<typename I> void erase(const I& i) const { graph->erase(i); }
2.146 +
2.147 +// void clear() const { graph->clear(); }
2.148 +
2.149 +// template<typename T> class NodeMap : public Graph::NodeMap<T> {
2.150 +// public:
2.151 +// NodeMap(const UndirGraphWrapper<Graph>& _G) :
2.152 +// Graph::NodeMap<T>(_G.getGraph()) { }
2.153 +// NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
2.154 +// Graph::NodeMap<T>(_G.getGraph(), a) { }
2.155 +// };
2.156 +
2.157 +// template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
2.158 +// public:
2.159 +// EdgeMap(const UndirGraphWrapper<Graph>& _G) :
2.160 +// Graph::EdgeMap<T>(_G.getGraph()) { }
2.161 +// EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
2.162 +// Graph::EdgeMap<T>(_G.getGraph(), a) { }
2.163 +// };
2.164 +// };
2.165 +
2.166 +
2.167 + template<typename GraphWrapper>
2.168 class UndirGraphWrapper {
2.169 protected:
2.170 - Graph* graph;
2.171 -
2.172 + //Graph* graph;
2.173 + GraphWrapper gw;
2.174 +
2.175 public:
2.176 - typedef Graph BaseGraph;
2.177 + typedef GraphWrapper BaseGraph;
2.178
2.179 - typedef typename Graph::Node Node;
2.180 - typedef typename Graph::NodeIt NodeIt;
2.181 + typedef typename GraphWrapper::Node Node;
2.182 + typedef typename GraphWrapper::NodeIt NodeIt;
2.183
2.184 //typedef typename Graph::Edge Edge;
2.185 //typedef typename Graph::OutEdgeIt OutEdgeIt;
2.186 @@ -354,19 +514,19 @@
2.187 //typedef typename Graph::EdgeIt EdgeIt;
2.188
2.189 //private:
2.190 - typedef typename Graph::Edge GraphEdge;
2.191 - typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
2.192 - typedef typename Graph::InEdgeIt GraphInEdgeIt;
2.193 + typedef typename GraphWrapper::Edge GraphEdge;
2.194 + typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
2.195 + typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
2.196 //public:
2.197
2.198 //UndirGraphWrapper() : graph(0) { }
2.199 - UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
2.200 + UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
2.201
2.202 - void setGraph(Graph& _graph) { graph = &_graph; }
2.203 - Graph& getGraph() const { return (*graph); }
2.204 + //void setGraph(Graph& _graph) { graph = &_graph; }
2.205 + //Graph& getGraph() const { return (*graph); }
2.206
2.207 class Edge {
2.208 - friend class UndirGraphWrapper<Graph>;
2.209 + friend class UndirGraphWrapper<GraphWrapper>;
2.210 bool out_or_in; //true iff out
2.211 GraphOutEdgeIt out;
2.212 GraphInEdgeIt in;
2.213 @@ -391,58 +551,59 @@
2.214 };
2.215
2.216 class OutEdgeIt : public Edge {
2.217 - friend class UndirGraphWrapper<Graph>;
2.218 + friend class UndirGraphWrapper<GraphWrapper>;
2.219 public:
2.220 OutEdgeIt() : Edge() { }
2.221 OutEdgeIt(const Invalid& i) : Edge(i) { }
2.222 - OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
2.223 + OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
2.224 + : Edge() {
2.225 out_or_in=true;
2.226 - _G.graph->first(out, n);
2.227 - if (!(_G.graph->valid(out))) {
2.228 + _G.gw.first(out, n);
2.229 + if (!(_G.gw.valid(out))) {
2.230 out_or_in=false;
2.231 - _G.graph->first(in, n);
2.232 + _G.gw.first(in, n);
2.233 }
2.234 }
2.235 };
2.236
2.237 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
2.238 e.out_or_in=true;
2.239 - graph->first(e.out, n);
2.240 - if (!(graph->valid(e.out))) {
2.241 + gw.first(e.out, n);
2.242 + if (!(gw.valid(e.out))) {
2.243 e.out_or_in=false;
2.244 - graph->first(e.in, n);
2.245 + gw.first(e.in, n);
2.246 }
2.247 return e;
2.248 }
2.249
2.250 OutEdgeIt& next(OutEdgeIt& e) const {
2.251 if (e.out_or_in) {
2.252 - Node n=graph->tail(e.out);
2.253 - graph->next(e.out);
2.254 - if (!graph->valid(e.out)) {
2.255 + Node n=gw.tail(e.out);
2.256 + gw.next(e.out);
2.257 + if (!gw.valid(e.out)) {
2.258 e.out_or_in=false;
2.259 - graph->first(e.in, n);
2.260 + gw.first(e.in, n);
2.261 }
2.262 } else {
2.263 - graph->next(e.in);
2.264 + gw.next(e.in);
2.265 }
2.266 return e;
2.267 }
2.268
2.269 Node aNode(const OutEdgeIt& e) const {
2.270 - if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
2.271 + if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
2.272 Node bNode(const OutEdgeIt& e) const {
2.273 - if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
2.274 + if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
2.275
2.276 typedef OutEdgeIt InEdgeIt;
2.277
2.278 - template<typename I> I& first(I& i) const { return graph->first(i); }
2.279 + template<typename I> I& first(I& i) const { return gw.first(i); }
2.280 // template<typename I, typename P> I& first(I& i, const P& p) const {
2.281 // return graph->first(i, p); }
2.282
2.283 template<typename I> I getNext(const I& i) const {
2.284 - return graph->getNext(i); }
2.285 - template<typename I> I& next(I &i) const { return graph->next(i); }
2.286 + return gw.getNext(i); }
2.287 + template<typename I> I& next(I &i) const { return gw.next(i); }
2.288
2.289 template< typename It > It first() const {
2.290 It e; first(e); return e; }
2.291 @@ -450,51 +611,53 @@
2.292 template< typename It > It first(const Node& v) const {
2.293 It e; first(e, v); return e; }
2.294
2.295 - Node head(const Edge& e) const { return graph->head(e); }
2.296 - Node tail(const Edge& e) const { return graph->tail(e); }
2.297 + Node head(const Edge& e) const { return gw.head(e); }
2.298 + Node tail(const Edge& e) const { return gw.tail(e); }
2.299
2.300 template<typename I> bool valid(const I& i) const
2.301 - { return graph->valid(i); }
2.302 + { return gw.valid(i); }
2.303
2.304 //template<typename I> void setInvalid(const I &i);
2.305 //{ return graph->setInvalid(i); }
2.306
2.307 - int nodeNum() const { return graph->nodeNum(); }
2.308 - int edgeNum() const { return graph->edgeNum(); }
2.309 + int nodeNum() const { return gw.nodeNum(); }
2.310 + int edgeNum() const { return gw.edgeNum(); }
2.311
2.312 // template<typename I> Node aNode(const I& e) const {
2.313 // return graph->aNode(e); }
2.314 // template<typename I> Node bNode(const I& e) const {
2.315 // return graph->bNode(e); }
2.316
2.317 - Node addNode() const { return graph->addNode(); }
2.318 + Node addNode() const { return gw.addNode(); }
2.319 // FIXME: ez igy nem jo, mert nem
2.320 // Edge addEdge(const Node& tail, const Node& head) const {
2.321 // return graph->addEdge(tail, head); }
2.322
2.323 - template<typename I> void erase(const I& i) const { graph->erase(i); }
2.324 + template<typename I> void erase(const I& i) const { gw.erase(i); }
2.325
2.326 - void clear() const { graph->clear(); }
2.327 + void clear() const { gw.clear(); }
2.328
2.329 - template<typename T> class NodeMap : public Graph::NodeMap<T> {
2.330 + template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
2.331 public:
2.332 - NodeMap(const UndirGraphWrapper<Graph>& _G) :
2.333 - Graph::NodeMap<T>(_G.getGraph()) { }
2.334 - NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
2.335 - Graph::NodeMap<T>(_G.getGraph(), a) { }
2.336 + NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
2.337 + GraphWrapper::NodeMap<T>(_G.gw) { }
2.338 + NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
2.339 + GraphWrapper::NodeMap<T>(_G.gw, a) { }
2.340 };
2.341
2.342 - template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
2.343 + template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
2.344 public:
2.345 - EdgeMap(const UndirGraphWrapper<Graph>& _G) :
2.346 - Graph::EdgeMap<T>(_G.getGraph()) { }
2.347 - EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
2.348 - Graph::EdgeMap<T>(_G.getGraph(), a) { }
2.349 + EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
2.350 + GraphWrapper::EdgeMap<T>(_G.gw) { }
2.351 + EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
2.352 + GraphWrapper::EdgeMap<T>(_G.gw, a) { }
2.353 };
2.354 };
2.355
2.356
2.357
2.358 +
2.359 +
2.360 // template<typename Graph>
2.361 // class SymGraphWrapper
2.362 // {