453 /// reader.run(); |
453 /// reader.run(); |
454 /// \endcode |
454 /// \endcode |
455 /// |
455 /// |
456 /// \see GraphReader |
456 /// \see GraphReader |
457 /// \see DefaultReaderTraits |
457 /// \see DefaultReaderTraits |
458 /// \see \ref UndirGraphWriter |
458 /// \see \ref UGraphWriter |
459 /// \see \ref graph-io-page |
459 /// \see \ref graph-io-page |
460 /// |
460 /// |
461 /// \author Balazs Dezso |
461 /// \author Balazs Dezso |
462 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits> |
462 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits> |
463 class UndirGraphReader { |
463 class UGraphReader { |
464 public: |
464 public: |
465 |
465 |
466 typedef _Graph Graph; |
466 typedef _Graph Graph; |
467 typedef typename Graph::Node Node; |
467 typedef typename Graph::Node Node; |
468 typedef typename Graph::Edge Edge; |
468 typedef typename Graph::Edge Edge; |
469 typedef typename Graph::UndirEdge UndirEdge; |
469 typedef typename Graph::UEdge UEdge; |
470 |
470 |
471 typedef _ReaderTraits ReaderTraits; |
471 typedef _ReaderTraits ReaderTraits; |
472 typedef typename ReaderTraits::Skipper DefaultSkipper; |
472 typedef typename ReaderTraits::Skipper DefaultSkipper; |
473 |
473 |
474 /// \brief Construct a new UndirGraphReader. |
474 /// \brief Construct a new UGraphReader. |
475 /// |
475 /// |
476 /// Construct a new UndirGraphReader. It reads into the given graph |
476 /// Construct a new UGraphReader. It reads into the given graph |
477 /// and it use the given reader as the default skipper. |
477 /// and it use the given reader as the default skipper. |
478 UndirGraphReader(std::istream& _is, Graph& _graph, |
478 UGraphReader(std::istream& _is, Graph& _graph, |
479 const DefaultSkipper& _skipper = DefaultSkipper()) |
479 const DefaultSkipper& _skipper = DefaultSkipper()) |
480 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper), |
480 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper), |
481 nodeset_reader(*reader, _graph, std::string(), skipper), |
481 nodeset_reader(*reader, _graph, std::string(), skipper), |
482 undir_edgeset_reader(*reader, _graph, nodeset_reader, |
482 u_edgeset_reader(*reader, _graph, nodeset_reader, |
483 std::string(), skipper), |
483 std::string(), skipper), |
484 node_reader(*reader, nodeset_reader, std::string()), |
484 node_reader(*reader, nodeset_reader, std::string()), |
485 undir_edge_reader(*reader, undir_edgeset_reader, std::string()), |
485 u_edge_reader(*reader, u_edgeset_reader, std::string()), |
486 attribute_reader(*reader, std::string()) {} |
486 attribute_reader(*reader, std::string()) {} |
487 |
487 |
488 /// \brief Construct a new UndirGraphReader. |
488 /// \brief Construct a new UGraphReader. |
489 /// |
489 /// |
490 /// Construct a new UndirGraphReader. It reads into the given graph |
490 /// Construct a new UGraphReader. It reads into the given graph |
491 /// and it use the given reader as the default skipper. |
491 /// and it use the given reader as the default skipper. |
492 UndirGraphReader(const std::string& _filename, Graph& _graph, |
492 UGraphReader(const std::string& _filename, Graph& _graph, |
493 const DefaultSkipper& _skipper = DefaultSkipper()) |
493 const DefaultSkipper& _skipper = DefaultSkipper()) |
494 : reader(new LemonReader(_filename)), own_reader(true), |
494 : reader(new LemonReader(_filename)), own_reader(true), |
495 skipper(_skipper), |
495 skipper(_skipper), |
496 nodeset_reader(*reader, _graph, std::string(), skipper), |
496 nodeset_reader(*reader, _graph, std::string(), skipper), |
497 undir_edgeset_reader(*reader, _graph, nodeset_reader, |
497 u_edgeset_reader(*reader, _graph, nodeset_reader, |
498 std::string(), skipper), |
498 std::string(), skipper), |
499 node_reader(*reader, nodeset_reader, std::string()), |
499 node_reader(*reader, nodeset_reader, std::string()), |
500 undir_edge_reader(*reader, undir_edgeset_reader, std::string()), |
500 u_edge_reader(*reader, u_edgeset_reader, std::string()), |
501 attribute_reader(*reader, std::string()) {} |
501 attribute_reader(*reader, std::string()) {} |
502 |
502 |
503 /// \brief Construct a new UndirGraphReader. |
503 /// \brief Construct a new UGraphReader. |
504 /// |
504 /// |
505 /// Construct a new UndirGraphReader. It reads into the given graph |
505 /// Construct a new UGraphReader. It reads into the given graph |
506 /// and it use the given reader as the default skipper. |
506 /// and it use the given reader as the default skipper. |
507 UndirGraphReader(LemonReader& _reader, Graph& _graph, |
507 UGraphReader(LemonReader& _reader, Graph& _graph, |
508 const DefaultSkipper& _skipper = DefaultSkipper()) |
508 const DefaultSkipper& _skipper = DefaultSkipper()) |
509 : reader(_reader), own_reader(false), skipper(_skipper), |
509 : reader(_reader), own_reader(false), skipper(_skipper), |
510 nodeset_reader(*reader, _graph, std::string(), skipper), |
510 nodeset_reader(*reader, _graph, std::string(), skipper), |
511 undir_edgeset_reader(*reader, _graph, nodeset_reader, |
511 u_edgeset_reader(*reader, _graph, nodeset_reader, |
512 std::string(), skipper), |
512 std::string(), skipper), |
513 node_reader(*reader, nodeset_reader, std::string()), |
513 node_reader(*reader, nodeset_reader, std::string()), |
514 undir_edge_reader(*reader, undir_edgeset_reader, std::string()), |
514 u_edge_reader(*reader, u_edgeset_reader, std::string()), |
515 attribute_reader(*reader, std::string()) {} |
515 attribute_reader(*reader, std::string()) {} |
516 |
516 |
517 /// \brief Destruct the graph reader. |
517 /// \brief Destruct the graph reader. |
518 /// |
518 /// |
519 /// Destruct the graph reader. |
519 /// Destruct the graph reader. |
520 ~UndirGraphReader() { |
520 ~UGraphReader() { |
521 if (own_reader) |
521 if (own_reader) |
522 delete reader; |
522 delete reader; |
523 } |
523 } |
524 |
524 |
525 /// \brief Give a new node map reading command to the reader. |
525 /// \brief Give a new node map reading command to the reader. |
526 /// |
526 /// |
527 /// Give a new node map reading command to the reader. |
527 /// Give a new node map reading command to the reader. |
528 template <typename Map> |
528 template <typename Map> |
529 UndirGraphReader& readNodeMap(std::string name, Map& map) { |
529 UGraphReader& readNodeMap(std::string name, Map& map) { |
530 nodeset_reader.readNodeMap(name, map); |
530 nodeset_reader.readNodeMap(name, map); |
531 return *this; |
531 return *this; |
532 } |
532 } |
533 |
533 |
534 template <typename Map> |
534 template <typename Map> |
535 UndirGraphReader& readNodeMap(std::string name, const Map& map) { |
535 UGraphReader& readNodeMap(std::string name, const Map& map) { |
536 nodeset_reader.readNodeMap(name, map); |
536 nodeset_reader.readNodeMap(name, map); |
537 return *this; |
537 return *this; |
538 } |
538 } |
539 |
539 |
540 /// \brief Give a new node map reading command to the reader. |
540 /// \brief Give a new node map reading command to the reader. |
541 /// |
541 /// |
542 /// Give a new node map reading command to the reader. |
542 /// Give a new node map reading command to the reader. |
543 template <typename Reader, typename Map> |
543 template <typename Reader, typename Map> |
544 UndirGraphReader& readNodeMap(std::string name, Map& map, |
544 UGraphReader& readNodeMap(std::string name, Map& map, |
545 const Reader& reader = Reader()) { |
545 const Reader& reader = Reader()) { |
546 nodeset_reader.readNodeMap(name, map, reader); |
546 nodeset_reader.readNodeMap(name, map, reader); |
547 return *this; |
547 return *this; |
548 } |
548 } |
549 |
549 |
550 template <typename Reader, typename Map> |
550 template <typename Reader, typename Map> |
551 UndirGraphReader& readNodeMap(std::string name, const Map& map, |
551 UGraphReader& readNodeMap(std::string name, const Map& map, |
552 const Reader& reader = Reader()) { |
552 const Reader& reader = Reader()) { |
553 nodeset_reader.readNodeMap(name, map, reader); |
553 nodeset_reader.readNodeMap(name, map, reader); |
554 return *this; |
554 return *this; |
555 } |
555 } |
556 |
556 |
557 /// \brief Give a new node map skipping command to the reader. |
557 /// \brief Give a new node map skipping command to the reader. |
558 /// |
558 /// |
559 /// Give a new node map skipping command to the reader. |
559 /// Give a new node map skipping command to the reader. |
560 template <typename Reader> |
560 template <typename Reader> |
561 UndirGraphReader& skipNodeMap(std::string name, |
561 UGraphReader& skipNodeMap(std::string name, |
562 const Reader& reader = Reader()) { |
562 const Reader& reader = Reader()) { |
563 nodeset_reader.skipNodeMap(name, reader); |
563 nodeset_reader.skipNodeMap(name, reader); |
564 return *this; |
564 return *this; |
565 } |
565 } |
566 |
566 |
567 /// \brief Give a new undirected edge map reading command to the reader. |
567 /// \brief Give a new undirected edge map reading command to the reader. |
568 /// |
568 /// |
569 /// Give a new undirected edge map reading command to the reader. |
569 /// Give a new undirected edge map reading command to the reader. |
570 template <typename Map> |
570 template <typename Map> |
571 UndirGraphReader& readUndirEdgeMap(std::string name, Map& map) { |
571 UGraphReader& readUEdgeMap(std::string name, Map& map) { |
572 undir_edgeset_reader.readUndirEdgeMap(name, map); |
572 u_edgeset_reader.readUEdgeMap(name, map); |
573 return *this; |
573 return *this; |
574 } |
574 } |
575 |
575 |
576 template <typename Map> |
576 template <typename Map> |
577 UndirGraphReader& readUndirEdgeMap(std::string name, const Map& map) { |
577 UGraphReader& readUEdgeMap(std::string name, const Map& map) { |
578 undir_edgeset_reader.readUndirEdgeMap(name, map); |
578 u_edgeset_reader.readUEdgeMap(name, map); |
579 return *this; |
579 return *this; |
580 } |
580 } |
581 |
581 |
582 |
582 |
583 /// \brief Give a new undirected edge map reading command to the reader. |
583 /// \brief Give a new undirected edge map reading command to the reader. |
584 /// |
584 /// |
585 /// Give a new undirected edge map reading command to the reader. |
585 /// Give a new undirected edge map reading command to the reader. |
586 template <typename Reader, typename Map> |
586 template <typename Reader, typename Map> |
587 UndirGraphReader& readUndirEdgeMap(std::string name, Map& map, |
587 UGraphReader& readUEdgeMap(std::string name, Map& map, |
588 const Reader& reader = Reader()) { |
588 const Reader& reader = Reader()) { |
589 undir_edgeset_reader.readUndirEdgeMap(name, map, reader); |
589 u_edgeset_reader.readUEdgeMap(name, map, reader); |
590 return *this; |
590 return *this; |
591 } |
591 } |
592 |
592 |
593 template <typename Reader, typename Map> |
593 template <typename Reader, typename Map> |
594 UndirGraphReader& readUndirEdgeMap(std::string name, const Map& map, |
594 UGraphReader& readUEdgeMap(std::string name, const Map& map, |
595 const Reader& reader = Reader()) { |
595 const Reader& reader = Reader()) { |
596 undir_edgeset_reader.readUndirEdgeMap(name, map, reader); |
596 u_edgeset_reader.readUEdgeMap(name, map, reader); |
597 return *this; |
597 return *this; |
598 } |
598 } |
599 |
599 |
600 /// \brief Give a new undirected edge map skipping command to the reader. |
600 /// \brief Give a new undirected edge map skipping command to the reader. |
601 /// |
601 /// |
602 /// Give a new undirected edge map skipping command to the reader. |
602 /// Give a new undirected edge map skipping command to the reader. |
603 template <typename Reader> |
603 template <typename Reader> |
604 UndirGraphReader& skipUndirEdgeMap(std::string name, |
604 UGraphReader& skipUEdgeMap(std::string name, |
605 const Reader& reader = Reader()) { |
605 const Reader& reader = Reader()) { |
606 undir_edgeset_reader.skipUndirMap(name, reader); |
606 u_edgeset_reader.skipUMap(name, reader); |
607 return *this; |
607 return *this; |
608 } |
608 } |
609 |
609 |
610 |
610 |
611 /// \brief Give a new edge map reading command to the reader. |
611 /// \brief Give a new edge map reading command to the reader. |
612 /// |
612 /// |
613 /// Give a new edge map reading command to the reader. |
613 /// Give a new edge map reading command to the reader. |
614 template <typename Map> |
614 template <typename Map> |
615 UndirGraphReader& readEdgeMap(std::string name, Map& map) { |
615 UGraphReader& readEdgeMap(std::string name, Map& map) { |
616 undir_edgeset_reader.readEdgeMap(name, map); |
616 u_edgeset_reader.readEdgeMap(name, map); |
617 return *this; |
617 return *this; |
618 } |
618 } |
619 |
619 |
620 template <typename Map> |
620 template <typename Map> |
621 UndirGraphReader& readEdgeMap(std::string name, const Map& map) { |
621 UGraphReader& readEdgeMap(std::string name, const Map& map) { |
622 undir_edgeset_reader.readEdgeMap(name, map); |
622 u_edgeset_reader.readEdgeMap(name, map); |
623 return *this; |
623 return *this; |
624 } |
624 } |
625 |
625 |
626 |
626 |
627 /// \brief Give a new edge map reading command to the reader. |
627 /// \brief Give a new edge map reading command to the reader. |
628 /// |
628 /// |
629 /// Give a new edge map reading command to the reader. |
629 /// Give a new edge map reading command to the reader. |
630 template <typename Reader, typename Map> |
630 template <typename Reader, typename Map> |
631 UndirGraphReader& readEdgeMap(std::string name, Map& map, |
631 UGraphReader& readEdgeMap(std::string name, Map& map, |
632 const Reader& reader = Reader()) { |
632 const Reader& reader = Reader()) { |
633 undir_edgeset_reader.readEdgeMap(name, map, reader); |
633 u_edgeset_reader.readEdgeMap(name, map, reader); |
634 return *this; |
634 return *this; |
635 } |
635 } |
636 |
636 |
637 template <typename Reader, typename Map> |
637 template <typename Reader, typename Map> |
638 UndirGraphReader& readEdgeMap(std::string name, const Map& map, |
638 UGraphReader& readEdgeMap(std::string name, const Map& map, |
639 const Reader& reader = Reader()) { |
639 const Reader& reader = Reader()) { |
640 undir_edgeset_reader.readEdgeMap(name, map, reader); |
640 u_edgeset_reader.readEdgeMap(name, map, reader); |
641 return *this; |
641 return *this; |
642 } |
642 } |
643 |
643 |
644 /// \brief Give a new edge map skipping command to the reader. |
644 /// \brief Give a new edge map skipping command to the reader. |
645 /// |
645 /// |
646 /// Give a new edge map skipping command to the reader. |
646 /// Give a new edge map skipping command to the reader. |
647 template <typename Reader> |
647 template <typename Reader> |
648 UndirGraphReader& skipEdgeMap(std::string name, |
648 UGraphReader& skipEdgeMap(std::string name, |
649 const Reader& reader = Reader()) { |
649 const Reader& reader = Reader()) { |
650 undir_edgeset_reader.skipEdgeMap(name, reader); |
650 u_edgeset_reader.skipEdgeMap(name, reader); |
651 return *this; |
651 return *this; |
652 } |
652 } |
653 |
653 |
654 /// \brief Give a new labeled node reading command to the reader. |
654 /// \brief Give a new labeled node reading command to the reader. |
655 /// |
655 /// |
656 /// Give a new labeled node reading command to the reader. |
656 /// Give a new labeled node reading command to the reader. |
657 UndirGraphReader& readNode(std::string name, Node& node) { |
657 UGraphReader& readNode(std::string name, Node& node) { |
658 node_reader.readNode(name, node); |
658 node_reader.readNode(name, node); |
659 return *this; |
659 return *this; |
660 } |
660 } |
661 |
661 |
662 /// \brief Give a new labeled edge reading command to the reader. |
662 /// \brief Give a new labeled edge reading command to the reader. |
663 /// |
663 /// |
664 /// Give a new labeled edge reading command to the reader. |
664 /// Give a new labeled edge reading command to the reader. |
665 UndirGraphReader& readEdge(std::string name, Edge& edge) { |
665 UGraphReader& readEdge(std::string name, Edge& edge) { |
666 undir_edge_reader.readEdge(name, edge); |
666 u_edge_reader.readEdge(name, edge); |
667 } |
667 } |
668 |
668 |
669 /// \brief Give a new labeled undirected edge reading command to the |
669 /// \brief Give a new labeled undirected edge reading command to the |
670 /// reader. |
670 /// reader. |
671 /// |
671 /// |
672 /// Give a new labeled undirected edge reading command to the reader. |
672 /// Give a new labeled undirected edge reading command to the reader. |
673 UndirGraphReader& readUndirEdge(std::string name, UndirEdge& edge) { |
673 UGraphReader& readUEdge(std::string name, UEdge& edge) { |
674 undir_edge_reader.readUndirEdge(name, edge); |
674 u_edge_reader.readUEdge(name, edge); |
675 } |
675 } |
676 |
676 |
677 /// \brief Give a new attribute reading command. |
677 /// \brief Give a new attribute reading command. |
678 /// |
678 /// |
679 /// Give a new attribute reading command. |
679 /// Give a new attribute reading command. |
680 template <typename Value> |
680 template <typename Value> |
681 UndirGraphReader& readAttribute(std::string name, Value& value) { |
681 UGraphReader& readAttribute(std::string name, Value& value) { |
682 attribute_reader.readAttribute(name, value); |
682 attribute_reader.readAttribute(name, value); |
683 return *this; |
683 return *this; |
684 } |
684 } |
685 |
685 |
686 /// \brief Give a new attribute reading command. |
686 /// \brief Give a new attribute reading command. |
687 /// |
687 /// |
688 /// Give a new attribute reading command. |
688 /// Give a new attribute reading command. |
689 template <typename Reader, typename Value> |
689 template <typename Reader, typename Value> |
690 UndirGraphReader& readAttribute(std::string name, Value& value, |
690 UGraphReader& readAttribute(std::string name, Value& value, |
691 const Reader& reader) { |
691 const Reader& reader) { |
692 attribute_reader.readAttribute<Reader>(name, value, reader); |
692 attribute_reader.readAttribute<Reader>(name, value, reader); |
693 return *this; |
693 return *this; |
694 } |
694 } |
695 |
695 |