src/lemon/maps.h
changeset 1402 655d8e78454d
parent 1359 1581f961cfaa
child 1420 e37cca875667
equal deleted inserted replaced
16:9ddb97b85c76 17:c92a112fc50c
    15  */
    15  */
    16 
    16 
    17 #ifndef LEMON_MAPS_H
    17 #ifndef LEMON_MAPS_H
    18 #define LEMON_MAPS_H
    18 #define LEMON_MAPS_H
    19 
    19 
    20 #include<math.h>
       
    21 
    20 
    22 ///\file
    21 ///\file
    23 ///\ingroup maps
    22 ///\ingroup maps
    24 ///\brief Miscellaneous property maps
    23 ///\brief Miscellaneous property maps
    25 ///
    24 ///
   184     struct rebind {
   183     struct rebind {
   185       typedef StdMap<Key,T1,Compare> other;
   184       typedef StdMap<Key,T1,Compare> other;
   186     };
   185     };
   187   };
   186   };
   188 
   187 
       
   188   /// @}
       
   189 
       
   190   /// \addtogroup map_adaptors
       
   191   /// @{
       
   192 
       
   193 
   189   ///Convert the \c Value of a maps to another type.
   194   ///Convert the \c Value of a maps to another type.
   190 
   195 
   191   ///This \ref concept::ReadMap "read only map"
   196   ///This \ref concept::ReadMap "read only map"
   192   ///converts the \c Value of a maps to type \c T.
   197   ///converts the \c Value of a maps to type \c T.
   193   ///Its \c Value is inherited from \c M.
   198   ///Its \c Value is inherited from \c M.
   232   ///\todo The order of the template parameters are changed.
   237   ///\todo The order of the template parameters are changed.
   233   template<class T, class M>
   238   template<class T, class M>
   234   inline ConvertMap<M,T> convertMap(const M &m) 
   239   inline ConvertMap<M,T> convertMap(const M &m) 
   235   {
   240   {
   236     return ConvertMap<M,T>(m);
   241     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& 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& graph) {
       
   312     return TargetMap<Graph>(graph);
       
   313   }
   242   }
   314 
   243 
   315   ///Sum of two maps
   244   ///Sum of two maps
   316 
   245 
   317   ///This \ref concept::ReadMap "read only map" returns the sum of the two
   246   ///This \ref concept::ReadMap "read only map" returns the sum of the two
   730   inline AbsMap<M> absMap(const M &m) 
   659   inline AbsMap<M> absMap(const M &m) 
   731   {
   660   {
   732     return AbsMap<M>(m);
   661     return AbsMap<M>(m);
   733   }
   662   }
   734 
   663 
   735   ///Converts an STL style functor to a a map
   664   ///Converts an STL style functor to a map
   736 
   665 
   737   ///This \ref concept::ReadMap "read only map" returns the value
   666   ///This \ref concept::ReadMap "read only map" returns the value
   738   ///of a
   667   ///of a
   739   ///given map.
   668   ///given map.
   740   ///
   669   ///