COIN-OR::LEMON - Graph Library

Changeset 1669:66ae78d29f1e in lemon-0.x


Ignore:
Timestamp:
08/31/05 15:29:32 (14 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.

Location:
lemon
Files:
10 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
  • lemon/bits/default_map.h

    r1587 r1669  
    2929namespace lemon {
    3030
    31 /// \addtogroup graphmapfactory
    32 /// @{
    33 
    34   /** The ArrayMap template class is graph map structure what
    35    *  automatically updates the map when a key is added to or erased from
    36    *  the map. This map uses the VectorMap if the Value is a primitive
    37    *  type and the ArrayMap for the other cases.
    38    *
    39    *  The template parameter is the MapRegistry that the maps
    40    *  will belong to and the Value.
    41    */
    42 
    43 
     31  /// \addtogroup graphmapfactory
     32  /// @{
    4433
    4534  template <typename _Graph, typename _Item, typename _Value>
     
    136125  };
    137126
    138 
    139 
     127  /// \e
    140128  template <
    141129    typename _Graph,
     
    153141    DefaultMap(const Graph& _g) : Parent(_g) {}
    154142    DefaultMap(const Graph& _g, const Value& _v) : Parent(_g, _v) {}
    155   };
    156 
    157 
    158 
     143
     144  };
     145
     146
     147  /// \e
    159148  template <typename _Base>
    160   class DefaultMappableGraphExtender : public _Base {
     149  class MappableGraphExtender : public _Base {
    161150  public:
    162151
    163     typedef DefaultMappableGraphExtender<_Base> Graph;
     152    typedef MappableGraphExtender<_Base> Graph;
    164153    typedef _Base Parent;
    165154
     
    175164      : public IterableMapExtender<DefaultMap<Graph, Node, _Value> > {
    176165    public:
    177       typedef DefaultMappableGraphExtender Graph;
     166      typedef MappableGraphExtender Graph;
    178167      typedef IterableMapExtender<DefaultMap<Graph, Node, _Value> > Parent;
    179168
     
    182171      NodeMap(const Graph& _g, const _Value& _v)
    183172        : Parent(_g, _v) {}
     173
     174      /// \brief Template assign operator.
     175      ///
     176      /// The given parameter should be conform to the ReadMap
     177      /// concecpt and could be indiced by the current item set of
     178      /// the NodeMap. In this case the value for each item
     179      /// is assigned by the value of the given ReadMap.
     180      template <typename CMap>
     181      NodeMap& operator=(const CMap& cmap) {
     182        checkConcept<concept::ReadMap<Node, _Value>, CMap>();
     183        const typename Parent::Graph* graph = Parent::getGraph();
     184        Node it;
     185        for (graph->first(it); it != INVALID; graph->next(it)) {
     186          Parent::set(it, cmap[it]);
     187        }
     188        return *this;
     189      }
     190
    184191    };
    185192
     
    188195      : public IterableMapExtender<DefaultMap<Graph, Edge, _Value> > {
    189196    public:
    190       typedef DefaultMappableGraphExtender Graph;
     197      typedef MappableGraphExtender Graph;
    191198      typedef IterableMapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
    192199
     
    195202      EdgeMap(const Graph& _g, const _Value& _v)
    196203        : Parent(_g, _v) {}
     204
     205      template <typename CMap>
     206      EdgeMap& operator=(const CMap& cmap) {
     207        checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
     208        const typename Parent::Graph* graph = Parent::getGraph();
     209        Edge it;
     210        for (graph->first(it); it != INVALID; graph->next(it)) {
     211          Parent::set(it, cmap[it]);
     212        }
     213        return *this;
     214      }
    197215    };
    198216   
    199217  };
    200218
     219  /// \e
    201220  template <typename _Base>
    202221  class MappableUndirGraphExtender :
    203     public DefaultMappableGraphExtender<_Base> {
     222    public MappableGraphExtender<_Base> {
    204223  public:
    205224
    206225    typedef MappableUndirGraphExtender Graph;
    207     typedef DefaultMappableGraphExtender<_Base> Parent;
     226    typedef MappableGraphExtender<_Base> Parent;
    208227
    209228    typedef typename Parent::UndirEdge UndirEdge;
     
    221240      UndirEdgeMap(const Graph& _g, const _Value& _v)
    222241        : Parent(_g, _v) {}
     242
     243      template <typename CMap>
     244      UndirEdgeMap& operator=(const CMap& cmap) {
     245        checkConcept<concept::ReadMap<UndirEdge, _Value>, CMap>();
     246        const typename Parent::Graph* graph = Parent::getGraph();
     247        UndirEdge it;
     248        for (graph->first(it); it != INVALID; graph->next(it)) {
     249          Parent::set(it, cmap[it]);
     250        }
     251        return *this;
     252      }
    223253    };
    224254
     
    226256  };
    227257
     258  /// @}
    228259}
    229260
  • 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
  • lemon/concept/graph_component.h

    r1644 r1669  
    799799          // Copy constructor. Do we need it?
    800800          _Map b=c;
    801           // Copy operator. Do we need it?
    802           a=b;
    803801
    804802          ignore_unused_variable_warning(a2);
  • lemon/concept/undir_graph.h

    r1643 r1669  
    249249      typedef True UndirTag;
    250250
    251       /// The base type of node iterators,
     251      /// \brief The base type of node iterators,
    252252      /// or in other words, the trivial node iterator.
    253 
     253      ///
    254254      /// This is the base type of each node iterator,
    255255      /// thus each kind of node iterator converts to this.
  • lemon/full_graph.h

    r1643 r1669  
    196196  typedef IterableGraphExtender<AlterableFullGraphBase>
    197197  IterableFullGraphBase;
    198   typedef DefaultMappableGraphExtender<IterableFullGraphBase>
    199   MappableFullGraphBase;
     198  typedef MappableGraphExtender<
     199    IterableGraphExtender<
     200    AlterableGraphExtender<FullGraphBase> > > ExtendedFullGraphBase;
    200201
    201202  /// \ingroup graphs
     
    211212  ///
    212213  /// \author Alpar Juttner
    213   class FullGraph : public MappableFullGraphBase {
     214  class FullGraph : public ExtendedFullGraphBase {
    214215  public:
    215216
     
    379380  };
    380381
    381   typedef UndirGraphExtender<UndirFullGraphBase>
    382   UndirUndirFullGraphBase;
    383   typedef AlterableUndirGraphExtender<UndirUndirFullGraphBase>
    384   AlterableUndirFullGraphBase;
    385   typedef IterableUndirGraphExtender<AlterableUndirFullGraphBase>
    386   IterableUndirFullGraphBase;
    387   typedef MappableUndirGraphExtender<IterableUndirFullGraphBase>
    388   MappableUndirFullGraphBase;
     382  typedef MappableUndirGraphExtender<
     383    IterableUndirGraphExtender<
     384    AlterableUndirGraphExtender<
     385    UndirGraphExtender<UndirFullGraphBase> > > > ExtendedUndirFullGraphBase;
    389386
    390387  /// \ingroup graphs
     
    403400  ///
    404401  /// \author Balazs Dezso
    405   class UndirFullGraph : public MappableUndirFullGraphBase {
     402  class UndirFullGraph : public ExtendedUndirFullGraphBase {
    406403  public:
    407404    UndirFullGraph(int n) { construct(n); }
  • lemon/graph_adaptor.h

    r1631 r1669  
    14311431    ClearableGraphExtender<
    14321432    ExtendableGraphExtender<
    1433     DefaultMappableGraphExtender<
     1433    MappableGraphExtender<
    14341434    IterableGraphExtender<
    14351435    AlterableGraphExtender<
     
    14411441      ClearableGraphExtender<
    14421442      ExtendableGraphExtender<
    1443       DefaultMappableGraphExtender<
     1443      MappableGraphExtender<
    14441444      IterableGraphExtender<
    14451445      AlterableGraphExtender<
  • lemon/list_graph.h

    r1555 r1669  
    305305  typedef AlterableGraphExtender<ListGraphBase> AlterableListGraphBase;
    306306  typedef IterableGraphExtender<AlterableListGraphBase> IterableListGraphBase;
    307   typedef DefaultMappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
     307  typedef MappableGraphExtender<IterableListGraphBase> MappableListGraphBase;
    308308  typedef ExtendableGraphExtender<MappableListGraphBase> ExtendableListGraphBase;
    309309  typedef ClearableGraphExtender<ExtendableListGraphBase> ClearableListGraphBase;
    310   typedef ErasableGraphExtender<ClearableListGraphBase> ErasableListGraphBase;
     310  typedef ErasableGraphExtender<
     311    ClearableGraphExtender<
     312    ExtendableGraphExtender<
     313    MappableGraphExtender<
     314    IterableGraphExtender<
     315    AlterableGraphExtender<ListGraphBase> > > > > > ExtendedListGraphBase;
    311316
    312317/// \addtogroup graphs
     
    322327  ///\sa concept::ErasableGraph.
    323328
    324   class ListGraph : public ErasableListGraphBase
     329  class ListGraph : public ExtendedListGraphBase
    325330  {
    326331  public:
     
    550555    IterableUndirGraphExtender<
    551556    AlterableUndirGraphExtender<
    552     UndirGraphExtender<ListGraphBase> > > > > > > ErasableUndirListGraphBase;
     557    UndirGraphExtender<ListGraphBase> > > > > > > ExtendedUndirListGraphBase;
    553558
    554559/// \addtogroup graphs
     
    567572  ///haven't been implemented yet.
    568573  ///
    569   class UndirListGraph : public ErasableUndirListGraphBase {
     574  class UndirListGraph : public ExtendedUndirListGraphBase {
    570575  };
    571576
  • lemon/maps.h

    r1660 r1669  
    114114  ///This function just returns a \ref ConstMap class.
    115115  ///\relates ConstMap
    116   template<class V,class K>
    117   inline ConstMap<V,K> constMap(const K &k)
    118   {
    119     return ConstMap<V,K>(k);
     116  template<class K,class V>
     117  inline ConstMap<K,V> constMap(const V &v)
     118  {
     119    return ConstMap<K,V>(v);
    120120  }
    121121
  • lemon/smart_graph.h

    r1641 r1669  
    234234  };
    235235
    236   typedef AlterableGraphExtender<SmartGraphBase> AlterableSmartGraphBase;
    237   typedef IterableGraphExtender<AlterableSmartGraphBase> IterableSmartGraphBase;
    238   typedef DefaultMappableGraphExtender<IterableSmartGraphBase> MappableSmartGraphBase;
    239   typedef ExtendableGraphExtender<MappableSmartGraphBase> ExtendableSmartGraphBase;
    240   typedef ClearableGraphExtender<ExtendableSmartGraphBase> ClearableSmartGraphBase;
     236  typedef ClearableGraphExtender<
     237    ExtendableGraphExtender<
     238    MappableGraphExtender<
     239    IterableGraphExtender<
     240    AlterableGraphExtender<SmartGraphBase> > > > > ExtendedSmartGraphBase;
    241241
    242242  /// \addtogroup graphs
     
    254254  ///
    255255  ///\author Alpar Juttner
    256   class SmartGraph : public ClearableSmartGraphBase {
     256  class SmartGraph : public ExtendedSmartGraphBase {
    257257  public:
    258258    /// Finds an edge between two nodes.
     
    391391    IterableUndirGraphExtender<
    392392    AlterableUndirGraphExtender<
    393     UndirGraphExtender<SmartGraphBase> > > > > > UndirSmartGraphBase;
     393    UndirGraphExtender<SmartGraphBase> > > > > > ExtendedUndirSmartGraphBase;
    394394
    395395  ///A smart undirected graph class.
     
    405405  ///\todo SnapShot hasn't been implemented yet.
    406406  ///
    407   class UndirSmartGraph : public UndirSmartGraphBase {
     407  class UndirSmartGraph : public ExtendedUndirSmartGraphBase {
    408408  };
    409409
Note: See TracChangeset for help on using the changeset viewer.