src/lemon/maps.h
changeset 1355 57936f15055b
parent 1317 83f80464f111
child 1357 8d9c47f31699
equal deleted inserted replaced
13:6ef62f420d7c 14:14ade9c00fae
   214 
   214 
   215     ///Constructor
   215     ///Constructor
   216     ///\param _m is the undelying map
   216     ///\param _m is the undelying map
   217     ///\param _v is the convert value
   217     ///\param _v is the convert value
   218     ConvertMap(const M &_m) : m(_m) {};
   218     ConvertMap(const M &_m) : m(_m) {};
       
   219 
       
   220     /// \brief The subscript operator.
       
   221     ///
       
   222     /// The subscript operator.
       
   223     /// \param edge The edge 
       
   224     /// \return The target of the edge 
   219     Value operator[](Key k) const {return m[k];}
   225     Value operator[](Key k) const {return m[k];}
   220   };
   226   };
   221   
   227   
   222   ///Returns an \ref ConvertMap class
   228   ///Returns an \ref ConvertMap class
   223 
   229 
   226   ///\todo The order of the template parameters are changed.
   232   ///\todo The order of the template parameters are changed.
   227   template<class T, class M>
   233   template<class T, class M>
   228   inline ConvertMap<M,T> convertMap(const M &m) 
   234   inline ConvertMap<M,T> convertMap(const M &m) 
   229   {
   235   {
   230     return ConvertMap<M,T>(m);
   236     return ConvertMap<M,T>(m);
       
   237   }
       
   238 
       
   239   /// \brief Returns the source of the given edge.
       
   240   ///
       
   241   /// The SourceMap gives back the source Node of the given edge. 
       
   242   /// \author Balazs Dezso
       
   243   template <typename Graph>
       
   244   class SourceMap {
       
   245   public:
       
   246     typedef typename Graph::Node Value;
       
   247     typedef typename Graph::Edge Key;
       
   248 
       
   249     /// \brief Constructor
       
   250     ///
       
   251     /// Constructor
       
   252     /// \param _graph The graph that the map belongs to.
       
   253     SourceMap(const Graph& _graph) : graph(_graph) {}
       
   254 
       
   255     /// \brief The subscript operator.
       
   256     ///
       
   257     /// The subscript operator.
       
   258     /// \param edge The edge 
       
   259     /// \return The source of the edge 
       
   260     Value operator[](const Key& edge) {
       
   261       return graph.source(edge);
       
   262     }
       
   263 
       
   264   private:
       
   265     const Graph& graph;
       
   266   };
       
   267 
       
   268   /// \brief Returns a \ref SourceMap class
       
   269 
       
   270   /// This function just returns an \ref SourceMap class.
       
   271   /// \relates SourceMap
       
   272   template <typename Graph>
       
   273   inline SourceMap<Graph> sourceMap(const Graph&) {
       
   274     return SourceMap<Graph>(graph);
       
   275   } 
       
   276 
       
   277   /// \brief Returns the target of the given edge.
       
   278   ///
       
   279   /// The TargetMap gives back the target Node of the given edge. 
       
   280   /// \author Balazs Dezso
       
   281   template <typename Graph>
       
   282   class TargetMap {
       
   283   public:
       
   284     typedef typename Graph::Node Value;
       
   285     typedef typename Graph::Edge Key;
       
   286 
       
   287     /// \brief Constructor
       
   288     ///
       
   289     /// Constructor
       
   290     /// \param _graph The graph that the map belongs to.
       
   291     TargetMap(const Graph& _graph) : graph(_graph) {}
       
   292 
       
   293     /// \brief The subscript operator.
       
   294     ///
       
   295     /// The subscript operator.
       
   296     /// \param edge The edge 
       
   297     /// \return The target of the edge 
       
   298     Value operator[](const Key& key) {
       
   299       return graph.target(key);
       
   300     }
       
   301 
       
   302   private:
       
   303     const Graph& graph;
       
   304   };
       
   305 
       
   306   /// \brief Returns a \ref TargetMap class
       
   307 
       
   308   /// This function just returns an \ref TargetMap class.
       
   309   /// \relates TargetMap
       
   310   template <typename Graph>
       
   311   inline TargetMap<Graph> targetMap(const Graph&) {
       
   312     return TargetMap<Graph>(graph);
   231   }
   313   }
   232 
   314 
   233   ///Sum of two maps
   315   ///Sum of two maps
   234 
   316 
   235   ///This \ref concept::ReadMap "read only map" returns the sum of the two
   317   ///This \ref concept::ReadMap "read only map" returns the sum of the two