src/lemon/vector_map.h
changeset 1114 eb57527fd183
parent 987 87f7c54892df
child 1164 80bb73097736
equal deleted inserted replaced
7:eb0815c15fd6 8:cf8757f6ea5d
    18 #define LEMON_VECTOR_MAP_H
    18 #define LEMON_VECTOR_MAP_H
    19 
    19 
    20 #include <vector>
    20 #include <vector>
    21 #include <algorithm>
    21 #include <algorithm>
    22 
    22 
    23 #include <lemon/alteration_observer_registry.h>
    23 #include <lemon/alteration_notifier.h>
    24 
    24 
    25 ///\ingroup graphmaps
    25 ///\ingroup graphmaps
    26 ///\file
    26 ///\file
    27 ///\brief Vector based graph maps.
    27 ///\brief Vector based graph maps.
    28 
    28 
    35   /// automatically updates the map when a key is added to or erased from
    35   /// automatically updates the map when a key is added to or erased from
    36   /// the map. This map factory uses the allocators to implement 
    36   /// the map. This map factory uses the allocators to implement 
    37   /// the container functionality. This map factory
    37   /// the container functionality. This map factory
    38   /// uses the std::vector to implement the container function.
    38   /// uses the std::vector to implement the container function.
    39   ///
    39   ///
    40   /// \param Registry The AlterationObserverRegistry that will notify this map.
    40   /// \param Registry The AlterationNotifier that will notify this map.
    41   /// \param IdMap The IdMap type of the graph items.
    41   /// \param IdMap The IdMap type of the graph items.
    42   /// \param Value The value type of the map.
    42   /// \param Value The value type of the map.
    43   /// 
    43   /// 
    44   /// \author Balazs Dezso
    44   /// \author Balazs Dezso
    45   	
    45   	
    46 
    46 
    47   template <typename _Graph, 
    47   template <typename _Graph, 
    48 	    typename _Item,
    48 	    typename _Item,
    49 	    typename _Value>
    49 	    typename _Value>
    50   class VectorMap : public AlterationObserverRegistry<_Item>::ObserverBase {
    50   class VectorMap : public AlterationNotifier<_Item>::ObserverBase {
    51   public:
    51   public:
    52 		
    52 		
    53     /// The graph type of the map. 
    53     /// The graph type of the map. 
    54     typedef _Graph Graph;
    54     typedef _Graph Graph;
    55     /// The key type of the map.
    55     /// The key type of the map.
    56     typedef _Item Key;
    56     typedef _Item Key;
    57     /// The id map type of the map.
    57     /// The id map type of the map.
    58     typedef AlterationObserverRegistry<_Item> Registry;
    58     typedef AlterationNotifier<_Item> Registry;
    59     /// The value type of the map.
    59     /// The value type of the map.
    60     typedef _Value Value;
    60     typedef _Value Value;
    61 
    61 
    62     /// The map type.
    62     /// The map type.
    63     typedef VectorMap Map;
    63     typedef VectorMap Map;
    87 
    87 
    88     /// It construates a map and attachs it into the registry.
    88     /// It construates a map and attachs it into the registry.
    89     /// It adds all the items of the graph to the map.
    89     /// It adds all the items of the graph to the map.
    90      
    90      
    91     VectorMap(const Graph& _g) : graph(&_g) {
    91     VectorMap(const Graph& _g) : graph(&_g) {
    92       attach(_g.getObserverRegistry(_Item()));
    92       attach(_g.getNotifier(_Item()));
    93       build();
    93       build();
    94     }
    94     }
    95 
    95 
    96     /// Constructor uses given value to initialize the map. 
    96     /// Constructor uses given value to initialize the map. 
    97 
    97 
    98     /// It construates a map uses a given value to initialize the map. 
    98     /// It construates a map uses a given value to initialize the map. 
    99     /// It adds all the items of the graph to the map.
    99     /// It adds all the items of the graph to the map.
   100      
   100      
   101     VectorMap(const Graph& _g, const Value& _v) : graph(&_g) { 
   101     VectorMap(const Graph& _g, const Value& _v) : graph(&_g) { 
   102       attach(_g.getObserverRegistry(_Item()));
   102       attach(_g.getNotifier(_Item()));
   103       container.resize(graph->maxId(_Item()) + 1, _v);
   103       container.resize(graph->maxId(_Item()) + 1, _v);
   104     }
   104     }
   105 
   105 
   106     VectorMap(const VectorMap& _copy) : graph(_copy.getGraph()) {
   106     VectorMap(const VectorMap& _copy) : graph(_copy.getGraph()) {
   107       if (_copy.attached()) {
   107       if (_copy.attached()) {
   222     typedef _Base Parent;
   222     typedef _Base Parent;
   223 
   223 
   224     typedef typename Parent::Node Node;
   224     typedef typename Parent::Node Node;
   225     typedef typename Parent::NodeIt NodeIt;
   225     typedef typename Parent::NodeIt NodeIt;
   226     typedef typename Parent::NodeIdMap NodeIdMap;
   226     typedef typename Parent::NodeIdMap NodeIdMap;
   227     typedef typename Parent::NodeObserverRegistry NodeObserverRegistry;
   227     typedef typename Parent::NodeNotifier NodeObserverRegistry;
   228 
   228 
   229     typedef typename Parent::Edge Edge;
   229     typedef typename Parent::Edge Edge;
   230     typedef typename Parent::EdgeIt EdgeIt;
   230     typedef typename Parent::EdgeIt EdgeIt;
   231     typedef typename Parent::EdgeIdMap EdgeIdMap;
   231     typedef typename Parent::EdgeIdMap EdgeIdMap;
   232     typedef typename Parent::EdgeObserverRegistry EdgeObserverRegistry;
   232     typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
   233 
   233 
   234     
   234     
   235 
   235 
   236     template <typename _Value>
   236     template <typename _Value>
   237     class NodeMap : public VectorMap<Graph, Node, _Value> {
   237     class NodeMap : public VectorMap<Graph, Node, _Value> {