lemon/bits/static_map.h
changeset 1909 2d806130e700
parent 1875 98698b69a902
child 1910 f95eea8c34b0
equal deleted inserted replaced
4:da58f4e0a9a5 5:4d433ac433d4
   303     
   303     
   304   };
   304   };
   305 
   305 
   306   /// \e
   306   /// \e
   307   template <typename _Base> 
   307   template <typename _Base> 
   308   class StaticMappableUndirGraphExtender : 
   308   class StaticMappableUGraphExtender : 
   309     public StaticMappableGraphExtender<_Base> {
   309     public StaticMappableGraphExtender<_Base> {
   310   public:
   310   public:
   311 
   311 
   312     typedef StaticMappableUndirGraphExtender Graph;
   312     typedef StaticMappableUGraphExtender Graph;
   313     typedef StaticMappableGraphExtender<_Base> Parent;
   313     typedef StaticMappableGraphExtender<_Base> Parent;
   314 
   314 
   315     typedef typename Parent::UndirEdge UndirEdge;
   315     typedef typename Parent::UEdge UEdge;
   316 
   316 
   317     template <typename _Value>
   317     template <typename _Value>
   318     class UndirEdgeMap 
   318     class UEdgeMap 
   319       : public IterableMapExtender<StaticMap<Graph, UndirEdge, _Value> > {
   319       : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
   320     public:
   320     public:
   321       typedef StaticMappableUndirGraphExtender Graph;
   321       typedef StaticMappableUGraphExtender Graph;
   322       typedef IterableMapExtender<
   322       typedef IterableMapExtender<
   323 	StaticMap<Graph, UndirEdge, _Value> > Parent;
   323 	StaticMap<Graph, UEdge, _Value> > Parent;
   324 
   324 
   325       UndirEdgeMap(const Graph& _g) 
   325       UEdgeMap(const Graph& _g) 
   326 	: Parent(_g) {}
   326 	: Parent(_g) {}
   327       UndirEdgeMap(const Graph& _g, const _Value& _v) 
   327       UEdgeMap(const Graph& _g, const _Value& _v) 
   328 	: Parent(_g, _v) {}
   328 	: Parent(_g, _v) {}
   329 
   329 
   330       UndirEdgeMap& operator=(const UndirEdgeMap& cmap) {
   330       UEdgeMap& operator=(const UEdgeMap& cmap) {
   331 	return operator=<UndirEdgeMap>(cmap);
   331 	return operator=<UEdgeMap>(cmap);
   332       }
   332       }
   333 
   333 
   334       template <typename CMap>
   334       template <typename CMap>
   335       UndirEdgeMap& operator=(const CMap& cmap) {
   335       UEdgeMap& operator=(const CMap& cmap) {
   336 	checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
   336 	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
   337 	const typename Parent::Graph* graph = Parent::getGraph();
   337 	const typename Parent::Graph* graph = Parent::getGraph();
   338 	UndirEdge it;
   338 	UEdge it;
   339 	for (graph->first(it); it != INVALID; graph->next(it)) {
   339 	for (graph->first(it); it != INVALID; graph->next(it)) {
   340 	  Parent::set(it, cmap[it]);
   340 	  Parent::set(it, cmap[it]);
   341 	}
   341 	}
   342 	return *this;
   342 	return *this;
   343       }
   343       }
   344     };
   344     };
   345 
   345 
   346   };
   346   };
   347 
   347 
   348   template <typename _Base>
   348   template <typename _Base>
   349   class StaticMappableUndirBipartiteGraphExtender : public _Base {
   349   class StaticMappableUBipartiteGraphExtender : public _Base {
   350   public:
   350   public:
   351 
   351 
   352     typedef _Base Parent;
   352     typedef _Base Parent;
   353     typedef StaticMappableUndirBipartiteGraphExtender Graph;
   353     typedef StaticMappableUBipartiteGraphExtender Graph;
   354 
   354 
   355     typedef typename Parent::Node Node;
   355     typedef typename Parent::Node Node;
   356     typedef typename Parent::UpperNode UpperNode;
   356     typedef typename Parent::UpperNode UpperNode;
   357     typedef typename Parent::LowerNode LowerNode;
   357     typedef typename Parent::LowerNode LowerNode;
   358     typedef typename Parent::Edge Edge;
   358     typedef typename Parent::Edge Edge;
   359     typedef typename Parent::UndirEdge UndirEdge;
   359     typedef typename Parent::UEdge UEdge;
   360     
   360     
   361     template <typename _Value>
   361     template <typename _Value>
   362     class UpperNodeMap 
   362     class UpperNodeMap 
   363       : public IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > {
   363       : public IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > {
   364     public:
   364     public:
   365       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   365       typedef StaticMappableUBipartiteGraphExtender Graph;
   366       typedef IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > 
   366       typedef IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > 
   367       Parent;
   367       Parent;
   368     
   368     
   369       UpperNodeMap(const Graph& _g) 
   369       UpperNodeMap(const Graph& _g) 
   370 	: Parent(_g) {}
   370 	: Parent(_g) {}
   397 
   397 
   398     template <typename _Value>
   398     template <typename _Value>
   399     class LowerNodeMap 
   399     class LowerNodeMap 
   400       : public IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > {
   400       : public IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > {
   401     public:
   401     public:
   402       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   402       typedef StaticMappableUBipartiteGraphExtender Graph;
   403       typedef IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > 
   403       typedef IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > 
   404       Parent;
   404       Parent;
   405     
   405     
   406       LowerNodeMap(const Graph& _g) 
   406       LowerNodeMap(const Graph& _g) 
   407 	: Parent(_g) {}
   407 	: Parent(_g) {}
   435   protected:
   435   protected:
   436 
   436 
   437     template <typename _Value>
   437     template <typename _Value>
   438     class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
   438     class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
   439     public:
   439     public:
   440       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   440       typedef StaticMappableUBipartiteGraphExtender Graph;
   441 
   441 
   442       typedef Node Key;
   442       typedef Node Key;
   443       typedef _Value Value;
   443       typedef _Value Value;
   444 
   444 
   445       /// The reference type of the map;
   445       /// The reference type of the map;
   515 
   515 
   516     template <typename _Value>
   516     template <typename _Value>
   517     class NodeMap 
   517     class NodeMap 
   518       : public IterableMapExtender<NodeMapBase<_Value> > {
   518       : public IterableMapExtender<NodeMapBase<_Value> > {
   519     public:
   519     public:
   520       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   520       typedef StaticMappableUBipartiteGraphExtender Graph;
   521       typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
   521       typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
   522     
   522     
   523       NodeMap(const Graph& _g) 
   523       NodeMap(const Graph& _g) 
   524 	: Parent(_g) {}
   524 	: Parent(_g) {}
   525       NodeMap(const Graph& _g, const _Value& _v) 
   525       NodeMap(const Graph& _g, const _Value& _v) 
   553 
   553 
   554     template <typename _Value>
   554     template <typename _Value>
   555     class EdgeMap 
   555     class EdgeMap 
   556       : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
   556       : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
   557     public:
   557     public:
   558       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   558       typedef StaticMappableUBipartiteGraphExtender Graph;
   559       typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
   559       typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
   560     
   560     
   561       EdgeMap(const Graph& _g) 
   561       EdgeMap(const Graph& _g) 
   562 	: Parent(_g) {}
   562 	: Parent(_g) {}
   563       EdgeMap(const Graph& _g, const _Value& _v) 
   563       EdgeMap(const Graph& _g, const _Value& _v) 
   578 	return *this;
   578 	return *this;
   579       }
   579       }
   580     };
   580     };
   581 
   581 
   582     template <typename _Value>
   582     template <typename _Value>
   583     class UndirEdgeMap 
   583     class UEdgeMap 
   584       : public IterableMapExtender<StaticMap<Graph, UndirEdge, _Value> > {
   584       : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
   585     public:
   585     public:
   586       typedef StaticMappableUndirBipartiteGraphExtender Graph;
   586       typedef StaticMappableUBipartiteGraphExtender Graph;
   587       typedef IterableMapExtender<StaticMap<Graph, UndirEdge, _Value> > 
   587       typedef IterableMapExtender<StaticMap<Graph, UEdge, _Value> > 
   588       Parent;
   588       Parent;
   589     
   589     
   590       UndirEdgeMap(const Graph& _g) 
   590       UEdgeMap(const Graph& _g) 
   591 	: Parent(_g) {}
   591 	: Parent(_g) {}
   592       UndirEdgeMap(const Graph& _g, const _Value& _v) 
   592       UEdgeMap(const Graph& _g, const _Value& _v) 
   593 	: Parent(_g, _v) {}
   593 	: Parent(_g, _v) {}
   594     
   594     
   595       UndirEdgeMap& operator=(const UndirEdgeMap& cmap) {
   595       UEdgeMap& operator=(const UEdgeMap& cmap) {
   596 	return operator=<UndirEdgeMap>(cmap);
   596 	return operator=<UEdgeMap>(cmap);
   597       }
   597       }
   598     
   598     
   599       template <typename CMap>
   599       template <typename CMap>
   600       UndirEdgeMap& operator=(const CMap& cmap) {
   600       UEdgeMap& operator=(const CMap& cmap) {
   601 	checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
   601 	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
   602 	const typename Parent::Graph* graph = Parent::getGraph();
   602 	const typename Parent::Graph* graph = Parent::getGraph();
   603 	UndirEdge it;
   603 	UEdge it;
   604 	for (graph->first(it); it != INVALID; graph->next(it)) {
   604 	for (graph->first(it); it != INVALID; graph->next(it)) {
   605 	  Parent::set(it, cmap[it]);
   605 	  Parent::set(it, cmap[it]);
   606 	}
   606 	}
   607 	return *this;
   607 	return *this;
   608       }
   608       }