UndirGraph implementation nearly complete
authorklao
Sun, 28 Nov 2004 16:30:10 +0000
changeset 1022567f392d1d2e
parent 1021 fd1d073b6557
child 1023 3268fef5d623
UndirGraph implementation nearly complete
src/lemon/alteration_observer_registry.h
src/lemon/clearable_graph_extender.h
src/lemon/concept/graph_component.h
src/lemon/concept/undir_graph.h
src/lemon/concept_check.h
src/lemon/default_map.h
src/lemon/erasable_graph_extender.h
src/lemon/extendable_graph_extender.h
src/lemon/iterable_graph_extender.h
src/test/graph_test.cc
src/test/undir_graph_test.cc
     1.1 --- a/src/lemon/alteration_observer_registry.h	Thu Nov 25 14:48:24 2004 +0000
     1.2 +++ b/src/lemon/alteration_observer_registry.h	Sun Nov 28 16:30:10 2004 +0000
     1.3 @@ -364,7 +364,10 @@
     1.4  
     1.5      mutable UndirEdgeObserverRegistry undir_edge_observers;
     1.6  
     1.7 -    UndirEdgeObserverRegistry& getObserverRegistry(UndirEdge = INVALID) const {
     1.8 +  public:
     1.9 +
    1.10 +    using Parent::getObserverRegistry;
    1.11 +    UndirEdgeObserverRegistry& getObserverRegistry(UndirEdge) const {
    1.12        return undir_edge_observers;
    1.13      }
    1.14  
     2.1 --- a/src/lemon/clearable_graph_extender.h	Thu Nov 25 14:48:24 2004 +0000
     2.2 +++ b/src/lemon/clearable_graph_extender.h	Sun Nov 28 16:30:10 2004 +0000
     2.3 @@ -25,6 +25,25 @@
     2.4  
     2.5    };
     2.6  
     2.7 +  template <typename _Base> 
     2.8 +  class ClearableUndirGraphExtender : public _Base {
     2.9 +  public:
    2.10 +
    2.11 +    typedef ClearableUndirGraphExtender Graph;
    2.12 +    typedef _Base Parent;
    2.13 +    typedef typename Parent::Node Node;
    2.14 +    typedef typename Parent::UndirEdge UndirEdge;
    2.15 +    typedef typename Parent::Edge Edge;
    2.16 +
    2.17 +    void clear() {
    2.18 +      Parent::getObserverRegistry(Node()).clear();
    2.19 +      Parent::getObserverRegistry(UndirEdge()).clear();
    2.20 +      Parent::getObserverRegistry(Edge()).clear();
    2.21 +      Parent::clear();
    2.22 +    }
    2.23 +
    2.24 +  };
    2.25 +
    2.26  }
    2.27  
    2.28  #endif
     3.1 --- a/src/lemon/concept/graph_component.h	Thu Nov 25 14:48:24 2004 +0000
     3.2 +++ b/src/lemon/concept/graph_component.h	Sun Nov 28 16:30:10 2004 +0000
     3.3 @@ -406,7 +406,7 @@
     3.4      /// This class provides beside the core graph features
     3.5      /// core clear functions for the graph structure.
     3.6      /// The most of the base graphs should be conform to this concept.
     3.7 -    class BaseClearableGraphComponent : virtual public BaseGraphComponent {
     3.8 +    class ClearableGraphComponent : virtual public BaseGraphComponent {
     3.9      public:
    3.10  
    3.11        /// Erase all the Nodes and Edges from the graph.
    3.12 @@ -418,11 +418,11 @@
    3.13        template <typename _Graph>
    3.14        struct Constraints {
    3.15  	void constraints() {
    3.16 -	  checkConcept< BaseGraphComponent, _Graph>();
    3.17 +	  checkConcept<BaseGraphComponent, _Graph>();
    3.18  	  graph.clear();
    3.19  	}
    3.20  
    3.21 -	_Graph& graph;
    3.22 +	_Graph graph;
    3.23        };
    3.24      };
    3.25  
    3.26 @@ -804,27 +804,6 @@
    3.27        };
    3.28      };
    3.29  
    3.30 -    class ClearableGraphComponent : virtual public BaseGraphComponent {
    3.31 -    public:
    3.32 -
    3.33 -      typedef ClearableGraphComponent Graph;
    3.34 -
    3.35 -      typedef BaseGraphComponent::Node Node;
    3.36 -      typedef BaseGraphComponent::Edge Edge;
    3.37 -
    3.38 -      void clear() {}    
    3.39 -
    3.40 -
    3.41 -      template <typename _Graph>
    3.42 -      struct ClearableGraphComponentConcept {
    3.43 -	void constraints() {
    3.44 -	  checkConcept< BaseGraphComponent, _Graph >();
    3.45 -	  graph.clear();
    3.46 -	}
    3.47 -	_Graph& graph;
    3.48 -      };
    3.49 -    };
    3.50 -
    3.51    }
    3.52  
    3.53  }
     4.1 --- a/src/lemon/concept/undir_graph.h	Thu Nov 25 14:48:24 2004 +0000
     4.2 +++ b/src/lemon/concept/undir_graph.h	Sun Nov 28 16:30:10 2004 +0000
     4.3 @@ -31,50 +31,163 @@
     4.4    namespace concept {
     4.5  
     4.6      /// \todo to be done
     4.7 -    class BaseIterableUndirGraph;
     4.8  
     4.9 -    template <typename Graph>
    4.10      struct BaseIterableUndirGraphConcept {
    4.11 -      typedef typename Graph::UndirEdge UndirEdge;
    4.12 -      typedef typename Graph::Edge Edge;
    4.13 -      typedef typename Graph::Node Node;
    4.14  
    4.15 -      void constraints() {
    4.16 -	checkConcept<BaseIterableGraphComponent, Graph>();
    4.17 -	checkConcept<GraphItem<'u'>, UndirEdge >();
    4.18 +      template <typename Graph>
    4.19 +      struct Constraints {
    4.20  
    4.21 -	/// \bug this should be base_and_derived:
    4.22 -	UndirEdge ue = e;
    4.23 -	ue = e;
    4.24 +	typedef typename Graph::UndirEdge UndirEdge;
    4.25 +	typedef typename Graph::Edge Edge;
    4.26 +	typedef typename Graph::Node Node;
    4.27  
    4.28 -	Node n;
    4.29 -	n = graph.target(ue);
    4.30 -	n = graph.source(ue);
    4.31 +	void constraints() {
    4.32 +	  checkConcept<BaseIterableGraphComponent, Graph>();
    4.33 +	  checkConcept<GraphItem<'u'>, UndirEdge >();
    4.34  
    4.35 -	graph.first(ue);
    4.36 -	graph.next(ue);
    4.37 -      }
    4.38 -      const Graph &graph;
    4.39 -      Edge e;
    4.40 +	  /// \bug this should be base_and_derived:
    4.41 +	  UndirEdge ue = e;
    4.42 +	  ue = e;
    4.43 +
    4.44 +	  Node n;
    4.45 +	  n = graph.target(ue);
    4.46 +	  n = graph.source(ue);
    4.47 +
    4.48 +	  graph.first(ue);
    4.49 +	  graph.next(ue);
    4.50 +	}
    4.51 +	const Graph &graph;
    4.52 +	Edge e;
    4.53 +      };
    4.54 +
    4.55      };
    4.56  
    4.57 -    template <typename Graph>
    4.58 +
    4.59      struct IterableUndirGraphConcept {
    4.60 -      void constraints() {
    4.61 -	/// \todo we don't need the iterable component should base iterable	
    4.62 -	//	checkConcept< BaseIterableUndirGraph, Graph > ();
    4.63 -	checkConcept< IterableGraphComponent, Graph > ();
    4.64  
    4.65 -	typedef typename Graph::UndirEdge UndirEdge;
    4.66 -	typedef typename Graph::UndirEdgeIt UndirEdgeIt;
    4.67 -	typedef typename Graph::UndirIncEdgeIt UndirIncEdgeIt;
    4.68 +      template <typename Graph>
    4.69 +      struct Constraints {
    4.70 +	void constraints() {
    4.71 +	  /// \todo we don't need the iterable component to be base iterable
    4.72 +	  /// Don't we really???
    4.73 +	  //checkConcept< BaseIterableUndirGraphConcept, Graph > ();
    4.74  
    4.75 -	checkConcept< GraphIterator<Graph, UndirEdge>, UndirEdgeIt >();
    4.76 +	  checkConcept<IterableGraphComponent, Graph> ();
    4.77  
    4.78 -	checkConcept<
    4.79 -	  GraphIncIterator<Graph, UndirEdge>,
    4.80 -	  UndirIncEdgeIt >();
    4.81 -      }
    4.82 +	  typedef typename Graph::UndirEdge UndirEdge;
    4.83 +	  typedef typename Graph::UndirEdgeIt UndirEdgeIt;
    4.84 +	  typedef typename Graph::UndirIncEdgeIt UndirIncEdgeIt;
    4.85 +
    4.86 +	  checkConcept<GraphIterator<Graph, UndirEdge>, UndirEdgeIt>();
    4.87 +	  checkConcept<GraphIncIterator<Graph, UndirEdge>, UndirIncEdgeIt>();
    4.88 +	}
    4.89 +      };
    4.90 +
    4.91 +    };
    4.92 +
    4.93 +    struct MappableUndirGraphConcept {
    4.94 +
    4.95 +      template <typename Graph>
    4.96 +      struct Constraints {
    4.97 +
    4.98 +	struct Dummy {
    4.99 +	  int value;
   4.100 +	  Dummy() : value(0) {}
   4.101 +	  Dummy(int _v) : value(_v) {}
   4.102 +	};
   4.103 +
   4.104 +	void constraints() {
   4.105 +	  checkConcept<MappableGraphComponent, Graph>();
   4.106 +
   4.107 +	  typedef typename Graph::template UndirEdgeMap<int> IntMap;
   4.108 +	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, int>,
   4.109 +	    IntMap >();
   4.110 +
   4.111 +	  typedef typename Graph::template UndirEdgeMap<bool> BoolMap;
   4.112 +	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, bool>,
   4.113 +	    BoolMap >();
   4.114 +
   4.115 +	  typedef typename Graph::template UndirEdgeMap<Dummy> DummyMap;
   4.116 +	  checkConcept<GraphMap<Graph, typename Graph::UndirEdge, Dummy>,
   4.117 +	    DummyMap >();
   4.118 +	}
   4.119 +      };
   4.120 +
   4.121 +    };
   4.122 +
   4.123 +    struct ExtendableUndirGraphConcept {
   4.124 +
   4.125 +      template <typename Graph>
   4.126 +      struct Constraints {
   4.127 +	void constraints() {
   4.128 +	  node_a = graph.addNode();
   4.129 +	  uedge = graph.addEdge(node_a, node_b);
   4.130 +	}
   4.131 +	typename Graph::Node node_a, node_b;
   4.132 +	typename Graph::UndirEdge uedge;
   4.133 +	Graph graph;
   4.134 +      };
   4.135 +
   4.136 +    };
   4.137 +
   4.138 +    struct ErasableUndirGraphConcept {
   4.139 +
   4.140 +      template <typename Graph>
   4.141 +      struct Constraints {
   4.142 +	void constraints() {
   4.143 +	  graph.erase(n);
   4.144 +	  graph.erase(e);
   4.145 +	}
   4.146 +	Graph graph;
   4.147 +	typename Graph::Node n;
   4.148 +	typename Graph::UndirEdge e;
   4.149 +      };
   4.150 +
   4.151 +    };
   4.152 +
   4.153 +    class UndirGraph {
   4.154 +    public:
   4.155 +
   4.156 +      template <typename Graph>
   4.157 +      struct Constraints {
   4.158 +	void constraints() {
   4.159 +	  checkConcept<BaseIterableUndirGraphConcept, Graph>();
   4.160 +	  checkConcept<IterableUndirGraphConcept, Graph>();
   4.161 +	  checkConcept<MappableUndirGraphConcept, Graph>();
   4.162 +	}
   4.163 +      };
   4.164 +
   4.165 +    };
   4.166 +
   4.167 +    class ExtendableUndirGraph : public UndirGraph {
   4.168 +    public:
   4.169 +
   4.170 +      template <typename Graph>
   4.171 +      struct Constraints {
   4.172 +	void constraints() {
   4.173 +	  checkConcept<BaseIterableUndirGraphConcept, Graph>();
   4.174 +	  checkConcept<IterableUndirGraphConcept, Graph>();
   4.175 +	  checkConcept<MappableUndirGraphConcept, Graph>();
   4.176 +
   4.177 +	  checkConcept<UndirGraph, Graph>();
   4.178 +	  checkConcept<ExtendableUndirGraphConcept, Graph>();
   4.179 +	  checkConcept<ClearableGraphComponent, Graph>();
   4.180 +	}
   4.181 +      };
   4.182 +
   4.183 +    };
   4.184 +
   4.185 +    class ErasableUndirGraph : public ExtendableUndirGraph {
   4.186 +    public:
   4.187 +
   4.188 +      template <typename Graph>
   4.189 +      struct Constraints {
   4.190 +	void constraints() {
   4.191 +	  checkConcept<ExtendableUndirGraph, Graph>();
   4.192 +	  checkConcept<ErasableUndirGraphConcept, Graph>();
   4.193 +	}
   4.194 +      };
   4.195 +
   4.196      };
   4.197  
   4.198    }
     5.1 --- a/src/lemon/concept_check.h	Thu Nov 25 14:48:24 2004 +0000
     5.2 +++ b/src/lemon/concept_check.h	Sun Nov 28 16:30:10 2004 +0000
     5.3 @@ -41,7 +41,11 @@
     5.4  
     5.5    template <typename Concept, typename Type>
     5.6    inline void checkConcept() {
     5.7 -    function_requires<typename Concept::template Constraints<Type> >();
     5.8 +#if !defined(NDEBUG)
     5.9 +    typedef typename Concept::template Constraints<Type> ConceptCheck;
    5.10 +    void (ConceptCheck::*x)() = & ConceptCheck::constraints;
    5.11 +    ignore_unused_variable_warning(x);
    5.12 +#endif
    5.13    }
    5.14  
    5.15  #define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
     6.1 --- a/src/lemon/default_map.h	Thu Nov 25 14:48:24 2004 +0000
     6.2 +++ b/src/lemon/default_map.h	Sun Nov 28 16:30:10 2004 +0000
     6.3 @@ -172,45 +172,55 @@
     6.4      template <typename _Value>
     6.5      class NodeMap : public DefaultMap<Graph, Node, NodeIt, _Value> {
     6.6      public:
     6.7 -      typedef DefaultMappableGraphExtender<_Base> Graph;
     6.8 -
     6.9 -      typedef typename Graph::Node Node;
    6.10 -      typedef typename Graph::NodeIt NodeIt;
    6.11 -
    6.12 +      typedef DefaultMappableGraphExtender Graph;
    6.13        typedef DefaultMap<Graph, Node, NodeIt, _Value> Parent;
    6.14  
    6.15 -      //typedef typename Parent::Graph Graph;
    6.16 -      typedef typename Parent::Value Value;
    6.17 -
    6.18        NodeMap(const Graph& _g) 
    6.19  	: Parent(_g) {}
    6.20 -      NodeMap(const Graph& _g, const Value& _v) 
    6.21 +      NodeMap(const Graph& _g, const _Value& _v) 
    6.22  	: Parent(_g, _v) {}
    6.23 -
    6.24      };
    6.25  
    6.26      template <typename _Value>
    6.27      class EdgeMap : public DefaultMap<Graph, Edge, EdgeIt, _Value> {
    6.28      public:
    6.29 -      typedef DefaultMappableGraphExtender<_Base> Graph;
    6.30 -
    6.31 -      typedef typename Graph::Edge Edge;
    6.32 -      typedef typename Graph::EdgeIt EdgeIt;
    6.33 -
    6.34 +      typedef DefaultMappableGraphExtender Graph;
    6.35        typedef DefaultMap<Graph, Edge, EdgeIt, _Value> Parent;
    6.36  
    6.37 -      //typedef typename Parent::Graph Graph;
    6.38 -      typedef typename Parent::Value Value;
    6.39 -
    6.40        EdgeMap(const Graph& _g) 
    6.41  	: Parent(_g) {}
    6.42 -      EdgeMap(const Graph& _g, const Value& _v) 
    6.43 +      EdgeMap(const Graph& _g, const _Value& _v) 
    6.44  	: Parent(_g, _v) {}
    6.45 -
    6.46      };
    6.47      
    6.48    };
    6.49  
    6.50 +  template <typename _Base> 
    6.51 +  class MappableUndirGraphExtender : 
    6.52 +    public DefaultMappableGraphExtender<_Base> {
    6.53 +  public:
    6.54 +
    6.55 +    typedef MappableUndirGraphExtender Graph;
    6.56 +    typedef DefaultMappableGraphExtender<_Base> Parent;
    6.57 +
    6.58 +    typedef typename Parent::UndirEdge UndirEdge;
    6.59 +    typedef typename Parent::UndirEdgeIt UndirEdgeIt;
    6.60 +
    6.61 +    template <typename _Value>
    6.62 +    class UndirEdgeMap :
    6.63 +      public DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> {
    6.64 +    public:
    6.65 +      typedef MappableUndirGraphExtender Graph;
    6.66 +      typedef DefaultMap<Graph, UndirEdge, UndirEdgeIt, _Value> Parent;
    6.67 +
    6.68 +      UndirEdgeMap(const Graph& _g) 
    6.69 +	: Parent(_g) {}
    6.70 +      UndirEdgeMap(const Graph& _g, const _Value& _v) 
    6.71 +	: Parent(_g, _v) {}
    6.72 +    };
    6.73 +
    6.74 +
    6.75 +  };
    6.76  
    6.77  }
    6.78  
     7.1 --- a/src/lemon/erasable_graph_extender.h	Thu Nov 25 14:48:24 2004 +0000
     7.2 +++ b/src/lemon/erasable_graph_extender.h	Sun Nov 28 16:30:10 2004 +0000
     7.3 @@ -43,6 +43,38 @@
     7.4  
     7.5    };
     7.6  
     7.7 +  template <typename _Base> 
     7.8 +  class ErasableUndirGraphExtender : public _Base {
     7.9 +  public:
    7.10 +
    7.11 +    typedef ErasableUndirGraphExtender Graph;
    7.12 +    typedef _Base Parent;
    7.13 +
    7.14 +    typedef typename Parent::Node Node;
    7.15 +    typedef typename Parent::UndirEdge UndirEdge;
    7.16 +    typedef typename Parent::Edge Edge;
    7.17 +
    7.18 +    void erase(const Node& node) {
    7.19 +      Edge edge;
    7.20 +      Parent::firstOut(edge, node);
    7.21 +      while (edge != INVALID ) {
    7.22 +	erase(edge);
    7.23 +	Parent::firstOut(edge, node);
    7.24 +      } 
    7.25 +
    7.26 +      Parent::getObserverRegistry(Node()).erase(node);
    7.27 +      Parent::erase(node);
    7.28 +    }
    7.29 +    
    7.30 +    void erase(const UndirEdge& uedge) {
    7.31 +      Parent::getObserverRegistry(Edge()).erase(Edge(uedge,true));
    7.32 +      Parent::getObserverRegistry(Edge()).erase(Edge(uedge,false));
    7.33 +      Parent::getObserverRegistry(UndirEdge()).erase(uedge);
    7.34 +      Parent::erase(uedge);
    7.35 +    }
    7.36 +
    7.37 +  };
    7.38 +
    7.39  }
    7.40  
    7.41  #endif
     8.1 --- a/src/lemon/extendable_graph_extender.h	Thu Nov 25 14:48:24 2004 +0000
     8.2 +++ b/src/lemon/extendable_graph_extender.h	Sun Nov 28 16:30:10 2004 +0000
     8.3 @@ -29,6 +29,37 @@
     8.4  
     8.5    };
     8.6  
     8.7 +  template <typename _Base> 
     8.8 +  class ExtendableUndirGraphExtender : public _Base {
     8.9 +  public:
    8.10 +
    8.11 +    typedef ExtendableUndirGraphExtender Graph;
    8.12 +    typedef _Base Parent;
    8.13 +
    8.14 +    typedef typename Parent::Node Node;
    8.15 +    typedef typename Parent::Edge Edge;
    8.16 +    typedef typename Parent::UndirEdge UndirEdge;
    8.17 +
    8.18 +    Node addNode() {
    8.19 +      Node node = Parent::addNode();
    8.20 +      Parent::getObserverRegistry(Node()).add(node);
    8.21 +      return node;
    8.22 +    }
    8.23 +
    8.24 +    UndirEdge addEdge(const Node& from, const Node& to) {
    8.25 +      UndirEdge uedge = Parent::addEdge(from, to);
    8.26 +      Parent::getObserverRegistry(UndirEdge()).add(uedge);
    8.27 +
    8.28 +      Edge edge_forward(uedge, true);
    8.29 +      Edge edge_backward(uedge, false);
    8.30 +      Parent::getObserverRegistry(Edge()).add(edge_forward);
    8.31 +      Parent::getObserverRegistry(Edge()).add(edge_backward);
    8.32 +
    8.33 +      return uedge;
    8.34 +    }
    8.35 +
    8.36 +  };
    8.37 +
    8.38  }
    8.39  
    8.40  #endif
     9.1 --- a/src/lemon/iterable_graph_extender.h	Thu Nov 25 14:48:24 2004 +0000
     9.2 +++ b/src/lemon/iterable_graph_extender.h	Sun Nov 28 16:30:10 2004 +0000
     9.3 @@ -176,8 +176,11 @@
     9.4        }
     9.5  
     9.6        // FIXME: Do we need this type of constructor here?
     9.7 -      // UndirIncEdgeIt(const Graph& _graph, const UndirEdge& e) : 
     9.8 -      //   UndirEdge(e), graph(&_graph) { }
     9.9 +      // UndirIncEdgeIt(const Graph& _graph, const Edge& e) : 
    9.10 +      //   UndirEdge(e), graph(&_graph), forward(_graph.forward(e)) { }
    9.11 +      // or
    9.12 +      // UndirIncEdgeIt(const Graph& _graph, const Node& n,
    9.13 +      //    Const UndirEdge &e) ... ?
    9.14  
    9.15        UndirIncEdgeIt& operator++() {
    9.16  	graph->_dirNextOut(*this);
    10.1 --- a/src/test/graph_test.cc	Thu Nov 25 14:48:24 2004 +0000
    10.2 +++ b/src/test/graph_test.cc	Sun Nov 28 16:30:10 2004 +0000
    10.3 @@ -29,7 +29,6 @@
    10.4  
    10.5      checkConcept<BaseExtendableGraphComponent, BaseExtendableGraphComponent >();
    10.6      checkConcept<BaseErasableGraphComponent, BaseErasableGraphComponent >();
    10.7 -    checkConcept<BaseClearableGraphComponent, BaseClearableGraphComponent >();
    10.8  
    10.9      checkConcept<IterableGraphComponent, IterableGraphComponent >();
   10.10  
    11.1 --- a/src/test/undir_graph_test.cc	Thu Nov 25 14:48:24 2004 +0000
    11.2 +++ b/src/test/undir_graph_test.cc	Sun Nov 28 16:30:10 2004 +0000
    11.3 @@ -16,12 +16,22 @@
    11.4  int main() {
    11.5    typedef UndirGraphExtender<ListGraphBase> UndirListGraphBase;
    11.6  
    11.7 -  function_requires< BaseIterableUndirGraphConcept<UndirListGraphBase> >();
    11.8 -
    11.9    typedef IterableUndirGraphExtender<
   11.10      AlterableUndirGraphExtender<UndirListGraphBase> > IterableUndirListGraph;
   11.11  
   11.12 -  function_requires< IterableUndirGraphConcept<IterableUndirListGraph> >();
   11.13 +  typedef MappableUndirGraphExtender<IterableUndirListGraph>
   11.14 +    MappableUndirListGraph;
   11.15 +
   11.16 +  typedef ErasableUndirGraphExtender<
   11.17 +    ClearableUndirGraphExtender<
   11.18 +    ExtendableUndirGraphExtender<MappableUndirListGraph> > > Graph;
   11.19 +
   11.20 +  checkConcept<BaseIterableUndirGraphConcept, Graph>();
   11.21 +  checkConcept<IterableUndirGraphConcept, Graph>();
   11.22 +  checkConcept<MappableUndirGraphConcept, Graph>();
   11.23 +
   11.24 +  checkConcept<UndirGraph, Graph>();
   11.25 +  checkConcept<ErasableUndirGraph, Graph>();
   11.26  
   11.27    return 0;
   11.28  }