Changeset 2031:080d51024ac5 in lemon-0.x for lemon/bits
- Timestamp:
- 04/03/06 11:45:23 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2670
- Location:
- lemon/bits
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/array_map.h
r1999 r2031 24 24 #include <lemon/bits/traits.h> 25 25 #include <lemon/bits/alteration_notifier.h> 26 #include <lemon/concept_check.h> 27 #include <lemon/concept/maps.h> 26 28 27 29 /// \ingroup graphbits … … 120 122 } 121 123 124 /// \brief Assign operator. 125 /// 126 /// This operator assigns for each item in the map the 127 /// value mapped to the same item in the copied map. 128 /// The parameter map should be indiced with the same 129 /// itemset because this assign operator does not change 130 /// the container of the map. 131 ArrayMap& operator=(const ArrayMap& cmap) { 132 return operator=<ArrayMap>(cmap); 133 } 134 135 136 /// \brief Template assign operator. 137 /// 138 /// The given parameter should be conform to the ReadMap 139 /// concecpt and could be indiced by the current item set of 140 /// the NodeMap. In this case the value for each item 141 /// is assigned by the value of the given ReadMap. 142 template <typename CMap> 143 ArrayMap& operator=(const CMap& cmap) { 144 checkConcept<concept::ReadMap<Key, _Value>, CMap>(); 145 const typename Parent::Notifier* notifier = Parent::getNotifier(); 146 Item it; 147 for (notifier->first(it); it != INVALID; notifier->next(it)) { 148 set(it, cmap[it]); 149 } 150 return *this; 151 } 152 122 153 /// \brief The destructor of the map. 123 154 /// … … 130 161 } 131 162 132 private:133 134 ArrayMap& operator=(const ArrayMap&);135 136 163 protected: 137 164 -
lemon/bits/base_extender.h
r1999 r2031 467 467 return Edge(edge, direction); 468 468 } 469 470 int edgeNum() const { 471 return 2 * Parent::edgeNum(); 472 } 473 474 int uEdgeNum() const { 475 return Parent::edgeNum(); 476 } 477 469 478 }; 470 479 -
lemon/bits/default_map.h
r1999 r2031 164 164 : Parent(graph, value) {} 165 165 166 DefaultMap& operator=(const DefaultMap& cmap) { 167 return operator=<DefaultMap>(cmap); 168 } 169 170 template <typename CMap> 171 DefaultMap& operator=(const CMap& cmap) { 172 Parent::operator=(cmap); 173 return *this; 174 } 175 166 176 }; 167 177 -
lemon/bits/edge_set_extender.h
r1999 r2031 102 102 103 103 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 104 _graph.first( *static_cast<Node*>(this));104 _graph.first(static_cast<Node&>(*this)); 105 105 } 106 106 … … 125 125 126 126 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 127 _graph.first( *static_cast<Edge*>(this));127 _graph.first(static_cast<Edge&>(*this)); 128 128 } 129 129 … … 236 236 template <typename CMap> 237 237 EdgeMap& operator=(const CMap& cmap) { 238 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 239 const typename Parent::Graph* graph = Parent::getGraph(); 240 Edge it; 241 for (graph->first(it); it != INVALID; graph->next(it)) { 242 Parent::set(it, cmap[it]); 243 } 238 Parent::operator=(cmap); 244 239 return *this; 245 240 } 241 246 242 }; 247 243 … … 365 361 366 362 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 367 _graph.first( *static_cast<Node*>(this));363 _graph.first(static_cast<Node&>(*this)); 368 364 } 369 365 … … 388 384 389 385 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 390 _graph.first( *static_cast<Edge*>(this));386 _graph.first(static_cast<Edge&>(*this)); 391 387 } 392 388 … … 459 455 460 456 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) { 461 _graph.first( *static_cast<UEdge*>(this));457 _graph.first(static_cast<UEdge&>(*this)); 462 458 } 463 459 … … 557 553 template <typename CMap> 558 554 EdgeMap& operator=(const CMap& cmap) { 559 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 560 const typename Parent::Graph* graph = Parent::getGraph(); 561 Edge it; 562 for (graph->first(it); it != INVALID; graph->next(it)) { 563 Parent::set(it, cmap[it]); 564 } 555 Parent::operator=(cmap); 565 556 return *this; 566 557 } 558 567 559 }; 568 560 … … 577 569 UEdgeMap(const Graph& _g) 578 570 : Parent(_g) {} 571 579 572 UEdgeMap(const Graph& _g, const _Value& _v) 580 573 : Parent(_g, _v) {} … … 586 579 template <typename CMap> 587 580 UEdgeMap& operator=(const CMap& cmap) { 588 checkConcept<concept::ReadMap<UEdge, _Value>, CMap>(); 589 const typename Parent::Graph* graph = Parent::getGraph(); 590 UEdge it; 591 for (graph->first(it); it != INVALID; graph->next(it)) { 592 Parent::set(it, cmap[it]); 593 } 581 Parent::operator=(cmap); 594 582 return *this; 595 583 } 584 596 585 }; 597 586 -
lemon/bits/graph_adaptor_extender.h
r1996 r2031 34 34 /// 35 35 /// \brief Extender for the GraphAdaptors 36 template <typename Base>37 class GraphAdaptorExtender : public Base{36 template <typename _Graph> 37 class GraphAdaptorExtender : public _Graph { 38 38 public: 39 39 40 typedef Base Parent; 41 typedef GraphAdaptorExtender Graph; 40 typedef _Graph Parent; 41 typedef _Graph Graph; 42 typedef GraphAdaptorExtender Adaptor; 42 43 43 44 // Base extensions … … 72 73 73 74 class NodeIt : public Node { 74 const Graph* graph;75 const Adaptor* graph; 75 76 public: 76 77 … … 79 80 NodeIt(Invalid i) : Node(i) { } 80 81 81 explicit NodeIt(const Graph& _graph) : graph(&_graph) {82 _graph.first( *static_cast<Node*>(this));83 } 84 85 NodeIt(const Graph& _graph, const Node& node)82 explicit NodeIt(const Adaptor& _graph) : graph(&_graph) { 83 _graph.first(static_cast<Node&>(*this)); 84 } 85 86 NodeIt(const Adaptor& _graph, const Node& node) 86 87 : Node(node), graph(&_graph) {} 87 88 … … 95 96 96 97 class EdgeIt : public Edge { 97 const Graph* graph;98 const Adaptor* graph; 98 99 public: 99 100 … … 102 103 EdgeIt(Invalid i) : Edge(i) { } 103 104 104 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {105 _graph.first( *static_cast<Edge*>(this));106 } 107 108 EdgeIt(const Graph& _graph, const Edge& e) :105 explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) { 106 _graph.first(static_cast<Edge&>(*this)); 107 } 108 109 EdgeIt(const Adaptor& _graph, const Edge& e) : 109 110 Edge(e), graph(&_graph) { } 110 111 … … 118 119 119 120 class OutEdgeIt : public Edge { 120 const Graph* graph;121 const Adaptor* graph; 121 122 public: 122 123 … … 125 126 OutEdgeIt(Invalid i) : Edge(i) { } 126 127 127 OutEdgeIt(const Graph& _graph, const Node& node)128 OutEdgeIt(const Adaptor& _graph, const Node& node) 128 129 : graph(&_graph) { 129 130 _graph.firstOut(*this, node); 130 131 } 131 132 132 OutEdgeIt(const Graph& _graph, const Edge& edge)133 OutEdgeIt(const Adaptor& _graph, const Edge& edge) 133 134 : Edge(edge), graph(&_graph) {} 134 135 … … 142 143 143 144 class InEdgeIt : public Edge { 144 const Graph* graph;145 const Adaptor* graph; 145 146 public: 146 147 … … 149 150 InEdgeIt(Invalid i) : Edge(i) { } 150 151 151 InEdgeIt(const Graph& _graph, const Node& node)152 InEdgeIt(const Adaptor& _graph, const Node& node) 152 153 : graph(&_graph) { 153 154 _graph.firstIn(*this, node); 154 155 } 155 156 156 InEdgeIt(const Graph& _graph, const Edge& edge) :157 InEdgeIt(const Adaptor& _graph, const Edge& edge) : 157 158 Edge(edge), graph(&_graph) {} 158 159 … … 198 199 /// 199 200 /// \brief Extender for the UGraphAdaptors 200 template <typename Base>201 class UGraphAdaptorExtender : public Base{201 template <typename _UGraph> 202 class UGraphAdaptorExtender : public _UGraph { 202 203 public: 203 204 204 typedef Base Parent; 205 typedef UGraphAdaptorExtender Graph; 205 typedef _UGraph Parent; 206 typedef _UGraph UGraph; 207 typedef UGraphAdaptorExtender Adaptor; 206 208 207 209 typedef typename Parent::Node Node; … … 255 257 256 258 class NodeIt : public Node { 257 const Graph* graph;259 const Adaptor* graph; 258 260 public: 259 261 … … 262 264 NodeIt(Invalid i) : Node(i) { } 263 265 264 explicit NodeIt(const Graph& _graph) : graph(&_graph) {265 _graph.first( *static_cast<Node*>(this));266 } 267 268 NodeIt(const Graph& _graph, const Node& node)266 explicit NodeIt(const Adaptor& _graph) : graph(&_graph) { 267 _graph.first(static_cast<Node&>(*this)); 268 } 269 270 NodeIt(const Adaptor& _graph, const Node& node) 269 271 : Node(node), graph(&_graph) {} 270 272 … … 278 280 279 281 class EdgeIt : public Edge { 280 const Graph* graph;282 const Adaptor* graph; 281 283 public: 282 284 … … 285 287 EdgeIt(Invalid i) : Edge(i) { } 286 288 287 explicit EdgeIt(const Graph& _graph) : graph(&_graph) {288 _graph.first( *static_cast<Edge*>(this));289 } 290 291 EdgeIt(const Graph& _graph, const Edge& e) :289 explicit EdgeIt(const Adaptor& _graph) : graph(&_graph) { 290 _graph.first(static_cast<Edge&>(*this)); 291 } 292 293 EdgeIt(const Adaptor& _graph, const Edge& e) : 292 294 Edge(e), graph(&_graph) { } 293 295 … … 301 303 302 304 class OutEdgeIt : public Edge { 303 const Graph* graph;305 const Adaptor* graph; 304 306 public: 305 307 … … 308 310 OutEdgeIt(Invalid i) : Edge(i) { } 309 311 310 OutEdgeIt(const Graph& _graph, const Node& node)312 OutEdgeIt(const Adaptor& _graph, const Node& node) 311 313 : graph(&_graph) { 312 314 _graph.firstOut(*this, node); 313 315 } 314 316 315 OutEdgeIt(const Graph& _graph, const Edge& edge)317 OutEdgeIt(const Adaptor& _graph, const Edge& edge) 316 318 : Edge(edge), graph(&_graph) {} 317 319 … … 325 327 326 328 class InEdgeIt : public Edge { 327 const Graph* graph;329 const Adaptor* graph; 328 330 public: 329 331 … … 332 334 InEdgeIt(Invalid i) : Edge(i) { } 333 335 334 InEdgeIt(const Graph& _graph, const Node& node)336 InEdgeIt(const Adaptor& _graph, const Node& node) 335 337 : graph(&_graph) { 336 338 _graph.firstIn(*this, node); 337 339 } 338 340 339 InEdgeIt(const Graph& _graph, const Edge& edge) :341 InEdgeIt(const Adaptor& _graph, const Edge& edge) : 340 342 Edge(edge), graph(&_graph) {} 341 343 … … 348 350 349 351 class UEdgeIt : public Parent::UEdge { 350 const Graph* graph;352 const Adaptor* graph; 351 353 public: 352 354 … … 355 357 UEdgeIt(Invalid i) : UEdge(i) { } 356 358 357 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) {358 _graph.first( *static_cast<UEdge*>(this));359 } 360 361 UEdgeIt(const Graph& _graph, const UEdge& e) :359 explicit UEdgeIt(const Adaptor& _graph) : graph(&_graph) { 360 _graph.first(static_cast<UEdge&>(*this)); 361 } 362 363 UEdgeIt(const Adaptor& _graph, const UEdge& e) : 362 364 UEdge(e), graph(&_graph) { } 363 365 … … 371 373 class IncEdgeIt : public Parent::UEdge { 372 374 friend class UGraphAdaptorExtender; 373 const Graph* graph;375 const Adaptor* graph; 374 376 bool direction; 375 377 public: … … 379 381 IncEdgeIt(Invalid i) : UEdge(i), direction(false) { } 380 382 381 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {383 IncEdgeIt(const Adaptor& _graph, const Node &n) : graph(&_graph) { 382 384 _graph.firstInc(static_cast<UEdge&>(*this), direction, n); 383 385 } 384 386 385 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n)387 IncEdgeIt(const Adaptor& _graph, const UEdge &ue, const Node &n) 386 388 : graph(&_graph), UEdge(ue) { 387 389 direction = (_graph.source(ue) == n); … … 437 439 }; 438 440 441 /// \ingroup graphbits 442 /// 443 /// \brief Extender for the BpUGraphAdaptors 444 template <typename Base> 445 class BpUGraphAdaptorExtender : public Base { 446 public: 447 typedef Base Parent; 448 typedef BpUGraphAdaptorExtender Graph; 449 450 typedef typename Parent::Node Node; 451 typedef typename Parent::BNode BNode; 452 typedef typename Parent::ANode ANode; 453 typedef typename Parent::Edge Edge; 454 typedef typename Parent::UEdge UEdge; 455 456 Node oppositeNode(const UEdge& edge, const Node& node) const { 457 return source(edge) == node ? 458 target(edge) : source(edge); 459 } 460 461 462 int maxId(Node) const { 463 return Parent::maxNodeId(); 464 } 465 int maxId(BNode) const { 466 return Parent::maxBNodeId(); 467 } 468 int maxId(ANode) const { 469 return Parent::maxANodeId(); 470 } 471 int maxId(Edge) const { 472 return Parent::maxEdgeId(); 473 } 474 int maxId(UEdge) const { 475 return Parent::maxUEdgeId(); 476 } 477 478 479 Node fromId(int id, Node) const { 480 return Parent::nodeFromId(id); 481 } 482 ANode fromId(int id, ANode) const { 483 return Parent::fromANodeId(id); 484 } 485 BNode fromId(int id, BNode) const { 486 return Parent::fromBNodeId(id); 487 } 488 Edge fromId(int id, Edge) const { 489 return Parent::edgeFromId(id); 490 } 491 UEdge fromId(int id, UEdge) const { 492 return Parent::uEdgeFromId(id); 493 } 494 495 class NodeIt : public Node { 496 const Graph* graph; 497 public: 498 499 NodeIt() { } 500 501 NodeIt(Invalid i) : Node(INVALID) { } 502 503 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 504 graph->first(static_cast<Node&>(*this)); 505 } 506 507 NodeIt(const Graph& _graph, const Node& node) 508 : Node(node), graph(&_graph) { } 509 510 NodeIt& operator++() { 511 graph->next(*this); 512 return *this; 513 } 514 515 }; 516 517 class ANodeIt : public Node { 518 friend class BpUGraphAdaptorExtender; 519 const Graph* graph; 520 public: 521 522 ANodeIt() { } 523 524 ANodeIt(Invalid i) : Node(INVALID) { } 525 526 explicit ANodeIt(const Graph& _graph) : graph(&_graph) { 527 graph->firstANode(static_cast<Node&>(*this)); 528 } 529 530 ANodeIt(const Graph& _graph, const Node& node) 531 : Node(node), graph(&_graph) {} 532 533 ANodeIt& operator++() { 534 graph->nextANode(*this); 535 return *this; 536 } 537 }; 538 539 class BNodeIt : public Node { 540 friend class BpUGraphAdaptorExtender; 541 const Graph* graph; 542 public: 543 544 BNodeIt() { } 545 546 BNodeIt(Invalid i) : Node(INVALID) { } 547 548 explicit BNodeIt(const Graph& _graph) : graph(&_graph) { 549 graph->firstBNode(static_cast<Node&>(*this)); 550 } 551 552 BNodeIt(const Graph& _graph, const Node& node) 553 : Node(node), graph(&_graph) {} 554 555 BNodeIt& operator++() { 556 graph->nextBNode(*this); 557 return *this; 558 } 559 }; 560 561 class EdgeIt : public Edge { 562 friend class BpUGraphAdaptorExtender; 563 const Graph* graph; 564 public: 565 566 EdgeIt() { } 567 568 EdgeIt(Invalid i) : Edge(INVALID) { } 569 570 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 571 graph->first(static_cast<Edge&>(*this)); 572 } 573 574 EdgeIt(const Graph& _graph, const Edge& edge) 575 : Edge(edge), graph(&_graph) { } 576 577 EdgeIt& operator++() { 578 graph->next(*this); 579 return *this; 580 } 581 582 }; 583 584 class UEdgeIt : public UEdge { 585 friend class BpUGraphAdaptorExtender; 586 const Graph* graph; 587 public: 588 589 UEdgeIt() { } 590 591 UEdgeIt(Invalid i) : UEdge(INVALID) { } 592 593 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) { 594 graph->first(static_cast<UEdge&>(*this)); 595 } 596 597 UEdgeIt(const Graph& _graph, const UEdge& edge) 598 : UEdge(edge), graph(&_graph) { } 599 600 UEdgeIt& operator++() { 601 graph->next(*this); 602 return *this; 603 } 604 }; 605 606 class OutEdgeIt : public Edge { 607 friend class BpUGraphAdaptorExtender; 608 const Graph* graph; 609 public: 610 611 OutEdgeIt() { } 612 613 OutEdgeIt(Invalid i) : Edge(i) { } 614 615 OutEdgeIt(const Graph& _graph, const Node& node) 616 : graph(&_graph) { 617 graph->firstOut(*this, node); 618 } 619 620 OutEdgeIt(const Graph& _graph, const Edge& edge) 621 : Edge(edge), graph(&_graph) {} 622 623 OutEdgeIt& operator++() { 624 graph->nextOut(*this); 625 return *this; 626 } 627 628 }; 629 630 631 class InEdgeIt : public Edge { 632 friend class BpUGraphAdaptorExtender; 633 const Graph* graph; 634 public: 635 636 InEdgeIt() { } 637 638 InEdgeIt(Invalid i) : Edge(i) { } 639 640 InEdgeIt(const Graph& _graph, const Node& node) 641 : graph(&_graph) { 642 graph->firstIn(*this, node); 643 } 644 645 InEdgeIt(const Graph& _graph, const Edge& edge) : 646 Edge(edge), graph(&_graph) {} 647 648 InEdgeIt& operator++() { 649 graph->nextIn(*this); 650 return *this; 651 } 652 653 }; 654 655 /// \brief Base node of the iterator 656 /// 657 /// Returns the base node (ie. the source in this case) of the iterator 658 Node baseNode(const OutEdgeIt &e) const { 659 return Parent::source((Edge&)e); 660 } 661 /// \brief Running node of the iterator 662 /// 663 /// Returns the running node (ie. the target in this case) of the 664 /// iterator 665 Node runningNode(const OutEdgeIt &e) const { 666 return Parent::target((Edge&)e); 667 } 668 669 /// \brief Base node of the iterator 670 /// 671 /// Returns the base node (ie. the target in this case) of the iterator 672 Node baseNode(const InEdgeIt &e) const { 673 return Parent::target((Edge&)e); 674 } 675 /// \brief Running node of the iterator 676 /// 677 /// Returns the running node (ie. the source in this case) of the 678 /// iterator 679 Node runningNode(const InEdgeIt &e) const { 680 return Parent::source((Edge&)e); 681 } 682 683 class IncEdgeIt : public Parent::UEdge { 684 friend class BpUGraphAdaptorExtender; 685 const Graph* graph; 686 bool direction; 687 public: 688 689 IncEdgeIt() { } 690 691 IncEdgeIt(Invalid i) : UEdge(i), direction(true) { } 692 693 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { 694 graph->firstInc(*this, direction, n); 695 } 696 697 IncEdgeIt(const Graph& _graph, const UEdge &ue, const Node &n) 698 : graph(&_graph), UEdge(ue) { 699 direction = (graph->source(ue) == n); 700 } 701 702 IncEdgeIt& operator++() { 703 graph->nextInc(*this, direction); 704 return *this; 705 } 706 }; 707 708 709 /// Base node of the iterator 710 /// 711 /// Returns the base node of the iterator 712 Node baseNode(const IncEdgeIt &e) const { 713 return e.direction ? source(e) : target(e); 714 } 715 716 /// Running node of the iterator 717 /// 718 /// Returns the running node of the iterator 719 Node runningNode(const IncEdgeIt &e) const { 720 return e.direction ? target(e) : source(e); 721 } 722 723 }; 724 439 725 440 726 } -
lemon/bits/graph_extender.h
r1999 r2031 104 104 105 105 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 106 _graph.first( *static_cast<Node*>(this));106 _graph.first(static_cast<Node&>(*this)); 107 107 } 108 108 … … 127 127 128 128 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 129 _graph.first( *static_cast<Edge*>(this));129 _graph.first(static_cast<Edge&>(*this)); 130 130 } 131 131 … … 233 233 } 234 234 235 236 /// \brief Template assign operator.237 ///238 /// The given parameter should be conform to the ReadMap239 /// concecpt and could be indiced by the current item set of240 /// the NodeMap. In this case the value for each item241 /// is assigned by the value of the given ReadMap.242 235 template <typename CMap> 243 236 NodeMap& operator=(const CMap& cmap) { 244 checkConcept<concept::ReadMap<Node, _Value>, CMap>(); 245 const typename Parent::Notifier* notifier = Parent::getNotifier(); 246 Node it; 247 for (notifier->first(it); it != INVALID; notifier->next(it)) { 248 Parent::set(it, cmap[it]); 249 } 237 Parent::operator=(cmap); 250 238 return *this; 251 239 } … … 271 259 template <typename CMap> 272 260 EdgeMap& operator=(const CMap& cmap) { 273 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 274 const typename Parent::Notifier* notifier = Parent::getNotifier(); 275 Edge it; 276 for (notifier->first(it); it != INVALID; notifier->next(it)) { 277 Parent::set(it, cmap[it]); 278 } 261 Parent::operator=(cmap); 279 262 return *this; 280 263 } … … 432 415 433 416 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 434 _graph.first( *static_cast<Node*>(this));417 _graph.first(static_cast<Node&>(*this)); 435 418 } 436 419 … … 455 438 456 439 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 457 _graph.first( *static_cast<Edge*>(this));440 _graph.first(static_cast<Edge&>(*this)); 458 441 } 459 442 … … 526 509 527 510 explicit UEdgeIt(const Graph& _graph) : graph(&_graph) { 528 _graph.first( *static_cast<UEdge*>(this));511 _graph.first(static_cast<UEdge&>(*this)); 529 512 } 530 513 … … 623 606 } 624 607 625 626 /// \brief Template assign operator.627 ///628 /// The given parameter should be conform to the ReadMap629 /// concecpt and could be indiced by the current item set of630 /// the NodeMap. In this case the value for each item631 /// is assigned by the value of the given ReadMap.632 608 template <typename CMap> 633 609 NodeMap& operator=(const CMap& cmap) { 634 checkConcept<concept::ReadMap<Node, _Value>, CMap>(); 635 const typename Parent::Notifier* notifier = Parent::getNotifier(); 636 Node it; 637 for (notifier->first(it); it != INVALID; notifier->next(it)) { 638 Parent::set(it, cmap[it]); 639 } 610 Parent::operator=(cmap); 640 611 return *this; 641 612 } … … 661 632 template <typename CMap> 662 633 EdgeMap& operator=(const CMap& cmap) { 663 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 664 const typename Parent::Notifier* notifier = Parent::getNotifier(); 665 Edge it; 666 for (notifier->first(it); it != INVALID; notifier->next(it)) { 667 Parent::set(it, cmap[it]); 668 } 634 Parent::operator=(cmap); 669 635 return *this; 670 636 } … … 681 647 UEdgeMap(const Graph& graph) 682 648 : Parent(graph) {} 649 683 650 UEdgeMap(const Graph& graph, const _Value& value) 684 651 : Parent(graph, value) {} … … 690 657 template <typename CMap> 691 658 UEdgeMap& operator=(const CMap& cmap) { 692 checkConcept<concept::ReadMap<UEdge, _Value>, CMap>(); 693 const typename Parent::Notifier* notifier = Parent::getNotifier(); 694 Edge it; 695 for (notifier->first(it); it != INVALID; notifier->next(it)) { 696 Parent::set(it, cmap[it]); 697 } 659 Parent::operator=(cmap); 698 660 return *this; 699 661 } 662 700 663 }; 701 664 … … 1105 1068 } 1106 1069 1107 1108 /// \brief Template assign operator.1109 ///1110 /// The given parameter should be conform to the ReadMap1111 /// concept and could be indiced by the current item set of1112 /// the ANodeMap. In this case the value for each item1113 /// is assigned by the value of the given ReadMap.1114 1070 template <typename CMap> 1115 1071 ANodeMap& operator=(const CMap& cmap) { 1116 checkConcept<concept::ReadMap<ANode, _Value>, CMap>(); 1117 const typename Parent::Graph* graph = Parent::getGraph(); 1118 ANode it; 1119 for (graph->first(it); it != INVALID; graph->next(it)) { 1120 Parent::set(it, cmap[it]); 1121 } 1072 Parent::operator=(cmap); 1122 1073 return *this; 1123 1074 } … … 1141 1092 } 1142 1093 1143 1144 /// \brief Template assign operator.1145 ///1146 /// The given parameter should be conform to the ReadMap1147 /// concept and could be indiced by the current item set of1148 /// the BNodeMap. In this case the value for each item1149 /// is assigned by the value of the given ReadMap.1150 1094 template <typename CMap> 1151 1095 BNodeMap& operator=(const CMap& cmap) { 1152 checkConcept<concept::ReadMap<BNode, _Value>, CMap>(); 1153 const typename Parent::Graph* graph = Parent::getGraph(); 1154 BNode it; 1155 for (graph->first(it); it != INVALID; graph->next(it)) { 1156 Parent::set(it, cmap[it]); 1157 } 1096 Parent::operator=(cmap); 1158 1097 return *this; 1159 1098 } … … 1161 1100 }; 1162 1101 1163 p rotected:1102 public: 1164 1103 1165 1104 template <typename _Value> 1166 class NodeMap Base{1105 class NodeMap { 1167 1106 public: 1168 1107 typedef BpUGraphExtender Graph; … … 1178 1117 typedef True ReferenceMapTag; 1179 1118 1180 NodeMapBase(const Graph& graph) 1181 : aNodeMap(graph), bNodeMap(graph) {} 1182 NodeMapBase(const Graph& graph, const _Value& value) 1183 : aNodeMap(graph, value), bNodeMap(graph, value) {} 1119 NodeMap(const Graph& _graph) 1120 : graph(_graph), aNodeMap(_graph), bNodeMap(_graph) {} 1121 NodeMap(const Graph& _graph, const _Value& _value) 1122 : graph(_graph), aNodeMap(_graph, _value), bNodeMap(_graph, _value) {} 1123 1124 NodeMap& operator=(const NodeMap& cmap) { 1125 return operator=<NodeMap>(cmap); 1126 } 1127 1128 template <typename CMap> 1129 NodeMap& operator=(const CMap& cmap) { 1130 checkConcept<concept::ReadMap<Node, _Value>, CMap>(); 1131 const typename Parent::Notifier* notifier = Parent::getNotifier(); 1132 Edge it; 1133 for (graph.first(it); it != INVALID; graph.next(it)) { 1134 Parent::set(it, cmap[it]); 1135 } 1136 return *this; 1137 } 1184 1138 1185 1139 ConstReference operator[](const Key& node) const { … … 1207 1161 } 1208 1162 1209 const Graph* getGraph() const { 1210 return aNodeMap.getGraph(); 1211 } 1212 1163 class MapIt : public NodeIt { 1164 public: 1165 1166 typedef NodeIt Parent; 1167 1168 explicit MapIt(NodeMap& _map) 1169 : Parent(_map.graph), map(_map) {} 1170 1171 typename MapTraits<NodeMap>::ConstReturnValue operator*() const { 1172 return map[*this]; 1173 } 1174 1175 typename MapTraits<NodeMap>::ReturnValue operator*() { 1176 return map[*this]; 1177 } 1178 1179 void set(const Value& value) { 1180 map.set(*this, value); 1181 } 1182 1183 private: 1184 NodeMap& map; 1185 }; 1186 1187 class ConstMapIt : public NodeIt { 1188 public: 1189 1190 typedef NodeIt Parent; 1191 1192 explicit ConstMapIt(const NodeMap& _map) 1193 : Parent(_map.graph), map(_map) {} 1194 1195 typename MapTraits<NodeMap>::ConstReturnValue operator*() const { 1196 return map[*this]; 1197 } 1198 1199 private: 1200 const NodeMap& map; 1201 }; 1202 1203 class ItemIt : public NodeIt { 1204 public: 1205 1206 typedef NodeIt Parent; 1207 1208 explicit ItemIt(const NodeMap& _map) 1209 : Parent(_map.graph) {} 1210 1211 }; 1212 1213 1213 private: 1214 const Graph& graph; 1214 1215 ANodeMap<_Value> aNodeMap; 1215 1216 BNodeMap<_Value> bNodeMap; 1216 1217 }; 1217 1218 1218 public:1219 1220 template <typename _Value>1221 class NodeMap1222 : public MapExtender<NodeMapBase<_Value> > {1223 public:1224 typedef BpUGraphExtender Graph;1225 typedef MapExtender< NodeMapBase<_Value> > Parent;1226 1227 NodeMap(const Graph& graph)1228 : Parent(graph) {}1229 NodeMap(const Graph& graph, const _Value& value)1230 : Parent(graph, value) {}1231 1232 NodeMap& operator=(const NodeMap& cmap) {1233 return operator=<NodeMap>(cmap);1234 }1235 1236 1237 /// \brief Template assign operator.1238 ///1239 /// The given parameter should be conform to the ReadMap1240 /// concept and could be indiced by the current item set of1241 /// the NodeMap. In this case the value for each item1242 /// is assigned by the value of the given ReadMap.1243 template <typename CMap>1244 NodeMap& operator=(const CMap& cmap) {1245 checkConcept<concept::ReadMap<Node, _Value>, CMap>();1246 const typename Parent::Notifier* notifier = Parent::getNotifier();1247 Edge it;1248 for (notifier->first(it); it != INVALID; notifier->next(it)) {1249 Parent::set(it, cmap[it]);1250 }1251 return *this;1252 }1253 1254 };1255 1256 1257 1219 1258 1220 template <typename _Value> … … 1274 1236 template <typename CMap> 1275 1237 EdgeMap& operator=(const CMap& cmap) { 1276 checkConcept<concept::ReadMap<Edge, _Value>, CMap>(); 1277 const typename Parent::Notifier* notifier = Parent::getNotifier(); 1278 Edge it; 1279 for (notifier->first(it); it != INVALID; notifier->next(it)) { 1280 Parent::set(it, cmap[it]); 1281 } 1238 Parent::operator=(cmap); 1282 1239 return *this; 1283 1240 } … … 1302 1259 template <typename CMap> 1303 1260 UEdgeMap& operator=(const CMap& cmap) { 1304 checkConcept<concept::ReadMap<UEdge, _Value>, CMap>(); 1305 const typename Parent::Notifier* notifier = Parent::getNotifier(); 1306 Edge it; 1307 for (notifier->first(it); it != INVALID; notifier->next(it)) { 1308 Parent::set(it, cmap[it]); 1309 } 1261 Parent::operator=(cmap); 1310 1262 return *this; 1311 1263 } -
lemon/bits/map_extender.h
r1999 r2031 23 23 24 24 #include <lemon/bits/traits.h> 25 26 #include <lemon/concept_check.h> 27 #include <lemon/concept/maps.h> 25 28 26 29 ///\file … … 60 63 : Parent(graph, value) {} 61 64 65 MapExtender& operator=(const MapExtender& cmap) { 66 return operator=<MapExtender>(cmap); 67 } 68 69 template <typename CMap> 70 MapExtender& operator=(const CMap& cmap) { 71 Parent::operator=(cmap); 72 return *this; 73 } 62 74 63 75 class MapIt : public Item { … … 131 143 }; 132 144 133 class ItemIt : Item {145 class ItemIt : public Item { 134 146 public: 135 147 … … 141 153 142 154 explicit ItemIt(Map& _map) : map(_map) { 143 map ->getNotifier()->first(*this);155 map.getNotifier()->first(*this); 144 156 } 145 157 … … 158 170 }; 159 171 172 /// \ingroup graphbits 173 /// 174 /// \brief Extender for maps which use a subset of the items. 175 template <typename _Graph, typename _Map> 176 class SubMapExtender : public _Map { 177 public: 178 179 typedef _Map Parent; 180 typedef SubMapExtender Map; 181 182 typedef _Graph Graph; 183 184 typedef typename Parent::Key Item; 185 186 typedef typename Parent::Key Key; 187 typedef typename Parent::Value Value; 188 189 class MapIt; 190 class ConstMapIt; 191 192 friend class MapIt; 193 friend class ConstMapIt; 194 195 public: 196 197 SubMapExtender(const Graph& _graph) 198 : Parent(_graph), graph(_graph) {} 199 200 SubMapExtender(const Graph& _graph, const Value& _value) 201 : Parent(_graph, _value), graph(_graph) {} 202 203 SubMapExtender& operator=(const SubMapExtender& cmap) { 204 return operator=<MapExtender>(cmap); 205 } 206 207 template <typename CMap> 208 SubMapExtender& operator=(const CMap& cmap) { 209 checkConcept<concept::ReadMap<Key, Value>, CMap>(); 210 Item it; 211 for (graph.first(it); it != INVALID; graph.next(it)) { 212 Parent::set(it, cmap[it]); 213 } 214 return *this; 215 } 216 217 class MapIt : public Item { 218 public: 219 220 typedef Item Parent; 221 typedef typename Map::Value Value; 222 223 MapIt() {} 224 225 MapIt(Invalid i) : Parent(i) { } 226 227 explicit MapIt(Map& _map) : map(_map) { 228 map.graph.first(*this); 229 } 230 231 MapIt(const Map& _map, const Item& item) 232 : Parent(item), map(_map) {} 233 234 MapIt& operator++() { 235 map.graph.next(*this); 236 return *this; 237 } 238 239 typename MapTraits<Map>::ConstReturnValue operator*() const { 240 return map[*this]; 241 } 242 243 typename MapTraits<Map>::ReturnValue operator*() { 244 return map[*this]; 245 } 246 247 void set(const Value& value) { 248 map.set(*this, value); 249 } 250 251 protected: 252 Map& map; 253 254 }; 255 256 class ConstMapIt : public Item { 257 public: 258 259 typedef Item Parent; 260 261 typedef typename Map::Value Value; 262 263 ConstMapIt() {} 264 265 ConstMapIt(Invalid i) : Parent(i) { } 266 267 explicit ConstMapIt(Map& _map) : map(_map) { 268 map.graph.first(*this); 269 } 270 271 ConstMapIt(const Map& _map, const Item& item) 272 : Parent(item), map(_map) {} 273 274 ConstMapIt& operator++() { 275 map.graph.next(*this); 276 return *this; 277 } 278 279 typename MapTraits<Map>::ConstReturnValue operator*() const { 280 return map[*this]; 281 } 282 283 protected: 284 const Map& map; 285 }; 286 287 class ItemIt : public Item { 288 public: 289 290 typedef Item Parent; 291 292 ItemIt() {} 293 294 ItemIt(Invalid i) : Parent(i) { } 295 296 explicit ItemIt(Map& _map) : map(_map) { 297 map.graph.first(*this); 298 } 299 300 ItemIt(const Map& _map, const Item& item) 301 : Parent(item), map(_map) {} 302 303 ItemIt& operator++() { 304 map.graph.next(*this); 305 return *this; 306 } 307 308 protected: 309 const Map& map; 310 311 }; 312 313 private: 314 315 const Graph& graph; 316 317 }; 318 160 319 } 161 320 -
lemon/bits/vector_map.h
r1999 r2031 27 27 28 28 #include <lemon/bits/alteration_notifier.h> 29 30 #include <lemon/concept_check.h> 31 #include <lemon/concept/maps.h> 29 32 30 33 ///\ingroup graphbits … … 113 116 } 114 117 115 private: 116 117 VectorMap& operator=(const VectorMap&); 118 118 /// \brief Assign operator. 119 /// 120 /// This operator assigns for each item in the map the 121 /// value mapped to the same item in the copied map. 122 /// The parameter map should be indiced with the same 123 /// itemset because this assign operator does not change 124 /// the container of the map. 125 VectorMap& operator=(const VectorMap& cmap) { 126 return operator=<VectorMap>(cmap); 127 } 128 129 130 /// \brief Template assign operator. 131 /// 132 /// The given parameter should be conform to the ReadMap 133 /// concecpt and could be indiced by the current item set of 134 /// the NodeMap. In this case the value for each item 135 /// is assigned by the value of the given ReadMap. 136 template <typename CMap> 137 VectorMap& operator=(const CMap& cmap) { 138 checkConcept<concept::ReadMap<Key, _Value>, CMap>(); 139 const typename Parent::Notifier* notifier = Parent::getNotifier(); 140 Item it; 141 for (notifier->first(it); it != INVALID; notifier->next(it)) { 142 set(it, cmap[it]); 143 } 144 return *this; 145 } 146 119 147 public: 120 148
Note: See TracChangeset
for help on using the changeset viewer.