586 for (; it != INVALID; ++it) { |
583 for (; it != INVALID; ++it) { |
587 target[it] = source[it]; |
584 target[it] = source[it]; |
588 } |
585 } |
589 } |
586 } |
590 |
587 |
|
588 namespace _graph_utils_bits { |
|
589 |
|
590 template <typename Graph, typename Item, typename RefMap> |
|
591 class MapCopyBase { |
|
592 public: |
|
593 virtual void copy(const Graph& source, const RefMap& refMap) = 0; |
|
594 |
|
595 virtual ~MapCopyBase() {} |
|
596 }; |
|
597 |
|
598 template <typename Graph, typename Item, typename RefMap, |
|
599 typename TargetMap, typename SourceMap> |
|
600 class MapCopy : public MapCopyBase<Graph, Item, RefMap> { |
|
601 public: |
|
602 |
|
603 MapCopy(TargetMap& tmap, const SourceMap& map) |
|
604 : _tmap(tmap), _map(map) {} |
|
605 |
|
606 virtual void copy(const Graph& graph, const RefMap& refMap) { |
|
607 typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt; |
|
608 for (ItemIt it(graph); it != INVALID; ++it) { |
|
609 _tmap.set(refMap[it], _map[it]); |
|
610 } |
|
611 } |
|
612 |
|
613 private: |
|
614 TargetMap& _tmap; |
|
615 const SourceMap& _map; |
|
616 }; |
|
617 |
|
618 template <typename Graph, typename Item, typename RefMap, typename Ref> |
|
619 class RefCopy : public MapCopyBase<Graph, Item, RefMap> { |
|
620 public: |
|
621 |
|
622 RefCopy(Ref& map) : _map(map) {} |
|
623 |
|
624 virtual void copy(const Graph& graph, const RefMap& refMap) { |
|
625 typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt; |
|
626 for (ItemIt it(graph); it != INVALID; ++it) { |
|
627 _map.set(it, refMap[it]); |
|
628 } |
|
629 } |
|
630 |
|
631 private: |
|
632 Ref& _map; |
|
633 }; |
|
634 |
|
635 template <typename Graph, typename Item, typename RefMap, |
|
636 typename CrossRef> |
|
637 class CrossRefCopy : public MapCopyBase<Graph, Item, RefMap> { |
|
638 public: |
|
639 |
|
640 CrossRefCopy(CrossRef& cmap) : _cmap(cmap) {} |
|
641 |
|
642 virtual void copy(const Graph& graph, const RefMap& refMap) { |
|
643 typedef typename ItemSetTraits<Graph, Item>::ItemIt ItemIt; |
|
644 for (ItemIt it(graph); it != INVALID; ++it) { |
|
645 _cmap.set(refMap[it], it); |
|
646 } |
|
647 } |
|
648 |
|
649 private: |
|
650 CrossRef& _cmap; |
|
651 }; |
|
652 |
|
653 } |
|
654 |
591 /// \brief Class to copy a graph. |
655 /// \brief Class to copy a graph. |
592 /// |
656 /// |
593 /// Class to copy a graph to another graph (duplicate a graph). The |
657 /// Class to copy a graph to another graph (duplicate a graph). The |
594 /// simplest way of using it is through the \c copyGraph() function. |
658 /// simplest way of using it is through the \c copyGraph() function. |
595 template <typename Target, typename Source> |
659 template <typename Target, typename Source> |
596 class GraphCopy { |
660 class GraphCopy { |
597 public: |
661 private: |
|
662 |
598 typedef typename Source::Node Node; |
663 typedef typename Source::Node Node; |
599 typedef typename Source::NodeIt NodeIt; |
664 typedef typename Source::NodeIt NodeIt; |
600 typedef typename Source::Edge Edge; |
665 typedef typename Source::Edge Edge; |
601 typedef typename Source::EdgeIt EdgeIt; |
666 typedef typename Source::EdgeIt EdgeIt; |
602 |
667 |
603 typedef typename Source::template NodeMap<typename Target::Node>NodeRefMap; |
668 typedef typename Target::Node TNode; |
604 typedef typename Source::template EdgeMap<typename Target::Edge>EdgeRefMap; |
669 typedef typename Target::Edge TEdge; |
|
670 |
|
671 typedef typename Source::template NodeMap<TNode> NodeRefMap; |
|
672 typedef typename Source::template EdgeMap<TEdge> EdgeRefMap; |
|
673 |
|
674 |
|
675 public: |
|
676 |
605 |
677 |
606 /// \brief Constructor for the GraphCopy. |
678 /// \brief Constructor for the GraphCopy. |
607 /// |
679 /// |
608 /// It copies the content of the \c _source graph into the |
680 /// It copies the content of the \c _source graph into the |
609 /// \c _target graph. It creates also two references, one beetween |
681 /// \c _target graph. |
610 /// the two nodeset and one beetween the two edgesets. |
|
611 GraphCopy(Target& _target, const Source& _source) |
682 GraphCopy(Target& _target, const Source& _source) |
612 : source(_source), target(_target), |
683 : source(_source), target(_target) {} |
613 nodeRefMap(_source), edgeRefMap(_source) { |
684 |
614 for (NodeIt it(source); it != INVALID; ++it) { |
685 /// \brief Destructor of the GraphCopy |
615 nodeRefMap[it] = target.addNode(); |
686 /// |
616 } |
687 /// Destructor of the GraphCopy |
617 for (EdgeIt it(source); it != INVALID; ++it) { |
688 ~GraphCopy() { |
618 edgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], |
689 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { |
619 nodeRefMap[source.target(it)]); |
690 delete nodeMapCopies[i]; |
620 } |
691 } |
|
692 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { |
|
693 delete edgeMapCopies[i]; |
|
694 } |
|
695 |
621 } |
696 } |
622 |
697 |
623 /// \brief Copies the node references into the given map. |
698 /// \brief Copies the node references into the given map. |
624 /// |
699 /// |
625 /// Copies the node references into the given map. |
700 /// Copies the node references into the given map. |
626 template <typename NodeRef> |
701 template <typename NodeRef> |
627 const GraphCopy& nodeRef(NodeRef& map) const { |
702 GraphCopy& nodeRef(NodeRef& map) { |
628 for (NodeIt it(source); it != INVALID; ++it) { |
703 nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, |
629 map.set(it, nodeRefMap[it]); |
704 NodeRefMap, NodeRef>(map)); |
630 } |
|
631 return *this; |
705 return *this; |
632 } |
706 } |
633 |
707 |
634 /// \brief Reverse and copies the node references into the given map. |
708 /// \brief Reverse and copies the node references into the given map. |
635 /// |
709 /// |
636 /// Reverse and copies the node references into the given map. |
710 /// Reverse and copies the node references into the given map. |
637 template <typename NodeRef> |
711 template <typename NodeCrossRef> |
638 const GraphCopy& nodeCrossRef(NodeRef& map) const { |
712 GraphCopy& nodeCrossRef(NodeCrossRef& map) { |
639 for (NodeIt it(source); it != INVALID; ++it) { |
713 nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node, |
640 map.set(nodeRefMap[it], it); |
714 NodeRefMap, NodeCrossRef>(map)); |
641 } |
|
642 return *this; |
|
643 } |
|
644 |
|
645 /// \brief Copies the edge references into the given map. |
|
646 /// |
|
647 /// Copies the edge references into the given map. |
|
648 template <typename EdgeRef> |
|
649 const GraphCopy& edgeRef(EdgeRef& map) const { |
|
650 for (EdgeIt it(source); it != INVALID; ++it) { |
|
651 map.set(it, edgeRefMap[it]); |
|
652 } |
|
653 return *this; |
|
654 } |
|
655 |
|
656 /// \brief Reverse and copies the edge references into the given map. |
|
657 /// |
|
658 /// Reverse and copies the edge references into the given map. |
|
659 template <typename EdgeRef> |
|
660 const GraphCopy& edgeCrossRef(EdgeRef& map) const { |
|
661 for (EdgeIt it(source); it != INVALID; ++it) { |
|
662 map.set(edgeRefMap[it], it); |
|
663 } |
|
664 return *this; |
715 return *this; |
665 } |
716 } |
666 |
717 |
667 /// \brief Make copy of the given map. |
718 /// \brief Make copy of the given map. |
668 /// |
719 /// |
669 /// Makes copy of the given map for the newly created graph. |
720 /// Makes copy of the given map for the newly created graph. |
670 /// The new map's key type is the target graph's node type, |
721 /// The new map's key type is the target graph's node type, |
671 /// and the copied map's key type is the source graph's node |
722 /// and the copied map's key type is the source graph's node |
672 /// type. |
723 /// type. |
673 template <typename TargetMap, typename SourceMap> |
724 template <typename TargetMap, typename SourceMap> |
674 const GraphCopy& nodeMap(TargetMap& tMap, const SourceMap& sMap) const { |
725 GraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) { |
675 copyMap(tMap, sMap, NodeIt(source), nodeRefMap); |
726 nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, |
|
727 NodeRefMap, TargetMap, SourceMap>(tmap, map)); |
|
728 return *this; |
|
729 } |
|
730 |
|
731 /// \brief Copies the edge references into the given map. |
|
732 /// |
|
733 /// Copies the edge references into the given map. |
|
734 template <typename EdgeRef> |
|
735 GraphCopy& edgeRef(EdgeRef& map) { |
|
736 edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, |
|
737 EdgeRefMap, EdgeRef>(map)); |
|
738 return *this; |
|
739 } |
|
740 |
|
741 /// \brief Reverse and copies the edge references into the given map. |
|
742 /// |
|
743 /// Reverse and copies the edge references into the given map. |
|
744 template <typename EdgeCrossRef> |
|
745 GraphCopy& edgeCrossRef(EdgeCrossRef& map) { |
|
746 edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge, |
|
747 EdgeRefMap, EdgeCrossRef>(map)); |
676 return *this; |
748 return *this; |
677 } |
749 } |
678 |
750 |
679 /// \brief Make copy of the given map. |
751 /// \brief Make copy of the given map. |
680 /// |
752 /// |
681 /// Makes copy of the given map for the newly created graph. |
753 /// Makes copy of the given map for the newly created graph. |
682 /// The new map's key type is the target graph's edge type, |
754 /// The new map's key type is the target graph's edge type, |
683 /// and the copied map's key type is the source graph's edge |
755 /// and the copied map's key type is the source graph's edge |
684 /// type. |
756 /// type. |
685 template <typename TargetMap, typename SourceMap> |
757 template <typename TargetMap, typename SourceMap> |
686 const GraphCopy& edgeMap(TargetMap& tMap, const SourceMap& sMap) const { |
758 GraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) { |
687 copyMap(tMap, sMap, EdgeIt(source), edgeRefMap); |
759 edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, |
|
760 EdgeRefMap, TargetMap, SourceMap>(tmap, map)); |
688 return *this; |
761 return *this; |
689 } |
762 } |
690 |
763 |
691 /// \brief Gives back the stored node references. |
764 /// \brief Executes the copies. |
692 /// |
765 /// |
693 /// Gives back the stored node references. |
766 /// Executes the copies. |
694 const NodeRefMap& nodeRef() const { |
767 void run() { |
695 return nodeRefMap; |
768 NodeRefMap nodeRefMap(source); |
696 } |
769 for (NodeIt it(source); it != INVALID; ++it) { |
697 |
770 nodeRefMap[it] = target.addNode(); |
698 /// \brief Gives back the stored edge references. |
771 } |
699 /// |
772 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { |
700 /// Gives back the stored edge references. |
773 nodeMapCopies[i]->copy(source, nodeRefMap); |
701 const EdgeRefMap& edgeRef() const { |
774 } |
702 return edgeRefMap; |
775 EdgeRefMap edgeRefMap(source); |
703 } |
776 for (EdgeIt it(source); it != INVALID; ++it) { |
704 |
777 edgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], |
705 void run() const {} |
778 nodeRefMap[source.target(it)]); |
|
779 } |
|
780 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { |
|
781 edgeMapCopies[i]->copy(source, edgeRefMap); |
|
782 } |
|
783 } |
706 |
784 |
707 private: |
785 private: |
708 |
786 |
709 const Source& source; |
787 const Source& source; |
710 Target& target; |
788 Target& target; |
711 |
789 |
712 NodeRefMap nodeRefMap; |
790 std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > |
713 EdgeRefMap edgeRefMap; |
791 nodeMapCopies; |
|
792 |
|
793 std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > |
|
794 edgeMapCopies; |
|
795 |
714 }; |
796 }; |
715 |
797 |
716 /// \brief Copy a graph to another graph. |
798 /// \brief Copy a graph to another graph. |
717 /// |
799 /// |
718 /// Copy a graph to another graph. |
800 /// Copy a graph to another graph. |
719 /// The usage of the function: |
801 /// The usage of the function: |
720 /// |
802 /// |
721 ///\code |
803 ///\code |
722 /// copyGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr); |
804 /// copyGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run(); |
723 ///\endcode |
805 ///\endcode |
724 /// |
806 /// |
725 /// After the copy the \c nr map will contain the mapping from the |
807 /// After the copy the \c nr map will contain the mapping from the |
726 /// source graph's nodes to the target graph's nodes and the \c ecr will |
808 /// source graph's nodes to the target graph's nodes and the \c ecr will |
727 /// contain the mapping from the target graph's edges to the source's |
809 /// contain the mapping from the target graph's edges to the source's |
735 /// |
817 /// |
736 /// Class to copy an undirected graph to another graph (duplicate a graph). |
818 /// Class to copy an undirected graph to another graph (duplicate a graph). |
737 /// The simplest way of using it is through the \c copyUGraph() function. |
819 /// The simplest way of using it is through the \c copyUGraph() function. |
738 template <typename Target, typename Source> |
820 template <typename Target, typename Source> |
739 class UGraphCopy { |
821 class UGraphCopy { |
740 public: |
822 private: |
|
823 |
741 typedef typename Source::Node Node; |
824 typedef typename Source::Node Node; |
742 typedef typename Source::NodeIt NodeIt; |
825 typedef typename Source::NodeIt NodeIt; |
743 typedef typename Source::Edge Edge; |
826 typedef typename Source::Edge Edge; |
744 typedef typename Source::EdgeIt EdgeIt; |
827 typedef typename Source::EdgeIt EdgeIt; |
745 typedef typename Source::UEdge UEdge; |
828 typedef typename Source::UEdge UEdge; |
746 typedef typename Source::UEdgeIt UEdgeIt; |
829 typedef typename Source::UEdgeIt UEdgeIt; |
747 |
830 |
748 typedef typename Source:: |
831 typedef typename Target::Node TNode; |
749 template NodeMap<typename Target::Node> NodeRefMap; |
832 typedef typename Target::Edge TEdge; |
750 |
833 typedef typename Target::UEdge TUEdge; |
751 typedef typename Source:: |
834 |
752 template UEdgeMap<typename Target::UEdge> UEdgeRefMap; |
835 typedef typename Source::template NodeMap<TNode> NodeRefMap; |
753 |
836 typedef typename Source::template UEdgeMap<TUEdge> UEdgeRefMap; |
754 private: |
|
755 |
837 |
756 struct EdgeRefMap { |
838 struct EdgeRefMap { |
757 EdgeRefMap(UGraphCopy& _gc) : gc(_gc) {} |
839 EdgeRefMap(const Target& _target, const Source& _source, |
|
840 const UEdgeRefMap& _uedge_ref, const NodeRefMap& _node_ref) |
|
841 : target(_target), source(_source), |
|
842 uedge_ref(_uedge_ref), node_ref(_node_ref) {} |
|
843 |
758 typedef typename Source::Edge Key; |
844 typedef typename Source::Edge Key; |
759 typedef typename Target::Edge Value; |
845 typedef typename Target::Edge Value; |
760 |
846 |
761 Value operator[](const Key& key) { |
847 Value operator[](const Key& key) const { |
762 return gc.target.direct(gc.uEdgeRef[key], |
848 bool forward = (source.direction(key) == |
763 gc.target.direction(key)); |
849 (node_ref[source.source((UEdge)key)] == |
|
850 target.source(uedge_ref[(UEdge)key]))); |
|
851 return target.direct(uedge_ref[key], forward); |
764 } |
852 } |
765 |
853 |
766 UGraphCopy& gc; |
854 const Target& target; |
|
855 const Source& source; |
|
856 const UEdgeRefMap& uedge_ref; |
|
857 const NodeRefMap& node_ref; |
767 }; |
858 }; |
768 |
859 |
769 public: |
860 |
770 |
861 public: |
771 /// \brief Constructor for the UGraphCopy. |
862 |
|
863 |
|
864 /// \brief Constructor for the GraphCopy. |
772 /// |
865 /// |
773 /// It copies the content of the \c _source graph into the |
866 /// It copies the content of the \c _source graph into the |
774 /// \c _target graph. It creates also two references, one beetween |
867 /// \c _target graph. |
775 /// the two nodeset and one beetween the two edgesets. |
|
776 UGraphCopy(Target& _target, const Source& _source) |
868 UGraphCopy(Target& _target, const Source& _source) |
777 : source(_source), target(_target), |
869 : source(_source), target(_target) {} |
778 nodeRefMap(_source), edgeRefMap(*this), uEdgeRefMap(_source) { |
870 |
779 for (NodeIt it(source); it != INVALID; ++it) { |
871 /// \brief Destructor of the GraphCopy |
780 nodeRefMap[it] = target.addNode(); |
872 /// |
781 } |
873 /// Destructor of the GraphCopy |
782 for (UEdgeIt it(source); it != INVALID; ++it) { |
874 ~UGraphCopy() { |
783 uEdgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], |
875 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { |
784 nodeRefMap[source.target(it)]); |
876 delete nodeMapCopies[i]; |
785 } |
877 } |
|
878 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { |
|
879 delete edgeMapCopies[i]; |
|
880 } |
|
881 for (int i = 0; i < (int)uEdgeMapCopies.size(); ++i) { |
|
882 delete uEdgeMapCopies[i]; |
|
883 } |
|
884 |
786 } |
885 } |
787 |
886 |
788 /// \brief Copies the node references into the given map. |
887 /// \brief Copies the node references into the given map. |
789 /// |
888 /// |
790 /// Copies the node references into the given map. |
889 /// Copies the node references into the given map. |
791 template <typename NodeRef> |
890 template <typename NodeRef> |
792 const UGraphCopy& nodeRef(NodeRef& map) const { |
891 UGraphCopy& nodeRef(NodeRef& map) { |
793 for (NodeIt it(source); it != INVALID; ++it) { |
892 nodeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Node, |
794 map.set(it, nodeRefMap[it]); |
893 NodeRefMap, NodeRef>(map)); |
795 } |
|
796 return *this; |
894 return *this; |
797 } |
895 } |
798 |
896 |
799 /// \brief Reverse and copies the node references into the given map. |
897 /// \brief Reverse and copies the node references into the given map. |
800 /// |
898 /// |
801 /// Reverse and copies the node references into the given map. |
899 /// Reverse and copies the node references into the given map. |
802 template <typename NodeRef> |
900 template <typename NodeCrossRef> |
803 const UGraphCopy& nodeCrossRef(NodeRef& map) const { |
901 UGraphCopy& nodeCrossRef(NodeCrossRef& map) { |
804 for (NodeIt it(source); it != INVALID; ++it) { |
902 nodeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Node, |
805 map.set(nodeRefMap[it], it); |
903 NodeRefMap, NodeCrossRef>(map)); |
806 } |
|
807 return *this; |
|
808 } |
|
809 |
|
810 /// \brief Copies the edge references into the given map. |
|
811 /// |
|
812 /// Copies the edge references into the given map. |
|
813 template <typename EdgeRef> |
|
814 const UGraphCopy& edgeRef(EdgeRef& map) const { |
|
815 for (EdgeIt it(source); it != INVALID; ++it) { |
|
816 map.set(edgeRefMap[it], it); |
|
817 } |
|
818 return *this; |
|
819 } |
|
820 |
|
821 /// \brief Reverse and copies the undirected edge references into the |
|
822 /// given map. |
|
823 /// |
|
824 /// Reverse and copies the undirected edge references into the given map. |
|
825 template <typename EdgeRef> |
|
826 const UGraphCopy& edgeCrossRef(EdgeRef& map) const { |
|
827 for (EdgeIt it(source); it != INVALID; ++it) { |
|
828 map.set(it, edgeRefMap[it]); |
|
829 } |
|
830 return *this; |
|
831 } |
|
832 |
|
833 /// \brief Copies the undirected edge references into the given map. |
|
834 /// |
|
835 /// Copies the undirected edge references into the given map. |
|
836 template <typename EdgeRef> |
|
837 const UGraphCopy& uEdgeRef(EdgeRef& map) const { |
|
838 for (UEdgeIt it(source); it != INVALID; ++it) { |
|
839 map.set(it, uEdgeRefMap[it]); |
|
840 } |
|
841 return *this; |
|
842 } |
|
843 |
|
844 /// \brief Reverse and copies the undirected edge references into the |
|
845 /// given map. |
|
846 /// |
|
847 /// Reverse and copies the undirected edge references into the given map. |
|
848 template <typename EdgeRef> |
|
849 const UGraphCopy& uEdgeCrossRef(EdgeRef& map) const { |
|
850 for (UEdgeIt it(source); it != INVALID; ++it) { |
|
851 map.set(uEdgeRefMap[it], it); |
|
852 } |
|
853 return *this; |
904 return *this; |
854 } |
905 } |
855 |
906 |
856 /// \brief Make copy of the given map. |
907 /// \brief Make copy of the given map. |
857 /// |
908 /// |
858 /// Makes copy of the given map for the newly created graph. |
909 /// Makes copy of the given map for the newly created graph. |
859 /// The new map's key type is the target graph's node type, |
910 /// The new map's key type is the target graph's node type, |
860 /// and the copied map's key type is the source graph's node |
911 /// and the copied map's key type is the source graph's node |
861 /// type. |
912 /// type. |
862 template <typename TargetMap, typename SourceMap> |
913 template <typename TargetMap, typename SourceMap> |
863 const UGraphCopy& nodeMap(TargetMap& tMap, |
914 UGraphCopy& nodeMap(TargetMap& tmap, const SourceMap& map) { |
864 const SourceMap& sMap) const { |
915 nodeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Node, |
865 copyMap(tMap, sMap, NodeIt(source), nodeRefMap); |
916 NodeRefMap, TargetMap, SourceMap>(tmap, map)); |
|
917 return *this; |
|
918 } |
|
919 |
|
920 /// \brief Copies the edge references into the given map. |
|
921 /// |
|
922 /// Copies the edge references into the given map. |
|
923 template <typename EdgeRef> |
|
924 UGraphCopy& edgeRef(EdgeRef& map) { |
|
925 edgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, Edge, |
|
926 EdgeRefMap, EdgeRef>(map)); |
|
927 return *this; |
|
928 } |
|
929 |
|
930 /// \brief Reverse and copies the edge references into the given map. |
|
931 /// |
|
932 /// Reverse and copies the edge references into the given map. |
|
933 template <typename EdgeCrossRef> |
|
934 UGraphCopy& edgeCrossRef(EdgeCrossRef& map) { |
|
935 edgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, Edge, |
|
936 EdgeRefMap, EdgeCrossRef>(map)); |
866 return *this; |
937 return *this; |
867 } |
938 } |
868 |
939 |
869 /// \brief Make copy of the given map. |
940 /// \brief Make copy of the given map. |
870 /// |
941 /// |
871 /// Makes copy of the given map for the newly created graph. |
942 /// Makes copy of the given map for the newly created graph. |
872 /// The new map's key type is the target graph's edge type, |
943 /// The new map's key type is the target graph's edge type, |
873 /// and the copied map's key type is the source graph's edge |
944 /// and the copied map's key type is the source graph's edge |
874 /// type. |
945 /// type. |
875 template <typename TargetMap, typename SourceMap> |
946 template <typename TargetMap, typename SourceMap> |
876 const UGraphCopy& edgeMap(TargetMap& tMap, |
947 UGraphCopy& edgeMap(TargetMap& tmap, const SourceMap& map) { |
877 const SourceMap& sMap) const { |
948 edgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, Edge, |
878 copyMap(tMap, sMap, EdgeIt(source), edgeRefMap); |
949 EdgeRefMap, TargetMap, SourceMap>(tmap, map)); |
879 return *this; |
950 return *this; |
880 } |
951 } |
881 |
952 |
|
953 /// \brief Copies the uEdge references into the given map. |
|
954 /// |
|
955 /// Copies the uEdge references into the given map. |
|
956 template <typename UEdgeRef> |
|
957 UGraphCopy& uEdgeRef(UEdgeRef& map) { |
|
958 uEdgeMapCopies.push_back(new _graph_utils_bits::RefCopy<Source, UEdge, |
|
959 UEdgeRefMap, UEdgeRef>(map)); |
|
960 return *this; |
|
961 } |
|
962 |
|
963 /// \brief Reverse and copies the uEdge references into the given map. |
|
964 /// |
|
965 /// Reverse and copies the uEdge references into the given map. |
|
966 template <typename UEdgeCrossRef> |
|
967 UGraphCopy& uEdgeCrossRef(UEdgeCrossRef& map) { |
|
968 uEdgeMapCopies.push_back(new _graph_utils_bits::CrossRefCopy<Source, |
|
969 UEdge, UEdgeRefMap, UEdgeCrossRef>(map)); |
|
970 return *this; |
|
971 } |
|
972 |
882 /// \brief Make copy of the given map. |
973 /// \brief Make copy of the given map. |
883 /// |
974 /// |
884 /// Makes copy of the given map for the newly created graph. |
975 /// Makes copy of the given map for the newly created graph. |
885 /// The new map's key type is the target graph's edge type, |
976 /// The new map's key type is the target graph's uEdge type, |
886 /// and the copied map's key type is the source graph's edge |
977 /// and the copied map's key type is the source graph's uEdge |
887 /// type. |
978 /// type. |
888 template <typename TargetMap, typename SourceMap> |
979 template <typename TargetMap, typename SourceMap> |
889 const UGraphCopy& uEdgeMap(TargetMap& tMap, |
980 UGraphCopy& uEdgeMap(TargetMap& tmap, const SourceMap& map) { |
890 const SourceMap& sMap) const { |
981 uEdgeMapCopies.push_back(new _graph_utils_bits::MapCopy<Source, UEdge, |
891 copyMap(tMap, sMap, UEdgeIt(source), uEdgeRefMap); |
982 UEdgeRefMap, TargetMap, SourceMap>(tmap, map)); |
892 return *this; |
983 return *this; |
893 } |
984 } |
894 |
985 |
895 /// \brief Gives back the stored node references. |
986 /// \brief Executes the copies. |
896 /// |
987 /// |
897 /// Gives back the stored node references. |
988 /// Executes the copies. |
898 const NodeRefMap& nodeRef() const { |
989 void run() { |
899 return nodeRefMap; |
990 NodeRefMap nodeRefMap(source); |
900 } |
991 for (NodeIt it(source); it != INVALID; ++it) { |
901 |
992 nodeRefMap[it] = target.addNode(); |
902 /// \brief Gives back the stored edge references. |
993 } |
903 /// |
994 for (int i = 0; i < (int)nodeMapCopies.size(); ++i) { |
904 /// Gives back the stored edge references. |
995 nodeMapCopies[i]->copy(source, nodeRefMap); |
905 const EdgeRefMap& edgeRef() const { |
996 } |
906 return edgeRefMap; |
997 UEdgeRefMap uEdgeRefMap(source); |
907 } |
998 EdgeRefMap edgeRefMap(target, source, uEdgeRefMap, nodeRefMap); |
908 |
999 for (UEdgeIt it(source); it != INVALID; ++it) { |
909 /// \brief Gives back the stored uedge references. |
1000 uEdgeRefMap[it] = target.addEdge(nodeRefMap[source.source(it)], |
910 /// |
1001 nodeRefMap[source.target(it)]); |
911 /// Gives back the stored uedge references. |
1002 } |
912 const UEdgeRefMap& uEdgeRef() const { |
1003 for (int i = 0; i < (int)uEdgeMapCopies.size(); ++i) { |
913 return uEdgeRefMap; |
1004 uEdgeMapCopies[i]->copy(source, uEdgeRefMap); |
914 } |
1005 } |
915 |
1006 for (int i = 0; i < (int)edgeMapCopies.size(); ++i) { |
916 void run() const {} |
1007 edgeMapCopies[i]->copy(source, edgeRefMap); |
|
1008 } |
|
1009 } |
917 |
1010 |
918 private: |
1011 private: |
919 |
1012 |
920 const Source& source; |
1013 const Source& source; |
921 Target& target; |
1014 Target& target; |
922 |
1015 |
923 NodeRefMap nodeRefMap; |
1016 std::vector<_graph_utils_bits::MapCopyBase<Source, Node, NodeRefMap>* > |
924 EdgeRefMap edgeRefMap; |
1017 nodeMapCopies; |
925 UEdgeRefMap uEdgeRefMap; |
1018 |
|
1019 std::vector<_graph_utils_bits::MapCopyBase<Source, Edge, EdgeRefMap>* > |
|
1020 edgeMapCopies; |
|
1021 |
|
1022 std::vector<_graph_utils_bits::MapCopyBase<Source, UEdge, UEdgeRefMap>* > |
|
1023 uEdgeMapCopies; |
|
1024 |
926 }; |
1025 }; |
927 |
1026 |
928 /// \brief Copy a graph to another graph. |
1027 /// \brief Copy a graph to another graph. |
929 /// |
1028 /// |
930 /// Copy a graph to another graph. |
1029 /// Copy a graph to another graph. |
931 /// The usage of the function: |
1030 /// The usage of the function: |
932 /// |
1031 /// |
933 ///\code |
1032 ///\code |
934 /// copyUGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr); |
1033 /// copyUGraph(trg, src).nodeRef(nr).edgeCrossRef(ecr).run(); |
935 ///\endcode |
1034 ///\endcode |
936 /// |
1035 /// |
937 /// After the copy the \c nr map will contain the mapping from the |
1036 /// After the copy the \c nr map will contain the mapping from the |
938 /// source graph's nodes to the target graph's nodes and the \c ecr will |
1037 /// source graph's nodes to the target graph's nodes and the \c ecr will |
939 /// contain the mapping from the target graph's edges to the source's |
1038 /// contain the mapping from the target graph's edges to the source's |