lemon/graph_adaptor.h
changeset 1933 a876a3d6a4c7
parent 1875 98698b69a902
child 1946 17eb3eaad9f8
equal deleted inserted replaced
16:52e16ceeec89 17:c90656dd783e
   670       Parent::setEdgeFilterMap(_edge_filter_map);
   670       Parent::setEdgeFilterMap(_edge_filter_map);
   671     }
   671     }
   672   };
   672   };
   673 
   673 
   674   template <typename _Graph>
   674   template <typename _Graph>
   675   class UndirGraphAdaptorBase : 
   675   class UGraphAdaptorBase : 
   676     public UndirGraphExtender<GraphAdaptorBase<_Graph> > {
   676     public UGraphExtender<GraphAdaptorBase<_Graph> > {
   677   public:
   677   public:
   678     typedef _Graph Graph;
   678     typedef _Graph Graph;
   679     typedef UndirGraphExtender<GraphAdaptorBase<_Graph> > Parent;
   679     typedef UGraphExtender<GraphAdaptorBase<_Graph> > Parent;
   680   protected:
   680   protected:
   681     UndirGraphAdaptorBase() : Parent() { }
   681     UGraphAdaptorBase() : Parent() { }
   682   public:
   682   public:
   683     typedef typename Parent::UndirEdge UndirEdge;
   683     typedef typename Parent::UEdge UEdge;
   684     typedef typename Parent::Edge Edge;
   684     typedef typename Parent::Edge Edge;
   685     
   685     
   686     template <typename T>
   686     template <typename T>
   687     class EdgeMap {
   687     class EdgeMap {
   688     protected:
   688     protected:
   689       const UndirGraphAdaptorBase<_Graph>* g;
   689       const UGraphAdaptorBase<_Graph>* g;
   690       template <typename TT> friend class EdgeMap;
   690       template <typename TT> friend class EdgeMap;
   691       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   691       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   692     public:
   692     public:
   693       typedef T Value;
   693       typedef T Value;
   694       typedef Edge Key;
   694       typedef Edge Key;
   695       
   695       
   696       EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g) : g(&_g), 
   696       EdgeMap(const UGraphAdaptorBase<_Graph>& _g) : g(&_g), 
   697 	forward_map(*(g->graph)), backward_map(*(g->graph)) { }
   697 	forward_map(*(g->graph)), backward_map(*(g->graph)) { }
   698 
   698 
   699       EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g, T a) : g(&_g), 
   699       EdgeMap(const UGraphAdaptorBase<_Graph>& _g, T a) : g(&_g), 
   700 	forward_map(*(g->graph), a), backward_map(*(g->graph), a) { }
   700 	forward_map(*(g->graph), a), backward_map(*(g->graph), a) { }
   701       
   701       
   702       void set(Edge e, T a) { 
   702       void set(Edge e, T a) { 
   703 	if (g->direction(e)) 
   703 	if (g->direction(e)) 
   704 	  forward_map.set(e, a); 
   704 	  forward_map.set(e, a); 
   713 	  return backward_map[e]; 
   713 	  return backward_map[e]; 
   714       }
   714       }
   715     };
   715     };
   716         
   716         
   717     template <typename T>
   717     template <typename T>
   718     class UndirEdgeMap {
   718     class UEdgeMap {
   719       template <typename TT> friend class UndirEdgeMap;
   719       template <typename TT> friend class UEdgeMap;
   720       typename _Graph::template EdgeMap<T> map; 
   720       typename _Graph::template EdgeMap<T> map; 
   721     public:
   721     public:
   722       typedef T Value;
   722       typedef T Value;
   723       typedef UndirEdge Key;
   723       typedef UEdge Key;
   724       
   724       
   725       UndirEdgeMap(const UndirGraphAdaptorBase<_Graph>& g) : 
   725       UEdgeMap(const UGraphAdaptorBase<_Graph>& g) : 
   726 	map(*(g.graph)) { }
   726 	map(*(g.graph)) { }
   727 
   727 
   728       UndirEdgeMap(const UndirGraphAdaptorBase<_Graph>& g, T a) : 
   728       UEdgeMap(const UGraphAdaptorBase<_Graph>& g, T a) : 
   729 	map(*(g.graph), a) { }
   729 	map(*(g.graph), a) { }
   730       
   730       
   731       void set(UndirEdge e, T a) { 
   731       void set(UEdge e, T a) { 
   732 	map.set(e, a); 
   732 	map.set(e, a); 
   733       }
   733       }
   734 
   734 
   735       T operator[](UndirEdge e) const { 
   735       T operator[](UEdge e) const { 
   736 	return map[e]; 
   736 	return map[e]; 
   737       }
   737       }
   738     };
   738     };
   739       
   739       
   740   };
   740   };
   744   /// Undocumented, untested!!!
   744   /// Undocumented, untested!!!
   745   /// If somebody knows nice demo application, let's polulate it.
   745   /// If somebody knows nice demo application, let's polulate it.
   746   /// 
   746   /// 
   747   /// \author Marton Makai
   747   /// \author Marton Makai
   748   template<typename _Graph>
   748   template<typename _Graph>
   749   class UndirGraphAdaptor : 
   749   class UGraphAdaptor : 
   750     public IterableUndirGraphExtender<
   750     public IterableUGraphExtender<
   751     UndirGraphAdaptorBase<_Graph> > {
   751     UGraphAdaptorBase<_Graph> > {
   752   public:
   752   public:
   753     typedef _Graph Graph;
   753     typedef _Graph Graph;
   754     typedef IterableUndirGraphExtender<
   754     typedef IterableUGraphExtender<
   755       UndirGraphAdaptorBase<_Graph> > Parent;
   755       UGraphAdaptorBase<_Graph> > Parent;
   756   protected:
   756   protected:
   757     UndirGraphAdaptor() { }
   757     UGraphAdaptor() { }
   758   public:
   758   public:
   759     UndirGraphAdaptor(_Graph& _graph) { 
   759     UGraphAdaptor(_Graph& _graph) { 
   760       setGraph(_graph);
   760       setGraph(_graph);
   761     }
   761     }
   762   };
   762   };
   763 
   763 
   764   
   764