COIN-OR::LEMON - Graph Library

Changeset 1669:66ae78d29f1e in lemon-0.x for lemon/bits/array_map.h


Ignore:
Timestamp:
08/31/05 15:29:32 (19 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2185
Message:

Template assign operator for graph maps.

Some naming and coding conventions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/array_map.h

    r1613 r1669  
    2020#include <memory>
    2121#include <lemon/bits/map_iterator.h>
    22 
    23 ///\ingroup graphmapfactory
    24 ///\file
    25 ///\brief Graph maps that construates and destruates
    26 ///their elements dynamically.
     22#include <lemon/concept_check.h>
     23#include <lemon/concept/maps.h>
     24
     25/// \ingroup graphmapfactory
     26/// \file
     27/// \brief Graph maps that construct and destruct
     28/// their elements dynamically.
    2729
    2830namespace lemon {
    2931
    30 
    31   /// \addtogroup graphmapfactory
    32   /// @{
    33        
     32  /// \ingroup graphmapfactory
     33  ///
     34  /// \brief Graph map based on the array storage.
     35  ///
    3436  /// The ArrayMap template class is graph map structure what
    3537  /// automatically updates the map when a key is added to or erased from
    36   /// the map. This map factory uses the allocators to implement
     38  /// the map. This map uses the allocators to implement
    3739  /// the container functionality.
    3840  ///
    3941  /// The template parameter is the AlterationNotifier that the maps
    4042  /// will belong to and the Value.
    41    
    4243
    4344  template <typename _Graph,
     
    7071
    7172    /// Graph and Registry initialized map constructor.
    72      
    7373    ArrayMap(const Graph& _g) : graph(&_g) {
    7474      Item it;
     
    111111    }
    112112
    113     using Parent::attach;
    114     using Parent::detach;
    115     using Parent::attached;
    116 
    117     /// Assign operator to copy a map of the same map type.
    118      
    119     ArrayMap& operator=(const ArrayMap& copy) {
    120       if (&copy == this) return *this;
    121      
    122       if (graph != copy.graph) {
    123         if (attached()) {
    124           clear();
    125           detach();
    126         }
    127         if (copy.attached()) {
    128           attach(*copy.getRegistry());
    129         }
    130         capacity = copy.capacity;
    131         if (capacity == 0) return *this;
    132         values = allocator.allocate(capacity);     
    133       }
    134 
    135       Item it;
    136       for (graph->first(it); it != INVALID; graph->next(it)) {
    137         int id = graph->id(it);;
    138         allocator.construct(&(values[id]), copy.values[id]);
    139       }
    140 
    141       return *this;
    142     }
    143 
     113    /// \brief The destructor of the map.
     114    ///     
    144115    /// The destructor of the map.
    145      
    146116    virtual ~ArrayMap() {     
    147117      if (attached()) {
     
    150120      }
    151121    }
    152        
    153        
     122               
     123  private:
     124
     125    ArrayMap& operator=(const ArrayMap&);
     126
     127  protected:
     128
     129    using Parent::attach;
     130    using Parent::detach;
     131    using Parent::attached;
     132
     133    const Graph* getGraph() {
     134      return graph;
     135    }
     136
     137
     138  public:
     139
    154140    ///The subscript operator. The map can be subscripted by the
    155141    ///actual keys of the graph.
     
    175161      (*this)[key] = val;
    176162    }
    177                
     163
     164  protected:
     165   
    178166    /// Add a new key to the map. It called by the map registry.
    179167     
     
    275263    }
    276264
    277     const Graph* getGraph() {
    278       return graph;
    279     }
    280 
    281265  private:
    282266     
     
    302286  };           
    303287
    304   template <typename _Base>
    305   class ArrayMappableGraphExtender : public _Base {
    306   public:
    307 
    308     typedef ArrayMappableGraphExtender<_Base> Graph;
    309     typedef _Base Parent;
    310 
    311     typedef typename Parent::Node Node;
    312     typedef typename Parent::NodeIt NodeIt;
    313     typedef typename Parent::NodeNotifier NodeObserverRegistry;
    314 
    315     typedef typename Parent::Edge Edge;
    316     typedef typename Parent::EdgeIt EdgeIt;
    317     typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
    318 
    319    
    320 
    321     template <typename _Value>
    322     class NodeMap
    323       : public IterableMapExtender<ArrayMap<Graph, Node, _Value> > {
    324     public:
    325       typedef ArrayMappableGraphExtender<_Base> Graph;
    326 
    327       typedef typename Graph::Node Node;
    328       typedef typename Graph::NodeIt NodeIt;
    329 
    330       typedef IterableMapExtender<ArrayMap<Graph, Node, _Value> > Parent;
    331 
    332       //typedef typename Parent::Graph Graph;
    333       typedef typename Parent::Value Value;
    334 
    335       NodeMap(const Graph& g)
    336         : Parent(g) {}
    337       NodeMap(const Graph& g, const Value& v)
    338         : Parent(g, v) {}
    339 
    340     };
    341 
    342     template <typename _Value>
    343     class EdgeMap
    344       : public IterableMapExtender<ArrayMap<Graph, Edge, _Value> > {
    345     public:
    346       typedef ArrayMappableGraphExtender<_Base> Graph;
    347 
    348       typedef typename Graph::Edge Edge;
    349       typedef typename Graph::EdgeIt EdgeIt;
    350 
    351       typedef IterableMapExtender<ArrayMap<Graph, Edge, _Value> > Parent;
    352 
    353       //typedef typename Parent::Graph Graph;
    354       typedef typename Parent::Value Value;
    355 
    356       EdgeMap(const Graph& g)
    357         : Parent(g) {}
    358       EdgeMap(const Graph& g, const Value& v)
    359         : Parent(g, v) {}
    360 
    361     };
    362    
    363   };
    364 
    365 /// @}
    366 
    367288}
    368289
Note: See TracChangeset for help on using the changeset viewer.