Changeset 236:ea3de9530ee8 in lemon-0.x for src
- Timestamp:
- 03/22/04 18:27:20 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@333
- Location:
- src/work
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/iterator_bfs_demo.cc
r234 r236 245 245 246 246 { 247 typedef UndirGraphWrapper<const Graph> GW; 247 //typedef UndirGraphWrapper<const Graph> GW; 248 typedef UndirGraphWrapper<const TrivGraphWrapper<const Graph> > GW; 248 249 GW gw(G); 249 250 -
src/work/marci/graph_wrapper.h
r235 r236 337 337 338 338 339 template<typename Graph> 339 340 // template<typename Graph> 341 // class UndirGraphWrapper { 342 // protected: 343 // Graph* graph; 344 345 // public: 346 // typedef Graph BaseGraph; 347 348 // typedef typename Graph::Node Node; 349 // typedef typename Graph::NodeIt NodeIt; 350 351 // //typedef typename Graph::Edge Edge; 352 // //typedef typename Graph::OutEdgeIt OutEdgeIt; 353 // //typedef typename Graph::InEdgeIt InEdgeIt; 354 // //typedef typename Graph::SymEdgeIt SymEdgeIt; 355 // //typedef typename Graph::EdgeIt EdgeIt; 356 357 // //private: 358 // typedef typename Graph::Edge GraphEdge; 359 // typedef typename Graph::OutEdgeIt GraphOutEdgeIt; 360 // typedef typename Graph::InEdgeIt GraphInEdgeIt; 361 // //public: 362 363 // //UndirGraphWrapper() : graph(0) { } 364 // UndirGraphWrapper(Graph& _graph) : graph(&_graph) { } 365 366 // void setGraph(Graph& _graph) { graph = &_graph; } 367 // Graph& getGraph() const { return (*graph); } 368 369 // class Edge { 370 // friend class UndirGraphWrapper<Graph>; 371 // bool out_or_in; //true iff out 372 // GraphOutEdgeIt out; 373 // GraphInEdgeIt in; 374 // public: 375 // Edge() : out_or_in(), out(), in() { } 376 // Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } 377 // operator GraphEdge() const { 378 // if (out_or_in) return(out); else return(in); 379 // } 380 // friend bool operator==(const Edge& u, const Edge& v) { 381 // if (v.out_or_in) 382 // return (u.out_or_in && u.out==v.out); 383 // else 384 // return (!u.out_or_in && u.in==v.in); 385 // } 386 // friend bool operator!=(const Edge& u, const Edge& v) { 387 // if (v.out_or_in) 388 // return (!u.out_or_in || u.out!=v.out); 389 // else 390 // return (u.out_or_in || u.in!=v.in); 391 // } 392 // }; 393 394 // class OutEdgeIt : public Edge { 395 // friend class UndirGraphWrapper<Graph>; 396 // public: 397 // OutEdgeIt() : Edge() { } 398 // OutEdgeIt(const Invalid& i) : Edge(i) { } 399 // OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() { 400 // out_or_in=true; 401 // _G.graph->first(out, n); 402 // if (!(_G.graph->valid(out))) { 403 // out_or_in=false; 404 // _G.graph->first(in, n); 405 // } 406 // } 407 // }; 408 409 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 410 // e.out_or_in=true; 411 // graph->first(e.out, n); 412 // if (!(graph->valid(e.out))) { 413 // e.out_or_in=false; 414 // graph->first(e.in, n); 415 // } 416 // return e; 417 // } 418 419 // OutEdgeIt& next(OutEdgeIt& e) const { 420 // if (e.out_or_in) { 421 // Node n=graph->tail(e.out); 422 // graph->next(e.out); 423 // if (!graph->valid(e.out)) { 424 // e.out_or_in=false; 425 // graph->first(e.in, n); 426 // } 427 // } else { 428 // graph->next(e.in); 429 // } 430 // return e; 431 // } 432 433 // Node aNode(const OutEdgeIt& e) const { 434 // if (e.out_or_in) return graph->tail(e); else return graph->head(e); } 435 // Node bNode(const OutEdgeIt& e) const { 436 // if (e.out_or_in) return graph->head(e); else return graph->tail(e); } 437 438 // typedef OutEdgeIt InEdgeIt; 439 440 // template<typename I> I& first(I& i) const { return graph->first(i); } 441 // // template<typename I, typename P> I& first(I& i, const P& p) const { 442 // // return graph->first(i, p); } 443 444 // template<typename I> I getNext(const I& i) const { 445 // return graph->getNext(i); } 446 // template<typename I> I& next(I &i) const { return graph->next(i); } 447 448 // template< typename It > It first() const { 449 // It e; first(e); return e; } 450 451 // template< typename It > It first(const Node& v) const { 452 // It e; first(e, v); return e; } 453 454 // Node head(const Edge& e) const { return graph->head(e); } 455 // Node tail(const Edge& e) const { return graph->tail(e); } 456 457 // template<typename I> bool valid(const I& i) const 458 // { return graph->valid(i); } 459 460 // //template<typename I> void setInvalid(const I &i); 461 // //{ return graph->setInvalid(i); } 462 463 // int nodeNum() const { return graph->nodeNum(); } 464 // int edgeNum() const { return graph->edgeNum(); } 465 466 // // template<typename I> Node aNode(const I& e) const { 467 // // return graph->aNode(e); } 468 // // template<typename I> Node bNode(const I& e) const { 469 // // return graph->bNode(e); } 470 471 // Node addNode() const { return graph->addNode(); } 472 // // FIXME: ez igy nem jo, mert nem 473 // // Edge addEdge(const Node& tail, const Node& head) const { 474 // // return graph->addEdge(tail, head); } 475 476 // template<typename I> void erase(const I& i) const { graph->erase(i); } 477 478 // void clear() const { graph->clear(); } 479 480 // template<typename T> class NodeMap : public Graph::NodeMap<T> { 481 // public: 482 // NodeMap(const UndirGraphWrapper<Graph>& _G) : 483 // Graph::NodeMap<T>(_G.getGraph()) { } 484 // NodeMap(const UndirGraphWrapper<Graph>& _G, T a) : 485 // Graph::NodeMap<T>(_G.getGraph(), a) { } 486 // }; 487 488 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 489 // public: 490 // EdgeMap(const UndirGraphWrapper<Graph>& _G) : 491 // Graph::EdgeMap<T>(_G.getGraph()) { } 492 // EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) : 493 // Graph::EdgeMap<T>(_G.getGraph(), a) { } 494 // }; 495 // }; 496 497 498 template<typename GraphWrapper> 340 499 class UndirGraphWrapper { 341 500 protected: 342 Graph* graph; 343 501 //Graph* graph; 502 GraphWrapper gw; 503 344 504 public: 345 typedef Graph BaseGraph;346 347 typedef typename Graph ::Node Node;348 typedef typename Graph ::NodeIt NodeIt;505 typedef GraphWrapper BaseGraph; 506 507 typedef typename GraphWrapper::Node Node; 508 typedef typename GraphWrapper::NodeIt NodeIt; 349 509 350 510 //typedef typename Graph::Edge Edge; … … 355 515 356 516 //private: 357 typedef typename Graph ::Edge GraphEdge;358 typedef typename Graph ::OutEdgeIt GraphOutEdgeIt;359 typedef typename Graph ::InEdgeIt GraphInEdgeIt;517 typedef typename GraphWrapper::Edge GraphEdge; 518 typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt; 519 typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt; 360 520 //public: 361 521 362 522 //UndirGraphWrapper() : graph(0) { } 363 UndirGraphWrapper(Graph & _graph) : graph(&_graph) { }364 365 void setGraph(Graph& _graph) { graph = &_graph; }366 Graph& getGraph() const { return (*graph); }523 UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { } 524 525 //void setGraph(Graph& _graph) { graph = &_graph; } 526 //Graph& getGraph() const { return (*graph); } 367 527 368 528 class Edge { 369 friend class UndirGraphWrapper<Graph >;529 friend class UndirGraphWrapper<GraphWrapper>; 370 530 bool out_or_in; //true iff out 371 531 GraphOutEdgeIt out; … … 392 552 393 553 class OutEdgeIt : public Edge { 394 friend class UndirGraphWrapper<Graph >;554 friend class UndirGraphWrapper<GraphWrapper>; 395 555 public: 396 556 OutEdgeIt() : Edge() { } 397 557 OutEdgeIt(const Invalid& i) : Edge(i) { } 398 OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() { 558 OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 559 : Edge() { 399 560 out_or_in=true; 400 _G.g raph->first(out, n);401 if (!(_G.g raph->valid(out))) {561 _G.gw.first(out, n); 562 if (!(_G.gw.valid(out))) { 402 563 out_or_in=false; 403 _G.g raph->first(in, n);564 _G.gw.first(in, n); 404 565 } 405 566 } … … 408 569 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 409 570 e.out_or_in=true; 410 g raph->first(e.out, n);411 if (!(g raph->valid(e.out))) {571 gw.first(e.out, n); 572 if (!(gw.valid(e.out))) { 412 573 e.out_or_in=false; 413 g raph->first(e.in, n);574 gw.first(e.in, n); 414 575 } 415 576 return e; … … 418 579 OutEdgeIt& next(OutEdgeIt& e) const { 419 580 if (e.out_or_in) { 420 Node n=g raph->tail(e.out);421 g raph->next(e.out);422 if (!g raph->valid(e.out)) {581 Node n=gw.tail(e.out); 582 gw.next(e.out); 583 if (!gw.valid(e.out)) { 423 584 e.out_or_in=false; 424 g raph->first(e.in, n);585 gw.first(e.in, n); 425 586 } 426 587 } else { 427 g raph->next(e.in);588 gw.next(e.in); 428 589 } 429 590 return e; … … 431 592 432 593 Node aNode(const OutEdgeIt& e) const { 433 if (e.out_or_in) return g raph->tail(e); else return graph->head(e); }594 if (e.out_or_in) return gw.tail(e); else return gw.head(e); } 434 595 Node bNode(const OutEdgeIt& e) const { 435 if (e.out_or_in) return g raph->head(e); else return graph->tail(e); }596 if (e.out_or_in) return gw.head(e); else return gw.tail(e); } 436 597 437 598 typedef OutEdgeIt InEdgeIt; 438 599 439 template<typename I> I& first(I& i) const { return g raph->first(i); }600 template<typename I> I& first(I& i) const { return gw.first(i); } 440 601 // template<typename I, typename P> I& first(I& i, const P& p) const { 441 602 // return graph->first(i, p); } 442 603 443 604 template<typename I> I getNext(const I& i) const { 444 return g raph->getNext(i); }445 template<typename I> I& next(I &i) const { return g raph->next(i); }605 return gw.getNext(i); } 606 template<typename I> I& next(I &i) const { return gw.next(i); } 446 607 447 608 template< typename It > It first() const { … … 451 612 It e; first(e, v); return e; } 452 613 453 Node head(const Edge& e) const { return g raph->head(e); }454 Node tail(const Edge& e) const { return g raph->tail(e); }614 Node head(const Edge& e) const { return gw.head(e); } 615 Node tail(const Edge& e) const { return gw.tail(e); } 455 616 456 617 template<typename I> bool valid(const I& i) const 457 { return g raph->valid(i); }618 { return gw.valid(i); } 458 619 459 620 //template<typename I> void setInvalid(const I &i); 460 621 //{ return graph->setInvalid(i); } 461 622 462 int nodeNum() const { return g raph->nodeNum(); }463 int edgeNum() const { return g raph->edgeNum(); }623 int nodeNum() const { return gw.nodeNum(); } 624 int edgeNum() const { return gw.edgeNum(); } 464 625 465 626 // template<typename I> Node aNode(const I& e) const { … … 468 629 // return graph->bNode(e); } 469 630 470 Node addNode() const { return g raph->addNode(); }631 Node addNode() const { return gw.addNode(); } 471 632 // FIXME: ez igy nem jo, mert nem 472 633 // Edge addEdge(const Node& tail, const Node& head) const { 473 634 // return graph->addEdge(tail, head); } 474 635 475 template<typename I> void erase(const I& i) const { g raph->erase(i); }476 477 void clear() const { g raph->clear(); }478 479 template<typename T> class NodeMap : public Graph ::NodeMap<T> {480 public: 481 NodeMap(const UndirGraphWrapper<Graph >& _G) :482 Graph ::NodeMap<T>(_G.getGraph()) { }483 NodeMap(const UndirGraphWrapper<Graph >& _G, T a) :484 Graph ::NodeMap<T>(_G.getGraph(), a) { }485 }; 486 487 template<typename T> class EdgeMap : public Graph ::EdgeMap<T> {488 public: 489 EdgeMap(const UndirGraphWrapper<Graph >& _G) :490 Graph ::EdgeMap<T>(_G.getGraph()) { }491 EdgeMap(const UndirGraphWrapper<Graph >& _G, T a) :492 Graph ::EdgeMap<T>(_G.getGraph(), a) { }636 template<typename I> void erase(const I& i) const { gw.erase(i); } 637 638 void clear() const { gw.clear(); } 639 640 template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 641 public: 642 NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 643 GraphWrapper::NodeMap<T>(_G.gw) { } 644 NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 645 GraphWrapper::NodeMap<T>(_G.gw, a) { } 646 }; 647 648 template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 649 public: 650 EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 651 GraphWrapper::EdgeMap<T>(_G.gw) { } 652 EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 653 GraphWrapper::EdgeMap<T>(_G.gw, a) { } 493 654 }; 494 655 }; 656 657 495 658 496 659
Note: See TracChangeset
for help on using the changeset viewer.