# HG changeset patch # User deba # Date 1116092071 0 # Node ID c3244a26adb19de518cf801f0ee64c86e20aadd5 # Parent afaa773d0ad0029ea90eb71510319bbf436b3c41 Added backward and forward map. Converting UndirEdge -> Edge diff -r afaa773d0ad0 -r c3244a26adb1 src/lemon/graph_utils.h --- a/src/lemon/graph_utils.h Sat May 14 17:32:11 2005 +0000 +++ b/src/lemon/graph_utils.h Sat May 14 17:34:31 2005 +0000 @@ -18,6 +18,7 @@ #define LEMON_GRAPH_UTILS_H #include +#include #include #include @@ -266,8 +267,7 @@ template - class ItemSetTraits { - }; + class ItemSetTraits {}; template 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 class SourceMap { public: + + typedef True NeedCopy; + typedef typename Graph::Node Value; typedef typename Graph::Edge Key; @@ -731,6 +738,9 @@ template class TargetMap { public: + + typedef True NeedCopy; + typedef typename Graph::Node Value; typedef typename Graph::Edge Key; @@ -762,6 +772,87 @@ return TargetMap(graph); } + /// \brief Returns the "forward" directed edge view of undirected edge. + /// + /// Returns the "forward" directed edge view of undirected edge. + /// \author Balazs Dezso + template + 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 + inline ForwardMap forwardMap(const Graph& graph) { + return ForwardMap(graph); + } + + /// \brief Returns the "backward" directed edge view of undirected edge. + /// + /// Returns the "backward" directed edge view of undirected edge. + /// \author Balazs Dezso + template + 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 + inline BackwardMap backwardMap(const Graph& graph) { + return BackwardMap(graph); + } + /// @}