[Lemon-commits] [lemon_svn] deba: r1889 - hugo/trunk/src/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:48:29 CET 2006


Author: deba
Date: Sat May 14 19:34:31 2005
New Revision: 1889

Modified:
   hugo/trunk/src/lemon/graph_utils.h

Log:
Added backward and forward map.
Converting UndirEdge -> Edge



Modified: hugo/trunk/src/lemon/graph_utils.h
==============================================================================
--- hugo/trunk/src/lemon/graph_utils.h	(original)
+++ hugo/trunk/src/lemon/graph_utils.h	Sat May 14 19:34:31 2005
@@ -18,6 +18,7 @@
 #define LEMON_GRAPH_UTILS_H
 
 #include <iterator>
+#include <vector>
 #include <map>
 
 #include <lemon/invalid.h>
@@ -266,8 +267,7 @@
 
 
   template <typename _Graph, typename _Item>
-  class ItemSetTraits {
-  };
+  class ItemSetTraits {};
   
   template <typename _Graph>
   class ItemSetTraits<_Graph, typename _Graph::Node> {
@@ -361,7 +361,6 @@
     typedef typename Map::ConstPointer ConstPointer;
   };
 
-
   /// Provides an immutable and unique id for each item in the graph.
 
   /// The IdMap class provides an unique and immutable mapping for each item
@@ -375,6 +374,8 @@
     typedef _Item Item;
     typedef _Item Key;
 
+    typedef True NeedCopy;
+
     /// \brief Constructor.
     ///
     /// Constructor for creating id map.
@@ -397,6 +398,9 @@
     /// \see inverse()
     class InverseMap {
     public:
+
+      typedef True NeedCopy;
+
       /// \brief Constructor.
       ///
       /// Constructor for creating an id-to-item map.
@@ -693,6 +697,9 @@
   template <typename Graph>
   class SourceMap {
   public:
+
+    typedef True NeedCopy;
+
     typedef typename Graph::Node Value;
     typedef typename Graph::Edge Key;
 
@@ -731,6 +738,9 @@
   template <typename Graph>
   class TargetMap {
   public:
+
+    typedef True NeedCopy;
+
     typedef typename Graph::Node Value;
     typedef typename Graph::Edge Key;
 
@@ -762,6 +772,87 @@
     return TargetMap<Graph>(graph);
   }
 
+  /// \brief Returns the "forward" directed edge view of undirected edge.
+  ///
+  /// Returns the "forward" directed edge view of undirected edge.
+  /// \author Balazs Dezso
+  template <typename Graph>
+  class ForwardMap {
+  public:
+
+    typedef True NeedCopy;
+
+    typedef typename Graph::Edge Value;
+    typedef typename Graph::UndirEdge Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _graph The graph that the map belongs to.
+    ForwardMap(const Graph& _graph) : graph(_graph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param key An undirected edge 
+    /// \return The "forward" directed edge view of undirected edge 
+    Value operator[](const Key& key) const {
+      return graph.edgeWithSource(key, graph.source(key));
+    }
+
+  private:
+    const Graph& graph;
+  };
+
+  /// \brief Returns a \ref ForwardMap class
+
+  /// This function just returns an \ref ForwardMap class.
+  /// \relates ForwardMap
+  template <typename Graph>
+  inline ForwardMap<Graph> forwardMap(const Graph& graph) {
+    return ForwardMap<Graph>(graph);
+  }
+
+  /// \brief Returns the "backward" directed edge view of undirected edge.
+  ///
+  /// Returns the "backward" directed edge view of undirected edge.
+  /// \author Balazs Dezso
+  template <typename Graph>
+  class BackwardMap {
+  public:
+    typedef True NeedCopy;
+
+    typedef typename Graph::Edge Value;
+    typedef typename Graph::UndirEdge Key;
+
+    /// \brief Constructor
+    ///
+    /// Constructor
+    /// \param _graph The graph that the map belongs to.
+    BackwardMap(const Graph& _graph) : graph(_graph) {}
+
+    /// \brief The subscript operator.
+    ///
+    /// The subscript operator.
+    /// \param key An undirected edge 
+    /// \return The "backward" directed edge view of undirected edge 
+    Value operator[](const Key& key) const {
+      return graph.edgeWithSource(key, graph.target(key));
+    }
+
+  private:
+    const Graph& graph;
+  };
+
+  /// \brief Returns a \ref BackwardMap class
+
+  /// This function just returns an \ref BackwardMap class.
+  /// \relates BackwardMap
+  template <typename Graph>
+  inline BackwardMap<Graph> backwardMap(const Graph& graph) {
+    return BackwardMap<Graph>(graph);
+  }
+
 
   /// @}
 



More information about the Lemon-commits mailing list