99 typedef NodeNumTagIndicator<Graph> NodeNumTag; |
99 typedef NodeNumTagIndicator<Graph> NodeNumTag; |
100 int nodeNum() const { return graph->nodeNum(); } |
100 int nodeNum() const { return graph->nodeNum(); } |
101 |
101 |
102 typedef EdgeNumTagIndicator<Graph> EdgeNumTag; |
102 typedef EdgeNumTagIndicator<Graph> EdgeNumTag; |
103 int edgeNum() const { return graph->edgeNum(); } |
103 int edgeNum() const { return graph->edgeNum(); } |
|
104 int uEdgeNum() const { return graph->uEdgeNum(); } |
104 |
105 |
105 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
106 typedef FindEdgeTagIndicator<Graph> FindEdgeTag; |
106 Edge findEdge(const Node& source, const Node& target, |
107 Edge findEdge(const Node& source, const Node& target, |
107 const Edge& prev = INVALID) { |
108 const Edge& prev = INVALID) { |
108 return graph->findEdge(source, target, prev); |
109 return graph->findEdge(source, target, prev); |
116 UEdge addEdge(const Node& source, const Node& target) const { |
117 UEdge addEdge(const Node& source, const Node& target) const { |
117 return graph->addEdge(source, target); |
118 return graph->addEdge(source, target); |
118 } |
119 } |
119 |
120 |
120 void erase(const Node& i) const { graph->erase(i); } |
121 void erase(const Node& i) const { graph->erase(i); } |
121 void erase(const Edge& i) const { graph->erase(i); } |
122 void erase(const UEdge& i) const { graph->erase(i); } |
122 |
123 |
123 void clear() const { graph->clear(); } |
124 void clear() const { graph->clear(); } |
124 |
125 |
125 int id(const Node& v) const { return graph->id(v); } |
|
126 int id(const UEdge& e) const { return graph->id(e); } |
|
127 |
|
128 bool direction(const Edge& e) const { return graph->direction(e); } |
126 bool direction(const Edge& e) const { return graph->direction(e); } |
129 Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); } |
127 Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); } |
|
128 |
|
129 int id(const Node& v) const { return graph->id(v); } |
|
130 int id(const Edge& e) const { return graph->id(e); } |
|
131 int id(const UEdge& e) const { return graph->id(e); } |
|
132 |
|
133 Node fromNodeId(int id) const { |
|
134 return graph->fromNodeId(id); |
|
135 } |
|
136 |
|
137 Edge fromEdgeId(int id) const { |
|
138 return graph->fromEdgeId(id); |
|
139 } |
|
140 |
|
141 UEdge fromUEdgeId(int id) const { |
|
142 return graph->fromUEdgeId(id); |
|
143 } |
130 |
144 |
131 int maxNodeId() const { |
145 int maxNodeId() const { |
132 return graph->maxNodeId(); |
146 return graph->maxNodeId(); |
133 } |
147 } |
134 |
148 |
171 return operator=<NodeMap>(cmap); |
185 return operator=<NodeMap>(cmap); |
172 } |
186 } |
173 |
187 |
174 template <typename CMap> |
188 template <typename CMap> |
175 NodeMap& operator=(const CMap& cmap) { |
189 NodeMap& operator=(const CMap& cmap) { |
176 checkConcept<concept::ReadMap<Node, _Value>, CMap>(); |
190 Parent::operator=(cmap); |
177 const typename Parent::Graph* graph = Parent::getGraph(); |
191 return *this; |
178 Node it; |
192 } |
179 for (graph->first(it); it != INVALID; graph->next(it)) { |
193 |
180 Parent::set(it, cmap[it]); |
|
181 } |
|
182 return *this; |
|
183 } |
|
184 }; |
194 }; |
185 |
195 |
186 template <typename _Value> |
196 template <typename _Value> |
187 class EdgeMap : public Graph::template EdgeMap<_Value> { |
197 class EdgeMap : public Graph::template EdgeMap<_Value> { |
188 public: |
198 public: |
252 template <typename _UGraph, typename NodeFilterMap, |
252 template <typename _UGraph, typename NodeFilterMap, |
253 typename UEdgeFilterMap, bool checked = true> |
253 typename UEdgeFilterMap, bool checked = true> |
254 class SubUGraphAdaptorBase : public UGraphAdaptorBase<_UGraph> { |
254 class SubUGraphAdaptorBase : public UGraphAdaptorBase<_UGraph> { |
255 public: |
255 public: |
256 typedef _UGraph Graph; |
256 typedef _UGraph Graph; |
|
257 typedef SubUGraphAdaptorBase Adaptor; |
257 typedef UGraphAdaptorBase<_UGraph> Parent; |
258 typedef UGraphAdaptorBase<_UGraph> Parent; |
258 protected: |
259 protected: |
259 |
260 |
260 NodeFilterMap* node_filter_map; |
261 NodeFilterMap* node_filter_map; |
261 UEdgeFilterMap* uedge_filter_map; |
262 UEdgeFilterMap* uedge_filter_map; |
414 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
415 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
415 uedge = Parent::findUEdge(source, target, uedge); |
416 uedge = Parent::findUEdge(source, target, uedge); |
416 } |
417 } |
417 return uedge; |
418 return uedge; |
418 } |
419 } |
|
420 |
|
421 template <typename _Value> |
|
422 class NodeMap |
|
423 : public SubMapExtender<Adaptor, |
|
424 typename Parent::template NodeMap<_Value> > |
|
425 { |
|
426 public: |
|
427 typedef Adaptor Graph; |
|
428 typedef SubMapExtender<Adaptor, typename Parent:: |
|
429 template NodeMap<_Value> > Parent; |
|
430 |
|
431 NodeMap(const Graph& graph) |
|
432 : Parent(graph) {} |
|
433 NodeMap(const Graph& graph, const _Value& value) |
|
434 : Parent(graph, value) {} |
|
435 |
|
436 NodeMap& operator=(const NodeMap& cmap) { |
|
437 return operator=<NodeMap>(cmap); |
|
438 } |
|
439 |
|
440 template <typename CMap> |
|
441 NodeMap& operator=(const CMap& cmap) { |
|
442 Parent::operator=(cmap); |
|
443 return *this; |
|
444 } |
|
445 }; |
|
446 |
|
447 template <typename _Value> |
|
448 class EdgeMap |
|
449 : public SubMapExtender<Adaptor, |
|
450 typename Parent::template EdgeMap<_Value> > |
|
451 { |
|
452 public: |
|
453 typedef Adaptor Graph; |
|
454 typedef SubMapExtender<Adaptor, typename Parent:: |
|
455 template EdgeMap<_Value> > Parent; |
|
456 |
|
457 EdgeMap(const Graph& graph) |
|
458 : Parent(graph) {} |
|
459 EdgeMap(const Graph& graph, const _Value& value) |
|
460 : Parent(graph, value) {} |
|
461 |
|
462 EdgeMap& operator=(const EdgeMap& cmap) { |
|
463 return operator=<EdgeMap>(cmap); |
|
464 } |
|
465 |
|
466 template <typename CMap> |
|
467 EdgeMap& operator=(const CMap& cmap) { |
|
468 Parent::operator=(cmap); |
|
469 return *this; |
|
470 } |
|
471 }; |
|
472 |
|
473 template <typename _Value> |
|
474 class UEdgeMap |
|
475 : public SubMapExtender<Adaptor, |
|
476 typename Parent::template UEdgeMap<_Value> > |
|
477 { |
|
478 public: |
|
479 typedef Adaptor Graph; |
|
480 typedef SubMapExtender<Adaptor, typename Parent:: |
|
481 template UEdgeMap<_Value> > Parent; |
|
482 |
|
483 UEdgeMap(const Graph& graph) |
|
484 : Parent(graph) {} |
|
485 UEdgeMap(const Graph& graph, const _Value& value) |
|
486 : Parent(graph, value) {} |
|
487 |
|
488 UEdgeMap& operator=(const UEdgeMap& cmap) { |
|
489 return operator=<UEdgeMap>(cmap); |
|
490 } |
|
491 |
|
492 template <typename CMap> |
|
493 UEdgeMap& operator=(const CMap& cmap) { |
|
494 Parent::operator=(cmap); |
|
495 return *this; |
|
496 } |
|
497 }; |
|
498 |
419 }; |
499 }; |
420 |
500 |
421 template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap> |
501 template <typename _UGraph, typename NodeFilterMap, typename UEdgeFilterMap> |
422 class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> |
502 class SubUGraphAdaptorBase<_UGraph, NodeFilterMap, UEdgeFilterMap, false> |
423 : public UGraphAdaptorBase<_UGraph> { |
503 : public UGraphAdaptorBase<_UGraph> { |
424 public: |
504 public: |
425 typedef _UGraph Graph; |
505 typedef _UGraph Graph; |
|
506 typedef SubUGraphAdaptorBase Adaptor; |
426 typedef UGraphAdaptorBase<_UGraph> Parent; |
507 typedef UGraphAdaptorBase<_UGraph> Parent; |
427 protected: |
508 protected: |
428 NodeFilterMap* node_filter_map; |
509 NodeFilterMap* node_filter_map; |
429 UEdgeFilterMap* uedge_filter_map; |
510 UEdgeFilterMap* uedge_filter_map; |
430 SubUGraphAdaptorBase() : Parent(), |
511 SubUGraphAdaptorBase() : Parent(), |
557 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
638 while (uedge != INVALID && !(*uedge_filter_map)[uedge]) { |
558 uedge = Parent::findUEdge(source, target, uedge); |
639 uedge = Parent::findUEdge(source, target, uedge); |
559 } |
640 } |
560 return uedge; |
641 return uedge; |
561 } |
642 } |
|
643 |
|
644 template <typename _Value> |
|
645 class NodeMap |
|
646 : public SubMapExtender<Adaptor, |
|
647 typename Parent::template NodeMap<_Value> > |
|
648 { |
|
649 public: |
|
650 typedef Adaptor Graph; |
|
651 typedef SubMapExtender<Adaptor, typename Parent:: |
|
652 template NodeMap<_Value> > Parent; |
|
653 |
|
654 NodeMap(const Graph& graph) |
|
655 : Parent(graph) {} |
|
656 NodeMap(const Graph& graph, const _Value& value) |
|
657 : Parent(graph, value) {} |
|
658 |
|
659 NodeMap& operator=(const NodeMap& cmap) { |
|
660 return operator=<NodeMap>(cmap); |
|
661 } |
|
662 |
|
663 template <typename CMap> |
|
664 NodeMap& operator=(const CMap& cmap) { |
|
665 Parent::operator=(cmap); |
|
666 return *this; |
|
667 } |
|
668 }; |
|
669 |
|
670 template <typename _Value> |
|
671 class EdgeMap |
|
672 : public SubMapExtender<Adaptor, |
|
673 typename Parent::template EdgeMap<_Value> > |
|
674 { |
|
675 public: |
|
676 typedef Adaptor Graph; |
|
677 typedef SubMapExtender<Adaptor, typename Parent:: |
|
678 template EdgeMap<_Value> > Parent; |
|
679 |
|
680 EdgeMap(const Graph& graph) |
|
681 : Parent(graph) {} |
|
682 EdgeMap(const Graph& graph, const _Value& value) |
|
683 : Parent(graph, value) {} |
|
684 |
|
685 EdgeMap& operator=(const EdgeMap& cmap) { |
|
686 return operator=<EdgeMap>(cmap); |
|
687 } |
|
688 |
|
689 template <typename CMap> |
|
690 EdgeMap& operator=(const CMap& cmap) { |
|
691 Parent::operator=(cmap); |
|
692 return *this; |
|
693 } |
|
694 }; |
|
695 |
|
696 template <typename _Value> |
|
697 class UEdgeMap |
|
698 : public SubMapExtender<Adaptor, |
|
699 typename Parent::template UEdgeMap<_Value> > |
|
700 { |
|
701 public: |
|
702 typedef Adaptor Graph; |
|
703 typedef SubMapExtender<Adaptor, typename Parent:: |
|
704 template UEdgeMap<_Value> > Parent; |
|
705 |
|
706 UEdgeMap(const Graph& graph) |
|
707 : Parent(graph) {} |
|
708 UEdgeMap(const Graph& graph, const _Value& value) |
|
709 : Parent(graph, value) {} |
|
710 |
|
711 UEdgeMap& operator=(const UEdgeMap& cmap) { |
|
712 return operator=<UEdgeMap>(cmap); |
|
713 } |
|
714 |
|
715 template <typename CMap> |
|
716 UEdgeMap& operator=(const CMap& cmap) { |
|
717 Parent::operator=(cmap); |
|
718 return *this; |
|
719 } |
|
720 }; |
562 }; |
721 }; |
563 |
722 |
564 /// \ingroup graph_adaptors |
723 /// \ingroup graph_adaptors |
565 /// |
724 /// |
566 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
725 /// \brief A graph adaptor for hiding nodes and edges from an undirected |
676 NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap> |
835 NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap> |
677 nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) { |
836 nodeSubUGraphAdaptor(const UGraph& graph, const NodeFilterMap& nfm) { |
678 return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm); |
837 return NodeSubUGraphAdaptor<const UGraph, const NodeFilterMap>(graph, nfm); |
679 } |
838 } |
680 |
839 |
681 |
|
682 /// \brief An adaptor for hiding undirected edges from an undirected graph. |
840 /// \brief An adaptor for hiding undirected edges from an undirected graph. |
683 /// |
841 /// |
684 /// \warning Graph adaptors are in even more experimental state |
842 /// \warning Graph adaptors are in even more experimental state |
685 /// than the other parts of the lib. Use them at you own risk. |
843 /// than the other parts of the lib. Use them at you own risk. |
686 /// |
844 /// |
702 EdgeSubUGraphAdaptor() : const_true_map(true) { |
860 EdgeSubUGraphAdaptor() : const_true_map(true) { |
703 Parent::setNodeFilterMap(const_true_map); |
861 Parent::setNodeFilterMap(const_true_map); |
704 } |
862 } |
705 |
863 |
706 public: |
864 public: |
|
865 |
707 EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : |
866 EdgeSubUGraphAdaptor(Graph& _graph, UEdgeFilterMap& _uedge_filter_map) : |
708 Parent(), const_true_map(true) { |
867 Parent(), const_true_map(true) { |
709 Parent::setGraph(_graph); |
868 Parent::setGraph(_graph); |
710 Parent::setNodeFilterMap(const_true_map); |
869 Parent::setNodeFilterMap(const_true_map); |
711 Parent::setUEdgeFilterMap(_uedge_filter_map); |
870 Parent::setUEdgeFilterMap(_uedge_filter_map); |
712 } |
871 } |
|
872 |
713 }; |
873 }; |
714 |
874 |
715 template<typename UGraph, typename EdgeFilterMap> |
875 template<typename UGraph, typename EdgeFilterMap> |
716 EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap> |
876 EdgeSubUGraphAdaptor<const UGraph, EdgeFilterMap> |
717 edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) { |
877 edgeSubUGraphAdaptor(const UGraph& graph, EdgeFilterMap& efm) { |
835 } |
995 } |
836 |
996 |
837 template <typename _Value> |
997 template <typename _Value> |
838 class NodeMap : public _UGraph::template NodeMap<_Value> { |
998 class NodeMap : public _UGraph::template NodeMap<_Value> { |
839 public: |
999 public: |
|
1000 |
840 typedef typename _UGraph::template NodeMap<_Value> Parent; |
1001 typedef typename _UGraph::template NodeMap<_Value> Parent; |
|
1002 |
841 explicit NodeMap(const DirUGraphAdaptorBase& ga) |
1003 explicit NodeMap(const DirUGraphAdaptorBase& ga) |
842 : Parent(*ga.graph) { } |
1004 : Parent(*ga.graph) {} |
|
1005 |
843 NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
1006 NodeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
844 : Parent(*ga.graph, value) { } |
1007 : Parent(*ga.graph, value) {} |
|
1008 |
|
1009 NodeMap& operator=(const NodeMap& cmap) { |
|
1010 return operator=<NodeMap>(cmap); |
|
1011 } |
|
1012 |
|
1013 template <typename CMap> |
|
1014 NodeMap& operator=(const CMap& cmap) { |
|
1015 Parent::operator=(cmap); |
|
1016 return *this; |
|
1017 } |
|
1018 |
845 }; |
1019 }; |
846 |
1020 |
847 template <typename _Value> |
1021 template <typename _Value> |
848 class EdgeMap : public _UGraph::template UEdgeMap<_Value> { |
1022 class EdgeMap : public _UGraph::template UEdgeMap<_Value> { |
849 public: |
1023 public: |
|
1024 |
850 typedef typename _UGraph::template UEdgeMap<_Value> Parent; |
1025 typedef typename _UGraph::template UEdgeMap<_Value> Parent; |
|
1026 |
851 explicit EdgeMap(const DirUGraphAdaptorBase& ga) |
1027 explicit EdgeMap(const DirUGraphAdaptorBase& ga) |
852 : Parent(*ga.graph) { } |
1028 : Parent(*ga.graph) { } |
|
1029 |
853 EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
1030 EdgeMap(const DirUGraphAdaptorBase& ga, const _Value& value) |
854 : Parent(*ga.graph, value) { } |
1031 : Parent(*ga.graph, value) { } |
|
1032 |
|
1033 EdgeMap& operator=(const EdgeMap& cmap) { |
|
1034 return operator=<EdgeMap>(cmap); |
|
1035 } |
|
1036 |
|
1037 template <typename CMap> |
|
1038 EdgeMap& operator=(const CMap& cmap) { |
|
1039 Parent::operator=(cmap); |
|
1040 return *this; |
|
1041 } |
855 }; |
1042 }; |
856 |
1043 |
857 |
1044 |
858 |
1045 |
859 protected: |
1046 protected: |