0
2
0
... | ... |
@@ -284,342 +284,342 @@ |
284 | 284 |
typedef typename Parent::Arc Arc; |
285 | 285 |
typedef typename Parent::Edge Edge; |
286 | 286 |
|
287 | 287 |
int maxId(Node) const { |
288 | 288 |
return Parent::maxNodeId(); |
289 | 289 |
} |
290 | 290 |
|
291 | 291 |
int maxId(Arc) const { |
292 | 292 |
return Parent::maxArcId(); |
293 | 293 |
} |
294 | 294 |
|
295 | 295 |
int maxId(Edge) const { |
296 | 296 |
return Parent::maxEdgeId(); |
297 | 297 |
} |
298 | 298 |
|
299 | 299 |
Node fromId(int id, Node) const { |
300 | 300 |
return Parent::nodeFromId(id); |
301 | 301 |
} |
302 | 302 |
|
303 | 303 |
Arc fromId(int id, Arc) const { |
304 | 304 |
return Parent::arcFromId(id); |
305 | 305 |
} |
306 | 306 |
|
307 | 307 |
Edge fromId(int id, Edge) const { |
308 | 308 |
return Parent::edgeFromId(id); |
309 | 309 |
} |
310 | 310 |
|
311 | 311 |
Node oppositeNode(const Node &n, const Edge &e) const { |
312 | 312 |
if( n == Parent::u(e)) |
313 | 313 |
return Parent::v(e); |
314 | 314 |
else if( n == Parent::v(e)) |
315 | 315 |
return Parent::u(e); |
316 | 316 |
else |
317 | 317 |
return INVALID; |
318 | 318 |
} |
319 | 319 |
|
320 | 320 |
Arc oppositeArc(const Arc &e) const { |
321 | 321 |
return Parent::direct(e, !Parent::direction(e)); |
322 | 322 |
} |
323 | 323 |
|
324 | 324 |
using Parent::direct; |
325 | 325 |
Arc direct(const Edge &e, const Node &s) const { |
326 | 326 |
return Parent::direct(e, Parent::u(e) == s); |
327 | 327 |
} |
328 | 328 |
|
329 | 329 |
typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier; |
330 | 330 |
typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier; |
331 | 331 |
|
332 | 332 |
|
333 | 333 |
protected: |
334 | 334 |
|
335 | 335 |
mutable ArcNotifier arc_notifier; |
336 | 336 |
mutable EdgeNotifier edge_notifier; |
337 | 337 |
|
338 | 338 |
public: |
339 | 339 |
|
340 | 340 |
using Parent::notifier; |
341 | 341 |
|
342 | 342 |
ArcNotifier& notifier(Arc) const { |
343 | 343 |
return arc_notifier; |
344 | 344 |
} |
345 | 345 |
|
346 | 346 |
EdgeNotifier& notifier(Edge) const { |
347 | 347 |
return edge_notifier; |
348 | 348 |
} |
349 | 349 |
|
350 | 350 |
|
351 | 351 |
class NodeIt : public Node { |
352 | 352 |
const Graph* graph; |
353 | 353 |
public: |
354 | 354 |
|
355 | 355 |
NodeIt() {} |
356 | 356 |
|
357 | 357 |
NodeIt(Invalid i) : Node(i) { } |
358 | 358 |
|
359 | 359 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) { |
360 | 360 |
_graph.first(static_cast<Node&>(*this)); |
361 | 361 |
} |
362 | 362 |
|
363 | 363 |
NodeIt(const Graph& _graph, const Node& node) |
364 | 364 |
: Node(node), graph(&_graph) {} |
365 | 365 |
|
366 | 366 |
NodeIt& operator++() { |
367 | 367 |
graph->next(*this); |
368 | 368 |
return *this; |
369 | 369 |
} |
370 | 370 |
|
371 | 371 |
}; |
372 | 372 |
|
373 | 373 |
|
374 | 374 |
class ArcIt : public Arc { |
375 | 375 |
const Graph* graph; |
376 | 376 |
public: |
377 | 377 |
|
378 | 378 |
ArcIt() { } |
379 | 379 |
|
380 | 380 |
ArcIt(Invalid i) : Arc(i) { } |
381 | 381 |
|
382 | 382 |
explicit ArcIt(const Graph& _graph) : graph(&_graph) { |
383 | 383 |
_graph.first(static_cast<Arc&>(*this)); |
384 | 384 |
} |
385 | 385 |
|
386 | 386 |
ArcIt(const Graph& _graph, const Arc& e) : |
387 | 387 |
Arc(e), graph(&_graph) { } |
388 | 388 |
|
389 | 389 |
ArcIt& operator++() { |
390 | 390 |
graph->next(*this); |
391 | 391 |
return *this; |
392 | 392 |
} |
393 | 393 |
|
394 | 394 |
}; |
395 | 395 |
|
396 | 396 |
|
397 | 397 |
class OutArcIt : public Arc { |
398 | 398 |
const Graph* graph; |
399 | 399 |
public: |
400 | 400 |
|
401 | 401 |
OutArcIt() { } |
402 | 402 |
|
403 | 403 |
OutArcIt(Invalid i) : Arc(i) { } |
404 | 404 |
|
405 | 405 |
OutArcIt(const Graph& _graph, const Node& node) |
406 | 406 |
: graph(&_graph) { |
407 | 407 |
_graph.firstOut(*this, node); |
408 | 408 |
} |
409 | 409 |
|
410 | 410 |
OutArcIt(const Graph& _graph, const Arc& arc) |
411 | 411 |
: Arc(arc), graph(&_graph) {} |
412 | 412 |
|
413 | 413 |
OutArcIt& operator++() { |
414 | 414 |
graph->nextOut(*this); |
415 | 415 |
return *this; |
416 | 416 |
} |
417 | 417 |
|
418 | 418 |
}; |
419 | 419 |
|
420 | 420 |
|
421 | 421 |
class InArcIt : public Arc { |
422 | 422 |
const Graph* graph; |
423 | 423 |
public: |
424 | 424 |
|
425 | 425 |
InArcIt() { } |
426 | 426 |
|
427 | 427 |
InArcIt(Invalid i) : Arc(i) { } |
428 | 428 |
|
429 | 429 |
InArcIt(const Graph& _graph, const Node& node) |
430 | 430 |
: graph(&_graph) { |
431 | 431 |
_graph.firstIn(*this, node); |
432 | 432 |
} |
433 | 433 |
|
434 | 434 |
InArcIt(const Graph& _graph, const Arc& arc) : |
435 | 435 |
Arc(arc), graph(&_graph) {} |
436 | 436 |
|
437 | 437 |
InArcIt& operator++() { |
438 | 438 |
graph->nextIn(*this); |
439 | 439 |
return *this; |
440 | 440 |
} |
441 | 441 |
|
442 | 442 |
}; |
443 | 443 |
|
444 | 444 |
|
445 | 445 |
class EdgeIt : public Parent::Edge { |
446 | 446 |
const Graph* graph; |
447 | 447 |
public: |
448 | 448 |
|
449 | 449 |
EdgeIt() { } |
450 | 450 |
|
451 | 451 |
EdgeIt(Invalid i) : Edge(i) { } |
452 | 452 |
|
453 | 453 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) { |
454 | 454 |
_graph.first(static_cast<Edge&>(*this)); |
455 | 455 |
} |
456 | 456 |
|
457 | 457 |
EdgeIt(const Graph& _graph, const Edge& e) : |
458 | 458 |
Edge(e), graph(&_graph) { } |
459 | 459 |
|
460 | 460 |
EdgeIt& operator++() { |
461 | 461 |
graph->next(*this); |
462 | 462 |
return *this; |
463 | 463 |
} |
464 | 464 |
|
465 | 465 |
}; |
466 | 466 |
|
467 | 467 |
class IncEdgeIt : public Parent::Edge { |
468 | 468 |
friend class EdgeSetExtender; |
469 | 469 |
const Graph* graph; |
470 | 470 |
bool direction; |
471 | 471 |
public: |
472 | 472 |
|
473 | 473 |
IncEdgeIt() { } |
474 | 474 |
|
475 | 475 |
IncEdgeIt(Invalid i) : Edge(i), direction(false) { } |
476 | 476 |
|
477 | 477 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { |
478 | 478 |
_graph.firstInc(*this, direction, n); |
479 | 479 |
} |
480 | 480 |
|
481 | 481 |
IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n) |
482 | 482 |
: graph(&_graph), Edge(ue) { |
483 | 483 |
direction = (_graph.source(ue) == n); |
484 | 484 |
} |
485 | 485 |
|
486 | 486 |
IncEdgeIt& operator++() { |
487 | 487 |
graph->nextInc(*this, direction); |
488 | 488 |
return *this; |
489 | 489 |
} |
490 | 490 |
}; |
491 | 491 |
|
492 | 492 |
// \brief Base node of the iterator |
493 | 493 |
// |
494 | 494 |
// Returns the base node (ie. the source in this case) of the iterator |
495 | 495 |
Node baseNode(const OutArcIt &e) const { |
496 | 496 |
return Parent::source(static_cast<const Arc&>(e)); |
497 | 497 |
} |
498 | 498 |
// \brief Running node of the iterator |
499 | 499 |
// |
500 | 500 |
// Returns the running node (ie. the target in this case) of the |
501 | 501 |
// iterator |
502 | 502 |
Node runningNode(const OutArcIt &e) const { |
503 | 503 |
return Parent::target(static_cast<const Arc&>(e)); |
504 | 504 |
} |
505 | 505 |
|
506 | 506 |
// \brief Base node of the iterator |
507 | 507 |
// |
508 | 508 |
// Returns the base node (ie. the target in this case) of the iterator |
509 | 509 |
Node baseNode(const InArcIt &e) const { |
510 | 510 |
return Parent::target(static_cast<const Arc&>(e)); |
511 | 511 |
} |
512 | 512 |
// \brief Running node of the iterator |
513 | 513 |
// |
514 | 514 |
// Returns the running node (ie. the source in this case) of the |
515 | 515 |
// iterator |
516 | 516 |
Node runningNode(const InArcIt &e) const { |
517 | 517 |
return Parent::source(static_cast<const Arc&>(e)); |
518 | 518 |
} |
519 | 519 |
|
520 | 520 |
// Base node of the iterator |
521 | 521 |
// |
522 | 522 |
// Returns the base node of the iterator |
523 | 523 |
Node baseNode(const IncEdgeIt &e) const { |
524 | 524 |
return e.direction ? u(e) : v(e); |
525 | 525 |
} |
526 | 526 |
// Running node of the iterator |
527 | 527 |
// |
528 | 528 |
// Returns the running node of the iterator |
529 | 529 |
Node runningNode(const IncEdgeIt &e) const { |
530 | 530 |
return e.direction ? v(e) : u(e); |
531 | 531 |
} |
532 | 532 |
|
533 | 533 |
|
534 | 534 |
template <typename _Value> |
535 | 535 |
class ArcMap |
536 | 536 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > { |
537 | 537 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
538 | 538 |
|
539 | 539 |
public: |
540 |
ArcMap(const Graph& _g) |
|
540 |
explicit ArcMap(const Graph& _g) |
|
541 | 541 |
: Parent(_g) {} |
542 | 542 |
ArcMap(const Graph& _g, const _Value& _v) |
543 | 543 |
: Parent(_g, _v) {} |
544 | 544 |
|
545 | 545 |
ArcMap& operator=(const ArcMap& cmap) { |
546 | 546 |
return operator=<ArcMap>(cmap); |
547 | 547 |
} |
548 | 548 |
|
549 | 549 |
template <typename CMap> |
550 | 550 |
ArcMap& operator=(const CMap& cmap) { |
551 | 551 |
Parent::operator=(cmap); |
552 | 552 |
return *this; |
553 | 553 |
} |
554 | 554 |
|
555 | 555 |
}; |
556 | 556 |
|
557 | 557 |
|
558 | 558 |
template <typename _Value> |
559 | 559 |
class EdgeMap |
560 | 560 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > { |
561 | 561 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
562 | 562 |
|
563 | 563 |
public: |
564 |
EdgeMap(const Graph& _g) |
|
564 |
explicit EdgeMap(const Graph& _g) |
|
565 | 565 |
: Parent(_g) {} |
566 | 566 |
|
567 | 567 |
EdgeMap(const Graph& _g, const _Value& _v) |
568 | 568 |
: Parent(_g, _v) {} |
569 | 569 |
|
570 | 570 |
EdgeMap& operator=(const EdgeMap& cmap) { |
571 | 571 |
return operator=<EdgeMap>(cmap); |
572 | 572 |
} |
573 | 573 |
|
574 | 574 |
template <typename CMap> |
575 | 575 |
EdgeMap& operator=(const CMap& cmap) { |
576 | 576 |
Parent::operator=(cmap); |
577 | 577 |
return *this; |
578 | 578 |
} |
579 | 579 |
|
580 | 580 |
}; |
581 | 581 |
|
582 | 582 |
|
583 | 583 |
// Alteration extension |
584 | 584 |
|
585 | 585 |
Edge addEdge(const Node& from, const Node& to) { |
586 | 586 |
Edge edge = Parent::addEdge(from, to); |
587 | 587 |
notifier(Edge()).add(edge); |
588 | 588 |
std::vector<Arc> arcs; |
589 | 589 |
arcs.push_back(Parent::direct(edge, true)); |
590 | 590 |
arcs.push_back(Parent::direct(edge, false)); |
591 | 591 |
notifier(Arc()).add(arcs); |
592 | 592 |
return edge; |
593 | 593 |
} |
594 | 594 |
|
595 | 595 |
void clear() { |
596 | 596 |
notifier(Arc()).clear(); |
597 | 597 |
notifier(Edge()).clear(); |
598 | 598 |
Parent::clear(); |
599 | 599 |
} |
600 | 600 |
|
601 | 601 |
void erase(const Edge& edge) { |
602 | 602 |
std::vector<Arc> arcs; |
603 | 603 |
arcs.push_back(Parent::direct(edge, true)); |
604 | 604 |
arcs.push_back(Parent::direct(edge, false)); |
605 | 605 |
notifier(Arc()).erase(arcs); |
606 | 606 |
notifier(Edge()).erase(edge); |
607 | 607 |
Parent::erase(edge); |
608 | 608 |
} |
609 | 609 |
|
610 | 610 |
|
611 | 611 |
EdgeSetExtender() { |
612 | 612 |
arc_notifier.setContainer(*this); |
613 | 613 |
edge_notifier.setContainer(*this); |
614 | 614 |
} |
615 | 615 |
|
616 | 616 |
~EdgeSetExtender() { |
617 | 617 |
edge_notifier.clear(); |
618 | 618 |
arc_notifier.clear(); |
619 | 619 |
} |
620 | 620 |
|
621 | 621 |
}; |
622 | 622 |
|
623 | 623 |
} |
624 | 624 |
|
625 | 625 |
#endif |
... | ... |
@@ -351,401 +351,401 @@ |
351 | 351 |
return Parent::maxArcId(); |
352 | 352 |
} |
353 | 353 |
|
354 | 354 |
int maxId(Edge) const { |
355 | 355 |
return Parent::maxEdgeId(); |
356 | 356 |
} |
357 | 357 |
|
358 | 358 |
Node fromId(int id, Node) const { |
359 | 359 |
return Parent::nodeFromId(id); |
360 | 360 |
} |
361 | 361 |
|
362 | 362 |
Arc fromId(int id, Arc) const { |
363 | 363 |
return Parent::arcFromId(id); |
364 | 364 |
} |
365 | 365 |
|
366 | 366 |
Edge fromId(int id, Edge) const { |
367 | 367 |
return Parent::edgeFromId(id); |
368 | 368 |
} |
369 | 369 |
|
370 | 370 |
Node oppositeNode(const Node &n, const Edge &e) const { |
371 | 371 |
if( n == Parent::u(e)) |
372 | 372 |
return Parent::v(e); |
373 | 373 |
else if( n == Parent::v(e)) |
374 | 374 |
return Parent::u(e); |
375 | 375 |
else |
376 | 376 |
return INVALID; |
377 | 377 |
} |
378 | 378 |
|
379 | 379 |
Arc oppositeArc(const Arc &arc) const { |
380 | 380 |
return Parent::direct(arc, !Parent::direction(arc)); |
381 | 381 |
} |
382 | 382 |
|
383 | 383 |
using Parent::direct; |
384 | 384 |
Arc direct(const Edge &edge, const Node &node) const { |
385 | 385 |
return Parent::direct(edge, Parent::u(edge) == node); |
386 | 386 |
} |
387 | 387 |
|
388 | 388 |
// Alterable extension |
389 | 389 |
|
390 | 390 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier; |
391 | 391 |
typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier; |
392 | 392 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier; |
393 | 393 |
|
394 | 394 |
|
395 | 395 |
protected: |
396 | 396 |
|
397 | 397 |
mutable NodeNotifier node_notifier; |
398 | 398 |
mutable ArcNotifier arc_notifier; |
399 | 399 |
mutable EdgeNotifier edge_notifier; |
400 | 400 |
|
401 | 401 |
public: |
402 | 402 |
|
403 | 403 |
NodeNotifier& notifier(Node) const { |
404 | 404 |
return node_notifier; |
405 | 405 |
} |
406 | 406 |
|
407 | 407 |
ArcNotifier& notifier(Arc) const { |
408 | 408 |
return arc_notifier; |
409 | 409 |
} |
410 | 410 |
|
411 | 411 |
EdgeNotifier& notifier(Edge) const { |
412 | 412 |
return edge_notifier; |
413 | 413 |
} |
414 | 414 |
|
415 | 415 |
|
416 | 416 |
|
417 | 417 |
class NodeIt : public Node { |
418 | 418 |
const Graph* _graph; |
419 | 419 |
public: |
420 | 420 |
|
421 | 421 |
NodeIt() {} |
422 | 422 |
|
423 | 423 |
NodeIt(Invalid i) : Node(i) { } |
424 | 424 |
|
425 | 425 |
explicit NodeIt(const Graph& graph) : _graph(&graph) { |
426 | 426 |
_graph->first(static_cast<Node&>(*this)); |
427 | 427 |
} |
428 | 428 |
|
429 | 429 |
NodeIt(const Graph& graph, const Node& node) |
430 | 430 |
: Node(node), _graph(&graph) {} |
431 | 431 |
|
432 | 432 |
NodeIt& operator++() { |
433 | 433 |
_graph->next(*this); |
434 | 434 |
return *this; |
435 | 435 |
} |
436 | 436 |
|
437 | 437 |
}; |
438 | 438 |
|
439 | 439 |
|
440 | 440 |
class ArcIt : public Arc { |
441 | 441 |
const Graph* _graph; |
442 | 442 |
public: |
443 | 443 |
|
444 | 444 |
ArcIt() { } |
445 | 445 |
|
446 | 446 |
ArcIt(Invalid i) : Arc(i) { } |
447 | 447 |
|
448 | 448 |
explicit ArcIt(const Graph& graph) : _graph(&graph) { |
449 | 449 |
_graph->first(static_cast<Arc&>(*this)); |
450 | 450 |
} |
451 | 451 |
|
452 | 452 |
ArcIt(const Graph& graph, const Arc& arc) : |
453 | 453 |
Arc(arc), _graph(&graph) { } |
454 | 454 |
|
455 | 455 |
ArcIt& operator++() { |
456 | 456 |
_graph->next(*this); |
457 | 457 |
return *this; |
458 | 458 |
} |
459 | 459 |
|
460 | 460 |
}; |
461 | 461 |
|
462 | 462 |
|
463 | 463 |
class OutArcIt : public Arc { |
464 | 464 |
const Graph* _graph; |
465 | 465 |
public: |
466 | 466 |
|
467 | 467 |
OutArcIt() { } |
468 | 468 |
|
469 | 469 |
OutArcIt(Invalid i) : Arc(i) { } |
470 | 470 |
|
471 | 471 |
OutArcIt(const Graph& graph, const Node& node) |
472 | 472 |
: _graph(&graph) { |
473 | 473 |
_graph->firstOut(*this, node); |
474 | 474 |
} |
475 | 475 |
|
476 | 476 |
OutArcIt(const Graph& graph, const Arc& arc) |
477 | 477 |
: Arc(arc), _graph(&graph) {} |
478 | 478 |
|
479 | 479 |
OutArcIt& operator++() { |
480 | 480 |
_graph->nextOut(*this); |
481 | 481 |
return *this; |
482 | 482 |
} |
483 | 483 |
|
484 | 484 |
}; |
485 | 485 |
|
486 | 486 |
|
487 | 487 |
class InArcIt : public Arc { |
488 | 488 |
const Graph* _graph; |
489 | 489 |
public: |
490 | 490 |
|
491 | 491 |
InArcIt() { } |
492 | 492 |
|
493 | 493 |
InArcIt(Invalid i) : Arc(i) { } |
494 | 494 |
|
495 | 495 |
InArcIt(const Graph& graph, const Node& node) |
496 | 496 |
: _graph(&graph) { |
497 | 497 |
_graph->firstIn(*this, node); |
498 | 498 |
} |
499 | 499 |
|
500 | 500 |
InArcIt(const Graph& graph, const Arc& arc) : |
501 | 501 |
Arc(arc), _graph(&graph) {} |
502 | 502 |
|
503 | 503 |
InArcIt& operator++() { |
504 | 504 |
_graph->nextIn(*this); |
505 | 505 |
return *this; |
506 | 506 |
} |
507 | 507 |
|
508 | 508 |
}; |
509 | 509 |
|
510 | 510 |
|
511 | 511 |
class EdgeIt : public Parent::Edge { |
512 | 512 |
const Graph* _graph; |
513 | 513 |
public: |
514 | 514 |
|
515 | 515 |
EdgeIt() { } |
516 | 516 |
|
517 | 517 |
EdgeIt(Invalid i) : Edge(i) { } |
518 | 518 |
|
519 | 519 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) { |
520 | 520 |
_graph->first(static_cast<Edge&>(*this)); |
521 | 521 |
} |
522 | 522 |
|
523 | 523 |
EdgeIt(const Graph& graph, const Edge& edge) : |
524 | 524 |
Edge(edge), _graph(&graph) { } |
525 | 525 |
|
526 | 526 |
EdgeIt& operator++() { |
527 | 527 |
_graph->next(*this); |
528 | 528 |
return *this; |
529 | 529 |
} |
530 | 530 |
|
531 | 531 |
}; |
532 | 532 |
|
533 | 533 |
class IncEdgeIt : public Parent::Edge { |
534 | 534 |
friend class GraphExtender; |
535 | 535 |
const Graph* _graph; |
536 | 536 |
bool _direction; |
537 | 537 |
public: |
538 | 538 |
|
539 | 539 |
IncEdgeIt() { } |
540 | 540 |
|
541 | 541 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { } |
542 | 542 |
|
543 | 543 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) { |
544 | 544 |
_graph->firstInc(*this, _direction, node); |
545 | 545 |
} |
546 | 546 |
|
547 | 547 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
548 | 548 |
: _graph(&graph), Edge(edge) { |
549 | 549 |
_direction = (_graph->source(edge) == node); |
550 | 550 |
} |
551 | 551 |
|
552 | 552 |
IncEdgeIt& operator++() { |
553 | 553 |
_graph->nextInc(*this, _direction); |
554 | 554 |
return *this; |
555 | 555 |
} |
556 | 556 |
}; |
557 | 557 |
|
558 | 558 |
// \brief Base node of the iterator |
559 | 559 |
// |
560 | 560 |
// Returns the base node (ie. the source in this case) of the iterator |
561 | 561 |
Node baseNode(const OutArcIt &arc) const { |
562 | 562 |
return Parent::source(static_cast<const Arc&>(arc)); |
563 | 563 |
} |
564 | 564 |
// \brief Running node of the iterator |
565 | 565 |
// |
566 | 566 |
// Returns the running node (ie. the target in this case) of the |
567 | 567 |
// iterator |
568 | 568 |
Node runningNode(const OutArcIt &arc) const { |
569 | 569 |
return Parent::target(static_cast<const Arc&>(arc)); |
570 | 570 |
} |
571 | 571 |
|
572 | 572 |
// \brief Base node of the iterator |
573 | 573 |
// |
574 | 574 |
// Returns the base node (ie. the target in this case) of the iterator |
575 | 575 |
Node baseNode(const InArcIt &arc) const { |
576 | 576 |
return Parent::target(static_cast<const Arc&>(arc)); |
577 | 577 |
} |
578 | 578 |
// \brief Running node of the iterator |
579 | 579 |
// |
580 | 580 |
// Returns the running node (ie. the source in this case) of the |
581 | 581 |
// iterator |
582 | 582 |
Node runningNode(const InArcIt &arc) const { |
583 | 583 |
return Parent::source(static_cast<const Arc&>(arc)); |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
// Base node of the iterator |
587 | 587 |
// |
588 | 588 |
// Returns the base node of the iterator |
589 | 589 |
Node baseNode(const IncEdgeIt &edge) const { |
590 | 590 |
return edge._direction ? u(edge) : v(edge); |
591 | 591 |
} |
592 | 592 |
// Running node of the iterator |
593 | 593 |
// |
594 | 594 |
// Returns the running node of the iterator |
595 | 595 |
Node runningNode(const IncEdgeIt &edge) const { |
596 | 596 |
return edge._direction ? v(edge) : u(edge); |
597 | 597 |
} |
598 | 598 |
|
599 | 599 |
// Mappable extension |
600 | 600 |
|
601 | 601 |
template <typename _Value> |
602 | 602 |
class NodeMap |
603 | 603 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > { |
604 | 604 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
605 | 605 |
|
606 | 606 |
public: |
607 |
NodeMap(const Graph& graph) |
|
607 |
explicit NodeMap(const Graph& graph) |
|
608 | 608 |
: Parent(graph) {} |
609 | 609 |
NodeMap(const Graph& graph, const _Value& value) |
610 | 610 |
: Parent(graph, value) {} |
611 | 611 |
|
612 | 612 |
private: |
613 | 613 |
NodeMap& operator=(const NodeMap& cmap) { |
614 | 614 |
return operator=<NodeMap>(cmap); |
615 | 615 |
} |
616 | 616 |
|
617 | 617 |
template <typename CMap> |
618 | 618 |
NodeMap& operator=(const CMap& cmap) { |
619 | 619 |
Parent::operator=(cmap); |
620 | 620 |
return *this; |
621 | 621 |
} |
622 | 622 |
|
623 | 623 |
}; |
624 | 624 |
|
625 | 625 |
template <typename _Value> |
626 | 626 |
class ArcMap |
627 | 627 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > { |
628 | 628 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
629 | 629 |
|
630 | 630 |
public: |
631 |
ArcMap(const Graph& graph) |
|
631 |
explicit ArcMap(const Graph& graph) |
|
632 | 632 |
: Parent(graph) {} |
633 | 633 |
ArcMap(const Graph& graph, const _Value& value) |
634 | 634 |
: Parent(graph, value) {} |
635 | 635 |
|
636 | 636 |
private: |
637 | 637 |
ArcMap& operator=(const ArcMap& cmap) { |
638 | 638 |
return operator=<ArcMap>(cmap); |
639 | 639 |
} |
640 | 640 |
|
641 | 641 |
template <typename CMap> |
642 | 642 |
ArcMap& operator=(const CMap& cmap) { |
643 | 643 |
Parent::operator=(cmap); |
644 | 644 |
return *this; |
645 | 645 |
} |
646 | 646 |
}; |
647 | 647 |
|
648 | 648 |
|
649 | 649 |
template <typename _Value> |
650 | 650 |
class EdgeMap |
651 | 651 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > { |
652 | 652 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
653 | 653 |
|
654 | 654 |
public: |
655 |
EdgeMap(const Graph& graph) |
|
655 |
explicit EdgeMap(const Graph& graph) |
|
656 | 656 |
: Parent(graph) {} |
657 | 657 |
|
658 | 658 |
EdgeMap(const Graph& graph, const _Value& value) |
659 | 659 |
: Parent(graph, value) {} |
660 | 660 |
|
661 | 661 |
private: |
662 | 662 |
EdgeMap& operator=(const EdgeMap& cmap) { |
663 | 663 |
return operator=<EdgeMap>(cmap); |
664 | 664 |
} |
665 | 665 |
|
666 | 666 |
template <typename CMap> |
667 | 667 |
EdgeMap& operator=(const CMap& cmap) { |
668 | 668 |
Parent::operator=(cmap); |
669 | 669 |
return *this; |
670 | 670 |
} |
671 | 671 |
|
672 | 672 |
}; |
673 | 673 |
|
674 | 674 |
// Alteration extension |
675 | 675 |
|
676 | 676 |
Node addNode() { |
677 | 677 |
Node node = Parent::addNode(); |
678 | 678 |
notifier(Node()).add(node); |
679 | 679 |
return node; |
680 | 680 |
} |
681 | 681 |
|
682 | 682 |
Edge addEdge(const Node& from, const Node& to) { |
683 | 683 |
Edge edge = Parent::addEdge(from, to); |
684 | 684 |
notifier(Edge()).add(edge); |
685 | 685 |
std::vector<Arc> ev; |
686 | 686 |
ev.push_back(Parent::direct(edge, true)); |
687 | 687 |
ev.push_back(Parent::direct(edge, false)); |
688 | 688 |
notifier(Arc()).add(ev); |
689 | 689 |
return edge; |
690 | 690 |
} |
691 | 691 |
|
692 | 692 |
void clear() { |
693 | 693 |
notifier(Arc()).clear(); |
694 | 694 |
notifier(Edge()).clear(); |
695 | 695 |
notifier(Node()).clear(); |
696 | 696 |
Parent::clear(); |
697 | 697 |
} |
698 | 698 |
|
699 | 699 |
template <typename Graph, typename NodeRefMap, typename EdgeRefMap> |
700 | 700 |
void build(const Graph& graph, NodeRefMap& nodeRef, |
701 | 701 |
EdgeRefMap& edgeRef) { |
702 | 702 |
Parent::build(graph, nodeRef, edgeRef); |
703 | 703 |
notifier(Node()).build(); |
704 | 704 |
notifier(Edge()).build(); |
705 | 705 |
notifier(Arc()).build(); |
706 | 706 |
} |
707 | 707 |
|
708 | 708 |
void erase(const Node& node) { |
709 | 709 |
Arc arc; |
710 | 710 |
Parent::firstOut(arc, node); |
711 | 711 |
while (arc != INVALID ) { |
712 | 712 |
erase(arc); |
713 | 713 |
Parent::firstOut(arc, node); |
714 | 714 |
} |
715 | 715 |
|
716 | 716 |
Parent::firstIn(arc, node); |
717 | 717 |
while (arc != INVALID ) { |
718 | 718 |
erase(arc); |
719 | 719 |
Parent::firstIn(arc, node); |
720 | 720 |
} |
721 | 721 |
|
722 | 722 |
notifier(Node()).erase(node); |
723 | 723 |
Parent::erase(node); |
724 | 724 |
} |
725 | 725 |
|
726 | 726 |
void erase(const Edge& edge) { |
727 | 727 |
std::vector<Arc> av; |
728 | 728 |
av.push_back(Parent::direct(edge, true)); |
729 | 729 |
av.push_back(Parent::direct(edge, false)); |
730 | 730 |
notifier(Arc()).erase(av); |
731 | 731 |
notifier(Edge()).erase(edge); |
732 | 732 |
Parent::erase(edge); |
733 | 733 |
} |
734 | 734 |
|
735 | 735 |
GraphExtender() { |
736 | 736 |
node_notifier.setContainer(*this); |
737 | 737 |
arc_notifier.setContainer(*this); |
738 | 738 |
edge_notifier.setContainer(*this); |
739 | 739 |
} |
740 | 740 |
|
741 | 741 |
~GraphExtender() { |
742 | 742 |
edge_notifier.clear(); |
743 | 743 |
arc_notifier.clear(); |
744 | 744 |
node_notifier.clear(); |
745 | 745 |
} |
746 | 746 |
|
747 | 747 |
}; |
748 | 748 |
|
749 | 749 |
} |
750 | 750 |
|
751 | 751 |
#endif |
0 comments (0 inline)