Some classes assumed that the GraphMaps should be inherited
authordeba
Wed, 01 Mar 2006 10:17:25 +0000
changeset 199015fb7a4ea6be
parent 1989 d276e88aa48a
child 1991 d7442141d9ef
Some classes assumed that the GraphMaps should be inherited
from an ObserverBase. These classes parents replaced with
DefaultMap which cause that the graph maps should not be
inherited from the ObserverBase.
lemon/edge_set.h
lemon/graph_utils.h
lemon/iterable_maps.h
lemon/sub_graph.h
test/edge_set_test.cc
     1.1 --- a/lemon/edge_set.h	Wed Mar 01 10:04:47 2006 +0000
     1.2 +++ b/lemon/edge_set.h	Wed Mar 01 10:17:25 2006 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  #define LEMON_EDGE_SET_H
     1.5  
     1.6  
     1.7 +#include <lemon/bits/default_map.h>
     1.8  #include <lemon/bits/edge_set_extender.h>
     1.9  
    1.10  /// \ingroup graphs
    1.11 @@ -45,7 +46,7 @@
    1.12        NodeT() : first_out(-1), first_in(-1) {}
    1.13      };
    1.14  
    1.15 -    typedef typename Graph::template NodeMap<NodeT> NodesImplBase;
    1.16 +    typedef DefaultMap<Graph, Node, NodeT> NodesImplBase;
    1.17  
    1.18      NodesImplBase* nodes;
    1.19  
    1.20 @@ -196,6 +197,12 @@
    1.21      Node source(const Edge& edge) const { return edges[edge.id].source;}
    1.22      Node target(const Edge& edge) const { return edges[edge.id].target;}
    1.23  
    1.24 +    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
    1.25 +
    1.26 +    NodeNotifier& getNotifier(Node) const {
    1.27 +      return graph->getNotifier(Node());
    1.28 +    } 
    1.29 +
    1.30      template <typename _Value>
    1.31      class NodeMap : public Graph::template NodeMap<_Value> {
    1.32      public:
    1.33 @@ -404,7 +411,7 @@
    1.34        NodeT() : first_out(-1), first_in(-1) {}
    1.35      };
    1.36  
    1.37 -    typedef typename Graph::template NodeMap<NodeT> NodesImplBase;
    1.38 +    typedef DefaultMap<Graph, Node, NodeT> NodesImplBase;
    1.39  
    1.40      NodesImplBase* nodes;
    1.41  
    1.42 @@ -505,6 +512,12 @@
    1.43      Node source(const Edge& edge) const { return edges[edge.id].source;}
    1.44      Node target(const Edge& edge) const { return edges[edge.id].target;}
    1.45  
    1.46 +    typedef typename ItemSetTraits<Graph, Node>::ItemNotifier NodeNotifier;
    1.47 +
    1.48 +    NodeNotifier& getNotifier(Node) const {
    1.49 +      return graph->getNotifier(Node());
    1.50 +    } 
    1.51 +
    1.52      template <typename _Value>
    1.53      class NodeMap : public Graph::template NodeMap<_Value> {
    1.54      public:
     2.1 --- a/lemon/graph_utils.h	Wed Mar 01 10:04:47 2006 +0000
     2.2 +++ b/lemon/graph_utils.h	Wed Mar 01 10:17:25 2006 +0000
     2.3 @@ -28,7 +28,9 @@
     2.4  #include <lemon/utility.h>
     2.5  #include <lemon/maps.h>
     2.6  #include <lemon/traits.h>
     2.7 +
     2.8  #include <lemon/bits/alteration_notifier.h>
     2.9 +#include <lemon/bits/default_map.h>
    2.10  
    2.11  ///\ingroup gutils
    2.12  ///\file
    2.13 @@ -900,8 +902,8 @@
    2.14  #ifndef DOXYGEN
    2.15    /// \param _Map A ReadWriteMap mapping from the item type to integer.
    2.16    template <
    2.17 -    typename _Graph, typename _Item, typename _Value, typename _Map 
    2.18 -    = typename ItemSetTraits<_Graph, _Item>::template Map<_Value>::Parent 
    2.19 +    typename _Graph, typename _Item, typename _Value, 
    2.20 +    typename _Map = DefaultMap<_Graph, _Item, _Value>
    2.21    >
    2.22  #else
    2.23    template <typename _Graph, typename _Item, typename _Value>
    2.24 @@ -1105,8 +1107,8 @@
    2.25  #ifndef DOXYGEN
    2.26    /// \param _Map A ReadWriteMap mapping from the item type to integer.
    2.27    template <
    2.28 -    typename _Graph, typename _Item, typename _Map 
    2.29 -    = typename ItemSetTraits<_Graph, _Item>::template Map<int>::Parent 
    2.30 +    typename _Graph, typename _Item,
    2.31 +    typename _Map = DefaultMap<_Graph, _Item, int>
    2.32    >
    2.33  #else
    2.34    template <typename _Graph, typename _Item>
    2.35 @@ -1505,14 +1507,11 @@
    2.36  
    2.37    private:
    2.38  
    2.39 -    class AutoNodeMap : public Graph::template NodeMap<int> {
    2.40 +    class AutoNodeMap : public DefaultMap<_Graph, Key, int> {
    2.41      public:
    2.42  
    2.43 -      typedef typename Graph::template NodeMap<int> Parent;
    2.44 +      typedef DefaultMap<_Graph, Key, int> Parent;
    2.45  
    2.46 -      typedef typename Parent::Key Key;
    2.47 -      typedef typename Parent::Value Value;
    2.48 -      
    2.49        AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
    2.50        
    2.51        virtual void add(const Key& key) {
    2.52 @@ -1622,14 +1621,11 @@
    2.53  
    2.54    private:
    2.55  
    2.56 -    class AutoNodeMap : public Graph::template NodeMap<int> {
    2.57 +    class AutoNodeMap : public DefaultMap<_Graph, Key, int> {
    2.58      public:
    2.59  
    2.60 -      typedef typename Graph::template NodeMap<int> Parent;
    2.61 +      typedef DefaultMap<_Graph, Key, int> Parent;
    2.62  
    2.63 -      typedef typename Parent::Key Key;
    2.64 -      typedef typename Parent::Value Value;
    2.65 -      
    2.66        AutoNodeMap(const Graph& graph) : Parent(graph, 0) {}
    2.67        
    2.68        virtual void add(const Key& key) {
    2.69 @@ -1663,7 +1659,7 @@
    2.70  	ObserverBase::detach();
    2.71      }
    2.72      
    2.73 -    /// Gives back the in-degree of a Node.
    2.74 +    /// Gives back the out-degree of a Node.
    2.75      int operator[](const Key& key) const {
    2.76        return deg[key];
    2.77      }
     3.1 --- a/lemon/iterable_maps.h	Wed Mar 01 10:04:47 2006 +0000
     3.2 +++ b/lemon/iterable_maps.h	Wed Mar 01 10:17:25 2006 +0000
     3.3 @@ -19,6 +19,8 @@
     3.4  #include <lemon/traits.h>
     3.5  #include <lemon/invalid.h>
     3.6  
     3.7 +#include <lemon/bits/default_map.h>
     3.8 +
     3.9  #include <vector>
    3.10  #include <map>
    3.11  
    3.12 @@ -47,14 +49,12 @@
    3.13    /// \param _Graph The graph type.
    3.14    /// \param _Item One of the graph's item type, the key of the map.
    3.15    template <typename _Graph, typename _Item>
    3.16 -  class IterableBoolMap 
    3.17 -    : protected ItemSetTraits<_Graph, _Item>::template Map<int>::Parent {
    3.18 +  class IterableBoolMap : protected DefaultMap<_Graph, _Item, int> {
    3.19    private:
    3.20      typedef _Graph Graph;
    3.21      
    3.22      typedef typename ItemSetTraits<Graph, _Item>::ItemIt KeyIt;
    3.23 -    typedef typename ItemSetTraits<Graph, _Item>
    3.24 -    ::template Map<int>::Parent Parent;
    3.25 +    typedef DefaultMap<_Graph, _Item, int> Parent;
    3.26      
    3.27      std::vector<_Item> array;
    3.28      int sep;
    3.29 @@ -399,12 +399,13 @@
    3.30    /// \param _Graph The graph type.
    3.31    /// \param _Item One of the graph's item type, the key of the map.
    3.32    template <typename _Graph, typename _Item>
    3.33 -  class IterableIntMap : protected ItemSetTraits<_Graph, _Item> 
    3.34 -  ::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >::Parent {
    3.35 +  class IterableIntMap 
    3.36 +    : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
    3.37 +                           IterableIntMapNode<_Item> > {
    3.38    public:
    3.39 -    typedef typename ItemSetTraits<_Graph, _Item> 
    3.40 -    ::template Map<_iterable_maps_bits::IterableIntMapNode<_Item> >
    3.41 -    ::Parent Parent;
    3.42 +    typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
    3.43 +                       IterableIntMapNode<_Item> >
    3.44 +    Parent;
    3.45  
    3.46      /// The key type
    3.47      typedef _Item Key;
    3.48 @@ -687,13 +688,12 @@
    3.49    /// \param _Item One of the graph's item type, the key of the map.
    3.50    /// \param _Value Any comparable value type.
    3.51    template <typename _Graph, typename _Item, typename _Value>
    3.52 -  class IterableValueMap : protected ItemSetTraits<_Graph, _Item> 
    3.53 -  ::template Map<_iterable_maps_bits::IterableValueMapNode<_Item, _Value> >
    3.54 -  ::Parent {
    3.55 +  class IterableValueMap 
    3.56 +    : protected DefaultMap<_Graph, _Item, _iterable_maps_bits::
    3.57 +                           IterableValueMapNode<_Item, _Value> > {
    3.58    public:
    3.59 -    typedef typename ItemSetTraits<_Graph, _Item> 
    3.60 -    ::template Map<_iterable_maps_bits::IterableValueMapNode<_Item, _Value> >
    3.61 -    ::Parent Parent;
    3.62 +    typedef DefaultMap<_Graph, _Item, _iterable_maps_bits::
    3.63 +                       IterableValueMapNode<_Item, _Value> > Parent;
    3.64  
    3.65      /// The key type
    3.66      typedef _Item Key;
    3.67 @@ -702,19 +702,25 @@
    3.68      /// The graph type
    3.69      typedef _Graph Graph;
    3.70  
    3.71 +  protected:
    3.72 +
    3.73 +    typedef typename ItemSetTraits<_Graph, Key>::ItemIt KeyIt; 
    3.74 +
    3.75 +  public:
    3.76 +
    3.77      /// \brief Constructor of the Map with a given value.
    3.78      ///
    3.79      /// Constructor of the Map with a given value.
    3.80      explicit IterableValueMap(const Graph& graph, 
    3.81                                const Value& value = Value()) 
    3.82 -      : Parent(graph, _iterable_maps_bits::IterableValueMapNode<_Item, 
    3.83 -               _Value>(value)) {
    3.84 -      for (typename Parent::ItemIt it(*this); it != INVALID; ++it) {
    3.85 +      : Parent(graph, _iterable_maps_bits::
    3.86 +               IterableValueMapNode<_Item, _Value>(value)) {
    3.87 +      for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
    3.88          lace(it);
    3.89        }
    3.90      }
    3.91  
    3.92 -  private:
    3.93 +  protected:
    3.94      
    3.95      void unlace(const Key& key) {
    3.96        typename Parent::Value& node = Parent::operator[](key);
    3.97 @@ -871,6 +877,18 @@
    3.98  
    3.99    protected:
   3.100      
   3.101 +    virtual void add(const Key& key) {
   3.102 +      Parent::add(key);
   3.103 +      unlace(key);
   3.104 +    }
   3.105 +
   3.106 +    virtual void add(const std::vector<Key>& keys) {
   3.107 +      Parent::add(keys);
   3.108 +      for (int i = 0; i < (int)keys.size(); ++i) {
   3.109 +        lace(keys[i]);
   3.110 +      }
   3.111 +    }
   3.112 +
   3.113      virtual void erase(const Key& key) {
   3.114        unlace(key);
   3.115        Parent::erase(key);
   3.116 @@ -883,6 +901,13 @@
   3.117        Parent::erase(keys);
   3.118      }
   3.119  
   3.120 +    virtual void build() {
   3.121 +      Parent::build();
   3.122 +      for (KeyIt it(*Parent::getGraph()); it != INVALID; ++it) {
   3.123 +        lace(it);
   3.124 +      }
   3.125 +    }
   3.126 +
   3.127      virtual void clear() {
   3.128        first.clear();
   3.129        Parent::clear();
     4.1 --- a/lemon/sub_graph.h	Wed Mar 01 10:04:47 2006 +0000
     4.2 +++ b/lemon/sub_graph.h	Wed Mar 01 10:17:25 2006 +0000
     4.3 @@ -20,6 +20,8 @@
     4.4  #define LEMON_SUB_GRAPH_H
     4.5  
     4.6  #include <lemon/graph_adaptor.h>
     4.7 +#include <lemon/bits/graph_adaptor_extender.h>
     4.8 +#include <lemon/bits/default_map.h>
     4.9  
    4.10  namespace lemon {
    4.11  
    4.12 @@ -242,10 +244,10 @@
    4.13        Node prev, next;
    4.14        Edge firstIn, firstOut;
    4.15      };
    4.16 -    class NodesImpl : public Graph::template NodeMap<NodeT> {
    4.17 +    class NodesImpl : public DefaultMap<Graph, Node, NodeT> {
    4.18        friend class SubGraphBase;
    4.19      public:
    4.20 -      typedef typename Graph::template NodeMap<NodeT> Parent;
    4.21 +      typedef DefaultMap<Graph, Node, NodeT> Parent;
    4.22  
    4.23        NodesImpl(SubGraph& _adaptor, const Graph& _graph) 
    4.24  	: Parent(_graph), adaptor(_adaptor) {}
    4.25 @@ -305,10 +307,10 @@
    4.26        Edge prevOut, nextOut;
    4.27        Edge prevIn, nextIn;
    4.28      };
    4.29 -    class EdgesImpl : public Graph::template EdgeMap<EdgeT> {
    4.30 +    class EdgesImpl : public DefaultMap<Graph, Edge, EdgeT> {
    4.31        friend class SubGraphBase;
    4.32      public:
    4.33 -      typedef typename Graph::template EdgeMap<EdgeT> Parent;
    4.34 +      typedef DefaultMap<Graph, Edge, EdgeT> Parent;
    4.35  
    4.36        EdgesImpl(SubGraph& _adaptor, const Graph& _graph) 
    4.37  	: Parent(_graph), adaptor(_adaptor) {}
    4.38 @@ -560,10 +562,10 @@
    4.39      struct NodeT {
    4.40        Edge firstIn, firstOut;
    4.41      };
    4.42 -    class NodesImpl : public Graph::template NodeMap<NodeT> {
    4.43 +    class NodesImpl : public DefaultMap<Graph, Node, NodeT> {
    4.44        friend class EdgeSubGraphBase;
    4.45      public:
    4.46 -      typedef typename Graph::template NodeMap<NodeT> Parent;
    4.47 +      typedef DefaultMap<Graph, Node, NodeT> Parent;
    4.48  
    4.49        NodesImpl(SubGraph& _adaptor, const Graph& _graph) 
    4.50  	: Parent(_graph), adaptor(_adaptor) {}
    4.51 @@ -603,10 +605,10 @@
    4.52        Edge prevOut, nextOut;
    4.53        Edge prevIn, nextIn;
    4.54      };
    4.55 -    class EdgesImpl : public Graph::template EdgeMap<EdgeT> {
    4.56 +    class EdgesImpl : public DefaultMap<Graph, Edge, EdgeT> {
    4.57        friend class EdgeSubGraphBase;
    4.58      public:
    4.59 -      typedef typename Graph::template EdgeMap<EdgeT> Parent;
    4.60 +      typedef DefaultMap<Graph, Edge, EdgeT> Parent;
    4.61  
    4.62        EdgesImpl(SubGraph& _adaptor, const Graph& _graph) 
    4.63  	: Parent(_graph), adaptor(_adaptor) {}
     5.1 --- a/test/edge_set_test.cc	Wed Mar 01 10:04:47 2006 +0000
     5.2 +++ b/test/edge_set_test.cc	Wed Mar 01 10:17:25 2006 +0000
     5.3 @@ -17,7 +17,7 @@
     5.4  using namespace lemon;
     5.5  using namespace lemon::concept;
     5.6  
     5.7 -typedef StaticGraph Graph;
     5.8 +typedef SmartGraph Graph;
     5.9  
    5.10  int main() {
    5.11    { // checking edge_sets