Added backward and forward map.
authordeba
Sat, 14 May 2005 17:34:31 +0000
changeset 1419c3244a26adb1
parent 1418 afaa773d0ad0
child 1420 e37cca875667
Added backward and forward map.
Converting UndirEdge -> Edge
src/lemon/graph_utils.h
     1.1 --- a/src/lemon/graph_utils.h	Sat May 14 17:32:11 2005 +0000
     1.2 +++ b/src/lemon/graph_utils.h	Sat May 14 17:34:31 2005 +0000
     1.3 @@ -18,6 +18,7 @@
     1.4  #define LEMON_GRAPH_UTILS_H
     1.5  
     1.6  #include <iterator>
     1.7 +#include <vector>
     1.8  #include <map>
     1.9  
    1.10  #include <lemon/invalid.h>
    1.11 @@ -266,8 +267,7 @@
    1.12  
    1.13  
    1.14    template <typename _Graph, typename _Item>
    1.15 -  class ItemSetTraits {
    1.16 -  };
    1.17 +  class ItemSetTraits {};
    1.18    
    1.19    template <typename _Graph>
    1.20    class ItemSetTraits<_Graph, typename _Graph::Node> {
    1.21 @@ -361,7 +361,6 @@
    1.22      typedef typename Map::ConstPointer ConstPointer;
    1.23    };
    1.24  
    1.25 -
    1.26    /// Provides an immutable and unique id for each item in the graph.
    1.27  
    1.28    /// The IdMap class provides an unique and immutable mapping for each item
    1.29 @@ -375,6 +374,8 @@
    1.30      typedef _Item Item;
    1.31      typedef _Item Key;
    1.32  
    1.33 +    typedef True NeedCopy;
    1.34 +
    1.35      /// \brief Constructor.
    1.36      ///
    1.37      /// Constructor for creating id map.
    1.38 @@ -397,6 +398,9 @@
    1.39      /// \see inverse()
    1.40      class InverseMap {
    1.41      public:
    1.42 +
    1.43 +      typedef True NeedCopy;
    1.44 +
    1.45        /// \brief Constructor.
    1.46        ///
    1.47        /// Constructor for creating an id-to-item map.
    1.48 @@ -693,6 +697,9 @@
    1.49    template <typename Graph>
    1.50    class SourceMap {
    1.51    public:
    1.52 +
    1.53 +    typedef True NeedCopy;
    1.54 +
    1.55      typedef typename Graph::Node Value;
    1.56      typedef typename Graph::Edge Key;
    1.57  
    1.58 @@ -731,6 +738,9 @@
    1.59    template <typename Graph>
    1.60    class TargetMap {
    1.61    public:
    1.62 +
    1.63 +    typedef True NeedCopy;
    1.64 +
    1.65      typedef typename Graph::Node Value;
    1.66      typedef typename Graph::Edge Key;
    1.67  
    1.68 @@ -762,6 +772,87 @@
    1.69      return TargetMap<Graph>(graph);
    1.70    }
    1.71  
    1.72 +  /// \brief Returns the "forward" directed edge view of undirected edge.
    1.73 +  ///
    1.74 +  /// Returns the "forward" directed edge view of undirected edge.
    1.75 +  /// \author Balazs Dezso
    1.76 +  template <typename Graph>
    1.77 +  class ForwardMap {
    1.78 +  public:
    1.79 +
    1.80 +    typedef True NeedCopy;
    1.81 +
    1.82 +    typedef typename Graph::Edge Value;
    1.83 +    typedef typename Graph::UndirEdge Key;
    1.84 +
    1.85 +    /// \brief Constructor
    1.86 +    ///
    1.87 +    /// Constructor
    1.88 +    /// \param _graph The graph that the map belongs to.
    1.89 +    ForwardMap(const Graph& _graph) : graph(_graph) {}
    1.90 +
    1.91 +    /// \brief The subscript operator.
    1.92 +    ///
    1.93 +    /// The subscript operator.
    1.94 +    /// \param key An undirected edge 
    1.95 +    /// \return The "forward" directed edge view of undirected edge 
    1.96 +    Value operator[](const Key& key) const {
    1.97 +      return graph.edgeWithSource(key, graph.source(key));
    1.98 +    }
    1.99 +
   1.100 +  private:
   1.101 +    const Graph& graph;
   1.102 +  };
   1.103 +
   1.104 +  /// \brief Returns a \ref ForwardMap class
   1.105 +
   1.106 +  /// This function just returns an \ref ForwardMap class.
   1.107 +  /// \relates ForwardMap
   1.108 +  template <typename Graph>
   1.109 +  inline ForwardMap<Graph> forwardMap(const Graph& graph) {
   1.110 +    return ForwardMap<Graph>(graph);
   1.111 +  }
   1.112 +
   1.113 +  /// \brief Returns the "backward" directed edge view of undirected edge.
   1.114 +  ///
   1.115 +  /// Returns the "backward" directed edge view of undirected edge.
   1.116 +  /// \author Balazs Dezso
   1.117 +  template <typename Graph>
   1.118 +  class BackwardMap {
   1.119 +  public:
   1.120 +    typedef True NeedCopy;
   1.121 +
   1.122 +    typedef typename Graph::Edge Value;
   1.123 +    typedef typename Graph::UndirEdge Key;
   1.124 +
   1.125 +    /// \brief Constructor
   1.126 +    ///
   1.127 +    /// Constructor
   1.128 +    /// \param _graph The graph that the map belongs to.
   1.129 +    BackwardMap(const Graph& _graph) : graph(_graph) {}
   1.130 +
   1.131 +    /// \brief The subscript operator.
   1.132 +    ///
   1.133 +    /// The subscript operator.
   1.134 +    /// \param key An undirected edge 
   1.135 +    /// \return The "backward" directed edge view of undirected edge 
   1.136 +    Value operator[](const Key& key) const {
   1.137 +      return graph.edgeWithSource(key, graph.target(key));
   1.138 +    }
   1.139 +
   1.140 +  private:
   1.141 +    const Graph& graph;
   1.142 +  };
   1.143 +
   1.144 +  /// \brief Returns a \ref BackwardMap class
   1.145 +
   1.146 +  /// This function just returns an \ref BackwardMap class.
   1.147 +  /// \relates BackwardMap
   1.148 +  template <typename Graph>
   1.149 +  inline BackwardMap<Graph> backwardMap(const Graph& graph) {
   1.150 +    return BackwardMap<Graph>(graph);
   1.151 +  }
   1.152 +
   1.153  
   1.154    /// @}
   1.155