lemon/bits/default_map.h
changeset 1669 66ae78d29f1e
parent 1587 8f1c317ebeb4
child 1672 85e30ec7c957
     1.1 --- a/lemon/bits/default_map.h	Tue Aug 30 21:19:07 2005 +0000
     1.2 +++ b/lemon/bits/default_map.h	Wed Aug 31 13:29:32 2005 +0000
     1.3 @@ -28,19 +28,8 @@
     1.4  
     1.5  namespace lemon {
     1.6  
     1.7 -/// \addtogroup graphmapfactory
     1.8 -/// @{
     1.9 -
    1.10 -  /** The ArrayMap template class is graph map structure what
    1.11 -   *  automatically updates the map when a key is added to or erased from
    1.12 -   *  the map. This map uses the VectorMap if the Value is a primitive
    1.13 -   *  type and the ArrayMap for the other cases.
    1.14 -   *
    1.15 -   *  The template parameter is the MapRegistry that the maps
    1.16 -   *  will belong to and the Value.
    1.17 -   */
    1.18 -
    1.19 -
    1.20 +  /// \addtogroup graphmapfactory
    1.21 +  /// @{
    1.22  
    1.23    template <typename _Graph, typename _Item, typename _Value>
    1.24    struct DefaultMapSelector {
    1.25 @@ -135,8 +124,7 @@
    1.26      typedef VectorMap<_Graph, _Item, _Ptr*> Map;
    1.27    };
    1.28  
    1.29 -
    1.30 -
    1.31 +  /// \e
    1.32    template <
    1.33      typename _Graph, 
    1.34      typename _Item,
    1.35 @@ -152,15 +140,16 @@
    1.36  
    1.37      DefaultMap(const Graph& _g) : Parent(_g) {}
    1.38      DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
    1.39 +
    1.40    };
    1.41  
    1.42  
    1.43 -
    1.44 +  /// \e
    1.45    template <typename _Base> 
    1.46 -  class DefaultMappableGraphExtender : public _Base {
    1.47 +  class MappableGraphExtender : public _Base {
    1.48    public:
    1.49  
    1.50 -    typedef DefaultMappableGraphExtender<_Base> Graph;
    1.51 +    typedef MappableGraphExtender<_Base> Graph;
    1.52      typedef _Base Parent;
    1.53  
    1.54      typedef typename Parent::Node Node;
    1.55 @@ -174,37 +163,67 @@
    1.56      class NodeMap 
    1.57        : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
    1.58      public:
    1.59 -      typedef DefaultMappableGraphExtender Graph;
    1.60 +      typedef MappableGraphExtender Graph;
    1.61        typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
    1.62  
    1.63        NodeMap(const Graph& _g) 
    1.64  	: Parent(_g) {}
    1.65        NodeMap(const Graph& _g, const _Value& _v) 
    1.66  	: Parent(_g, _v) {}
    1.67 +
    1.68 +      /// \brief Template assign operator.
    1.69 +      ///
    1.70 +      /// The given parameter should be conform to the ReadMap
    1.71 +      /// concecpt and could be indiced by the current item set of
    1.72 +      /// the NodeMap. In this case the value for each item
    1.73 +      /// is assigned by the value of the given ReadMap. 
    1.74 +      template <typename CMap>
    1.75 +      NodeMap& operator=(const CMap& cmap) {
    1.76 +	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
    1.77 +	const typename Parent::Graph* graph = Parent::getGraph();
    1.78 +	Node it;
    1.79 +	for (graph->first(it); it != INVALID; graph->next(it)) {
    1.80 +	  Parent::set(it, cmap[it]);
    1.81 +	}
    1.82 +	return *this;
    1.83 +      }
    1.84 +
    1.85      };
    1.86  
    1.87      template <typename _Value>
    1.88      class EdgeMap 
    1.89        : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
    1.90      public:
    1.91 -      typedef DefaultMappableGraphExtender Graph;
    1.92 +      typedef MappableGraphExtender Graph;
    1.93        typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    1.94  
    1.95        EdgeMap(const Graph& _g) 
    1.96  	: Parent(_g) {}
    1.97        EdgeMap(const Graph& _g, const _Value& _v) 
    1.98  	: Parent(_g, _v) {}
    1.99 +
   1.100 +      template <typename CMap>
   1.101 +      EdgeMap& operator=(const CMap& cmap) {
   1.102 +	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
   1.103 +	const typename Parent::Graph* graph = Parent::getGraph();
   1.104 +	Edge it;
   1.105 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.106 +	  Parent::set(it, cmap[it]);
   1.107 +	}
   1.108 +	return *this;
   1.109 +      }
   1.110      };
   1.111      
   1.112    };
   1.113  
   1.114 +  /// \e
   1.115    template <typename _Base> 
   1.116    class MappableUndirGraphExtender : 
   1.117 -    public DefaultMappableGraphExtender<_Base> {
   1.118 +    public MappableGraphExtender<_Base> {
   1.119    public:
   1.120  
   1.121      typedef MappableUndirGraphExtender Graph;
   1.122 -    typedef DefaultMappableGraphExtender<_Base> Parent;
   1.123 +    typedef MappableGraphExtender<_Base> Parent;
   1.124  
   1.125      typedef typename Parent::UndirEdge UndirEdge;
   1.126  
   1.127 @@ -220,11 +239,23 @@
   1.128  	: Parent(_g) {}
   1.129        UndirEdgeMap(const Graph& _g, const _Value& _v) 
   1.130  	: Parent(_g, _v) {}
   1.131 +
   1.132 +      template <typename CMap>
   1.133 +      UndirEdgeMap& operator=(const CMap& cmap) {
   1.134 +	checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
   1.135 +	const typename Parent::Graph* graph = Parent::getGraph();
   1.136 +	UndirEdge it;
   1.137 +	for (graph->first(it); it != INVALID; graph->next(it)) {
   1.138 +	  Parent::set(it, cmap[it]);
   1.139 +	}
   1.140 +	return *this;
   1.141 +      }
   1.142      };
   1.143  
   1.144  
   1.145    };
   1.146  
   1.147 +  /// @}
   1.148  }
   1.149  
   1.150  #endif