lemon/bits/undir_graph_extender.h
changeset 1627 3fd1ba6e9872
parent 1435 8e85e6bbefdf
child 1704 467d7927a901
equal deleted inserted replaced
0:ae84bff21d30 1:171b2c8a77a2
    40     protected:
    40     protected:
    41       // FIXME: Marci use opposite logic in his graph adaptors. It would
    41       // FIXME: Marci use opposite logic in his graph adaptors. It would
    42       // be reasonable to syncronize...
    42       // be reasonable to syncronize...
    43       bool forward;
    43       bool forward;
    44 
    44 
       
    45       Edge(const UndirEdge &ue, bool _forward) :
       
    46         UndirEdge(ue), forward(_forward) {}
       
    47 
    45     public:
    48     public:
    46       Edge() {}
    49       Edge() {}
    47 
       
    48       /// \brief Directed edge from undirected edge and a direction.
       
    49       ///
       
    50       /// This constructor is not a part of the concept interface of
       
    51       /// undirected graph, so please avoid using it if possible!
       
    52       Edge(const UndirEdge &ue, bool _forward) :
       
    53         UndirEdge(ue), forward(_forward) {}
       
    54 
       
    55       /// \brief Directed edge from undirected edge and a source node.
       
    56       ///
       
    57       /// Constructs a directed edge from undirected edge and a source node.
       
    58       ///
       
    59       /// \note You have to specify the graph for this constructor.
       
    60       Edge(const Graph &g, const UndirEdge &ue, const Node &n) :
       
    61 	UndirEdge(ue) { forward = (g.source(ue) == n); }
       
    62 
    50 
    63       /// Invalid edge constructor
    51       /// Invalid edge constructor
    64       Edge(Invalid i) : UndirEdge(i), forward(true) {}
    52       Edge(Invalid i) : UndirEdge(i), forward(true) {}
    65 
    53 
    66       bool operator==(const Edge &that) const {
    54       bool operator==(const Edge &that) const {
    77 
    65 
    78 
    66 
    79     /// \brief Edge of opposite direction.
    67     /// \brief Edge of opposite direction.
    80     ///
    68     ///
    81     /// Returns the Edge of opposite direction.
    69     /// Returns the Edge of opposite direction.
    82     Edge opposite(const Edge &e) const {
    70     Edge oppositeEdge(const Edge &e) const {
    83       return Edge(e,!e.forward);
    71       return Edge(e,!e.forward);
    84     }
    72     }
    85 
    73 
    86   protected:
    74   protected:
    87 
    75 
   111 
    99 
   112     /// Target of the given Edge.
   100     /// Target of the given Edge.
   113     Node target(const Edge &e) const {
   101     Node target(const Edge &e) const {
   114       return _dirTarget(e);
   102       return _dirTarget(e);
   115     }
   103     }
   116 
       
   117     /// Returns whether the given directed edge is same orientation as the
       
   118     /// corresponding undirected edge.
       
   119     ///
       
   120     /// \todo reference to the corresponding point of the undirected graph
       
   121     /// concept. "What does the direction of an undirected edge mean?"
       
   122     bool forward(const Edge &e) const { return e.forward; }
       
   123 
   104 
   124     Node oppositeNode(const Node &n, const UndirEdge &e) const {
   105     Node oppositeNode(const Node &n, const UndirEdge &e) const {
   125       if( n == Parent::source(e))
   106       if( n == Parent::source(e))
   126 	return Parent::target(e);
   107 	return Parent::target(e);
   127       else if( n == Parent::target(e))
   108       else if( n == Parent::target(e))
   128 	return Parent::source(e);
   109 	return Parent::source(e);
   129       else
   110       else
   130 	return INVALID;
   111 	return INVALID;
   131     }
   112     }
   132 
   113 
   133     /// Directed edge from an undirected edge and a source node.
   114     /// \brief Directed edge from an undirected edge and a source node.
   134     ///
   115     ///
   135     /// Returns a (directed) Edge corresponding to the specified UndirEdge
   116     /// Returns a (directed) Edge corresponding to the specified UndirEdge
   136     /// and source Node.
   117     /// and source Node.
   137     ///
   118     ///
   138     ///\todo Do we need this?
   119     Edge direct(const UndirEdge &ue, const Node &s) const {
   139     ///
   120       return Edge(ue, s == source(ue));
   140     ///\todo Better name...
   121     }
   141     Edge edgeWithSource(const UndirEdge &ue, const Node &s) const {
   122 
   142       return Edge(*this, ue, s);
   123     /// \brief Directed edge from an undirected edge.
   143     }
   124     ///
       
   125     /// Returns a directed edge corresponding to the specified UndirEdge.
       
   126     /// If the given bool is true the given undirected edge and the
       
   127     /// returned edge have the same source node.
       
   128     Edge direct(const UndirEdge &ue, bool d) const {
       
   129       return Edge(ue, d);
       
   130     }
       
   131 
       
   132     /// Returns whether the given directed edge is same orientation as the
       
   133     /// corresponding undirected edge.
       
   134     ///
       
   135     /// \todo reference to the corresponding point of the undirected graph
       
   136     /// concept. "What does the direction of an undirected edge mean?"
       
   137     bool direction(const Edge &e) const { return e.forward; }
       
   138 
   144 
   139 
   145     using Parent::first;
   140     using Parent::first;
   146     void first(Edge &e) const {
   141     void first(Edge &e) const {
   147       Parent::first(e);
   142       Parent::first(e);
   148       e.forward=true;
   143       e.forward=true;