COIN-OR::LEMON - Graph Library

Changeset 1669:66ae78d29f1e in lemon-0.x for lemon/bits/vector_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/vector_map.h

    r1587 r1669  
    2424#include <lemon/bits/map_iterator.h>
    2525#include <lemon/bits/alteration_notifier.h>
    26 
    27 ///\ingroup graphmapfactory
     26#include <lemon/concept_check.h>
     27#include <lemon/concept/maps.h>
     28
     29/// \ingroup graphmapfactory
     30///
    2831///\file
    2932///\brief Vector based graph maps.
    3033
    3134namespace lemon {
    32  
    33   /// \addtogroup graphmapfactory
    34   /// @{
    35  
     35
     36  /// \ingroup graphmapfactory
     37  ///
     38  /// \brief Graph map based on the std::vector storage.
     39  ///
    3640  /// The VectorMap template class is graph map structure what
    3741  /// automatically updates the map when a key is added to or erased from
     
    118122    }
    119123
    120     using Parent::attach;
    121     using Parent::detach;
    122     using Parent::attached;
    123 
    124     /** Assign operator to copy a map of the same map type.
    125      */
    126     VectorMap& operator=(const VectorMap& copy) {
    127       if (&copy == this) return *this;
    128      
    129       if (graph != copy.graph) {
    130         if (attached()) {
    131           detach();
    132         }
    133         if (copy.attached()) {
    134           attach(*copy.getRegistry());
    135         }
    136       }
    137       container = copy.container;
    138 
    139       return *this;
    140     }
    141 
    142 
    143124    virtual ~VectorMap() {
    144125      if (attached()) {
     
    147128    }
    148129
     130
     131  private:
     132
     133    VectorMap& operator=(const VectorMap&);
     134
     135  protected:
     136
     137    using Parent::attach;
     138    using Parent::detach;
     139    using Parent::attached;
     140
    149141    const Graph* getGraph() const {
    150142      return graph;
    151143    }
     144
     145  public:
    152146
    153147    /// The subcript operator.
     
    174168    /// It the same as operator[](key) = value expression.
    175169    ///
    176      
    177170    void set(const Key& key, const Value& value) {
    178171      (*this)[key] = value;
    179172    }
    180173
    181     /// Adds a new key to the map.
    182                
     174  protected:
     175
     176    /// \brief Adds a new key to the map.
     177    ///         
    183178    /// It adds a new key to the map. It called by the observer registry
    184179    /// and it overrides the add() member function of the observer base.
     
    221216  };
    222217
    223 
    224   template <typename _Base>
    225   class VectorMappableGraphExtender : public _Base {
    226   public:
    227 
    228     typedef VectorMappableGraphExtender<_Base> Graph;
    229     typedef _Base Parent;
    230 
    231     typedef typename Parent::Node Node;
    232     typedef typename Parent::NodeIt NodeIt;
    233     typedef typename Parent::NodeIdMap NodeIdMap;
    234     typedef typename Parent::NodeNotifier NodeObserverRegistry;
    235 
    236     typedef typename Parent::Edge Edge;
    237     typedef typename Parent::EdgeIt EdgeIt;
    238     typedef typename Parent::EdgeIdMap EdgeIdMap;
    239     typedef typename Parent::EdgeNotifier EdgeObserverRegistry;
    240 
    241    
    242     template <typename _Value>
    243     class NodeMap :
    244       public IterableMapExtender<VectorMap<Graph, Node, _Value> > {
    245     public:
    246       typedef VectorMappableGraphExtender<_Base> Graph;
    247 
    248       typedef typename Graph::Node Node;
    249 
    250       typedef IterableMapExtender<VectorMap<Graph, Node, _Value> > Parent;
    251 
    252       //typedef typename Parent::Graph Graph;
    253       typedef typename Parent::Value Value;
    254 
    255       NodeMap(const Graph& g)
    256         : Parent(g) {}
    257       NodeMap(const Graph& g, const Value& v)
    258         : Parent(g, v) {}
    259 
    260     };
    261 
    262     template <typename _Value>
    263     class EdgeMap
    264       : public IterableMapExtender<VectorMap<Graph, Edge, _Value> > {
    265     public:
    266       typedef VectorMappableGraphExtender<_Base> Graph;
    267 
    268       typedef typename Graph::Edge Edge;
    269 
    270       typedef IterableMapExtender<VectorMap<Graph, Edge, _Value> > Parent;
    271 
    272       //typedef typename Parent::Graph Graph;
    273       typedef typename Parent::Value Value;
    274 
    275       EdgeMap(const Graph& g)
    276         : Parent(g) {}
    277       EdgeMap(const Graph& g, const Value& v)
    278         : Parent(g, v) {}
    279 
    280     };
    281    
    282   };
    283  
    284   /// @}
    285  
    286218}
    287219
Note: See TracChangeset for help on using the changeset viewer.