lemon/bits/static_map.h
author alpar
Fri, 03 Feb 2006 16:40:16 +0000
changeset 1956 a055123339d5
parent 1946 17eb3eaad9f8
child 1961 8e19ca944727
permissions -rw-r--r--
Unified copyright notices
deba@1703
     1
/* -*- C++ -*-
deba@1703
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1956
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1703
     8
 *
deba@1703
     9
 * Permission to use, modify and distribute this software is granted
deba@1703
    10
 * provided that this copyright notice appears in all copies. For
deba@1703
    11
 * precise terms see the accompanying LICENSE file.
deba@1703
    12
 *
deba@1703
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1703
    14
 * express or implied, and with no claim as to its suitability for any
deba@1703
    15
 * purpose.
deba@1703
    16
 *
deba@1703
    17
 */
deba@1703
    18
deba@1703
    19
#ifndef LEMON_STATIC_MAP_H
deba@1703
    20
#define LEMON_STATIC_MAP_H
deba@1703
    21
deba@1703
    22
#include <algorithm>
deba@1703
    23
#include <iostream>
deba@1703
    24
deba@1703
    25
#include <lemon/utility.h>
deba@1810
    26
#include <lemon/bits/map_extender.h>
deba@1703
    27
#include <lemon/bits/alteration_notifier.h>
deba@1703
    28
#include <lemon/error.h>
deba@1703
    29
#include <lemon/concept_check.h>
deba@1703
    30
#include <lemon/concept/maps.h>
deba@1703
    31
alpar@1946
    32
/// \ingroup graphmaps
deba@1703
    33
///
deba@1703
    34
///\file
deba@1703
    35
///\brief Static sized graph maps.
deba@1703
    36
deba@1703
    37
namespace lemon {
deba@1703
    38
alpar@1946
    39
  /// \ingroup graphmaps
deba@1703
    40
  ///
deba@1703
    41
  /// \brief Graph map with static sized storage.
deba@1703
    42
  ///
deba@1703
    43
  /// The StaticMap template class is graph map structure what
deba@1910
    44
  /// does not indate automatically the map when a key is added to or 
deba@1703
    45
  /// erased from the map rather it throws an exception. This map factory 
deba@1703
    46
  /// uses the allocators to implement the container functionality.
deba@1703
    47
  ///
deba@1703
    48
  /// \param Registry The AlterationNotifier that will notify this map.
deba@1703
    49
  /// \param Item The item type of the graph items.
deba@1703
    50
  /// \param Value The value type of the map.
deba@1703
    51
  /// 
deba@1703
    52
  /// \author Balazs Dezso
deba@1703
    53
  	
deba@1703
    54
deba@1703
    55
  template <typename _Graph, typename _Item, typename _Value>
deba@1703
    56
  class StaticMap : public AlterationNotifier<_Item>::ObserverBase {
deba@1703
    57
  public:
deba@1703
    58
deba@1910
    59
    /// \brief Exception class for unsinported exceptions.
deba@1910
    60
    class UnsinportedOperation : public lemon::LogicError {
deba@1703
    61
    public:
deba@1703
    62
      virtual const char* exceptionName() const {
deba@1910
    63
	return "lemon::StaticMap::UnsinportedOperation";
deba@1703
    64
      }
deba@1703
    65
    };
deba@1703
    66
deba@1719
    67
  private:
deba@1703
    68
		
deba@1719
    69
    typedef std::vector<_Value> Container;	
deba@1719
    70
deba@1719
    71
  public:
deba@1719
    72
deba@1703
    73
    /// The graph type of the map. 
deba@1703
    74
    typedef _Graph Graph;
deba@1719
    75
    /// The reference map tag.
deba@1719
    76
    typedef True ReferenceMapTag;
deba@1719
    77
deba@1703
    78
    /// The key type of the map.
deba@1703
    79
    typedef _Item Key;
deba@1703
    80
    /// The value type of the map.
deba@1703
    81
    typedef _Value Value;
deba@1719
    82
    /// The const reference type of the map.
deba@1719
    83
    typedef typename Container::const_reference ConstReference;
deba@1719
    84
    /// The reference type of the map.
deba@1719
    85
    typedef typename Container::reference Reference;
deba@1719
    86
deba@1719
    87
    typedef const Value ConstValue;
deba@1719
    88
    typedef Value* Pointer;
deba@1719
    89
    typedef const Value* ConstPointer;
deba@1719
    90
deba@1719
    91
    typedef AlterationNotifier<_Item> Registry;
deba@1703
    92
deba@1703
    93
    /// The map type.
deba@1703
    94
    typedef StaticMap Map;
deba@1703
    95
    /// The base class of the map.
deba@1703
    96
    typedef typename Registry::ObserverBase Parent;
deba@1703
    97
deba@1703
    98
    /// \brief Constructor to attach the new map into the registry.
deba@1703
    99
    ///
deba@1703
   100
    /// It constructs a map and attachs it into the registry.
deba@1703
   101
    /// It adds all the items of the graph to the map.
deba@1703
   102
    StaticMap(const Graph& _g) : graph(&_g) {
deba@1703
   103
      attach(_g.getNotifier(_Item()));
deba@1703
   104
      build();
deba@1703
   105
    }
deba@1703
   106
deba@1703
   107
    /// \brief Constructor uses given value to initialize the map. 
deba@1703
   108
    ///
deba@1703
   109
    /// It constructs a map uses a given value to initialize the map. 
deba@1703
   110
    /// It adds all the items of the graph to the map.     
deba@1703
   111
    StaticMap(const Graph& _g, const Value& _v) : graph(&_g) { 
deba@1703
   112
      attach(_g.getNotifier(_Item()));
deba@1703
   113
      unsigned size = graph->maxId(_Item()) + 1;
deba@1703
   114
      container.reserve(size);
deba@1703
   115
      container.resize(size, _v);
deba@1703
   116
    }
deba@1703
   117
deba@1703
   118
    /// \brief Copy constructor
deba@1703
   119
    ///
deba@1703
   120
    /// Copy constructor.
deba@1703
   121
    StaticMap(const StaticMap& _copy) : Parent(), graph(_copy.getGraph()) {
deba@1703
   122
      if (_copy.attached()) {
deba@1703
   123
	attach(*_copy.getRegistry());
deba@1703
   124
	container = _copy.container;
deba@1703
   125
      }
deba@1703
   126
    }
deba@1703
   127
deba@1703
   128
    /// \brief Destrcutor
deba@1703
   129
    ///
deba@1703
   130
    /// Destructor.
deba@1703
   131
    virtual ~StaticMap() {
deba@1703
   132
      clear();
deba@1703
   133
      if (attached()) {
deba@1703
   134
	detach();
deba@1703
   135
      }
deba@1703
   136
    }
deba@1703
   137
deba@1703
   138
deba@1703
   139
  private:
deba@1703
   140
deba@1703
   141
    StaticMap& operator=(const StaticMap&);
deba@1703
   142
deba@1703
   143
  protected:
deba@1703
   144
deba@1703
   145
    using Parent::attach;
deba@1703
   146
    using Parent::detach;
deba@1703
   147
    using Parent::attached;
deba@1703
   148
deba@1703
   149
    const Graph* getGraph() const {
deba@1703
   150
      return graph;
deba@1703
   151
    }
deba@1703
   152
deba@1703
   153
  public:
deba@1703
   154
deba@1703
   155
    /// \brief The subcript operator.
deba@1703
   156
    ///
deba@1703
   157
    /// The subscript operator. The map can be subscripted by the
deba@1703
   158
    /// actual items of the graph. 
deba@1703
   159
     
deba@1703
   160
    Reference operator[](const Key& key) {
deba@1703
   161
      return container[graph->id(key)];
deba@1703
   162
    } 
deba@1703
   163
		
deba@1703
   164
    /// \brief The const subcript operator.
deba@1703
   165
    ///
deba@1703
   166
    /// The const subscript operator. The map can be subscripted by the
deba@1703
   167
    /// actual items of the graph. 
deba@1703
   168
     
deba@1703
   169
    ConstReference operator[](const Key& key) const {
deba@1703
   170
      return container[graph->id(key)];
deba@1703
   171
    }
deba@1703
   172
deba@1703
   173
deba@1703
   174
    /// \brief The setter function of the map.
deba@1703
   175
    ///
deba@1703
   176
    /// It the same as operator[](key) = value expression.
deba@1703
   177
    ///
deba@1703
   178
    void set(const Key& key, const Value& value) {
deba@1703
   179
      (*this)[key] = value;
deba@1703
   180
    }
deba@1703
   181
deba@1703
   182
  protected:
deba@1703
   183
deba@1703
   184
    /// \brief Adds a new key to the map.
deba@1703
   185
    ///		
deba@1703
   186
    /// It adds a new key to the map. It called by the observer registry
deba@1703
   187
    /// and it overrides the add() member function of the observer base.
deba@1703
   188
     
deba@1703
   189
    void add(const Key&) {
deba@1910
   190
      throw UnsinportedOperation();
deba@1703
   191
    }
deba@1703
   192
deba@1703
   193
    /// \brief Erases a key from the map.
deba@1703
   194
    ///
deba@1703
   195
    /// Erase a key from the map. It called by the observer registry
deba@1703
   196
    /// and it overrides the erase() member function of the observer base.     
deba@1703
   197
    void erase(const Key&) {
deba@1910
   198
      throw UnsinportedOperation();
deba@1703
   199
    }
deba@1703
   200
deba@1703
   201
    /// Buildes the map.
deba@1703
   202
		
deba@1703
   203
    /// It buildes the map. It called by the observer registry
deba@1703
   204
    /// and it overrides the build() member function of the observer base.
deba@1703
   205
deba@1703
   206
    void build() { 
deba@1703
   207
      int size = graph->maxId(_Item()) + 1;
deba@1703
   208
      container.reserve(size);
deba@1703
   209
      container.resize(size);
deba@1703
   210
    }
deba@1703
   211
deba@1703
   212
    /// Clear the map.
deba@1703
   213
deba@1703
   214
    /// It erase all items from the map. It called by the observer registry
deba@1703
   215
    /// and it overrides the clear() member function of the observer base.     
deba@1703
   216
    void clear() { 
deba@1703
   217
      container.clear();
deba@1703
   218
    }
deba@1703
   219
    
deba@1703
   220
  private:
deba@1703
   221
		
deba@1703
   222
    Container container;
deba@1703
   223
    const Graph *graph;
deba@1703
   224
deba@1703
   225
  };
deba@1703
   226
deba@1703
   227
  /// \e
deba@1703
   228
  template <typename _Base> 
deba@1703
   229
  class StaticMappableGraphExtender : public _Base {
deba@1703
   230
  public:
deba@1703
   231
deba@1703
   232
    typedef StaticMappableGraphExtender<_Base> Graph;
deba@1703
   233
    typedef _Base Parent;
deba@1703
   234
deba@1703
   235
    typedef typename Parent::Node Node;
deba@1703
   236
    typedef typename Parent::NodeIt NodeIt;
deba@1703
   237
deba@1703
   238
    typedef typename Parent::Edge Edge;
deba@1703
   239
    typedef typename Parent::EdgeIt EdgeIt;
deba@1703
   240
deba@1703
   241
    
deba@1703
   242
    template <typename _Value>
deba@1703
   243
    class NodeMap 
deba@1703
   244
      : public IterableMapExtender<StaticMap<Graph, Node, _Value> > {
deba@1703
   245
    public:
deba@1703
   246
      typedef StaticMappableGraphExtender Graph;
deba@1703
   247
      typedef IterableMapExtender<StaticMap<Graph, Node, _Value> > Parent;
deba@1703
   248
deba@1703
   249
      NodeMap(const Graph& _g) 
deba@1703
   250
	: Parent(_g) {}
deba@1703
   251
      NodeMap(const Graph& _g, const _Value& _v) 
deba@1703
   252
	: Parent(_g, _v) {}
deba@1703
   253
deba@1703
   254
      NodeMap& operator=(const NodeMap& cmap) {
deba@1703
   255
	return operator=<NodeMap>(cmap);
deba@1703
   256
      }
deba@1703
   257
deba@1703
   258
deba@1703
   259
      /// \brief Template assign operator.
deba@1703
   260
      ///
deba@1703
   261
      /// The given parameter should be conform to the ReadMap
deba@1703
   262
      /// concecpt and could be indiced by the current item set of
deba@1703
   263
      /// the NodeMap. In this case the value for each item
deba@1703
   264
      /// is assigned by the value of the given ReadMap. 
deba@1703
   265
      template <typename CMap>
deba@1703
   266
      NodeMap& operator=(const CMap& cmap) {
deba@1703
   267
	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
deba@1703
   268
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1703
   269
	Node it;
deba@1703
   270
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1703
   271
	  Parent::set(it, cmap[it]);
deba@1703
   272
	}
deba@1703
   273
	return *this;
deba@1703
   274
      }
deba@1703
   275
deba@1703
   276
    };
deba@1703
   277
deba@1703
   278
    template <typename _Value>
deba@1703
   279
    class EdgeMap 
deba@1703
   280
      : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
deba@1703
   281
    public:
deba@1703
   282
      typedef StaticMappableGraphExtender Graph;
deba@1703
   283
      typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
deba@1703
   284
deba@1703
   285
      EdgeMap(const Graph& _g) 
deba@1703
   286
	: Parent(_g) {}
deba@1703
   287
      EdgeMap(const Graph& _g, const _Value& _v) 
deba@1703
   288
	: Parent(_g, _v) {}
deba@1703
   289
deba@1703
   290
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1703
   291
	return operator=<EdgeMap>(cmap);
deba@1703
   292
      }
deba@1703
   293
deba@1703
   294
      template <typename CMap>
deba@1703
   295
      EdgeMap& operator=(const CMap& cmap) {
deba@1703
   296
	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
deba@1703
   297
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1703
   298
	Edge it;
deba@1703
   299
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1703
   300
	  Parent::set(it, cmap[it]);
deba@1703
   301
	}
deba@1703
   302
	return *this;
deba@1703
   303
      }
deba@1703
   304
    };
deba@1703
   305
    
deba@1703
   306
  };
deba@1703
   307
deba@1703
   308
  /// \e
deba@1703
   309
  template <typename _Base> 
klao@1909
   310
  class StaticMappableUGraphExtender : 
deba@1703
   311
    public StaticMappableGraphExtender<_Base> {
deba@1703
   312
  public:
deba@1703
   313
klao@1909
   314
    typedef StaticMappableUGraphExtender Graph;
deba@1703
   315
    typedef StaticMappableGraphExtender<_Base> Parent;
deba@1703
   316
klao@1909
   317
    typedef typename Parent::UEdge UEdge;
deba@1703
   318
deba@1703
   319
    template <typename _Value>
klao@1909
   320
    class UEdgeMap 
klao@1909
   321
      : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
deba@1703
   322
    public:
klao@1909
   323
      typedef StaticMappableUGraphExtender Graph;
deba@1703
   324
      typedef IterableMapExtender<
klao@1909
   325
	StaticMap<Graph, UEdge, _Value> > Parent;
deba@1703
   326
klao@1909
   327
      UEdgeMap(const Graph& _g) 
deba@1703
   328
	: Parent(_g) {}
klao@1909
   329
      UEdgeMap(const Graph& _g, const _Value& _v) 
deba@1703
   330
	: Parent(_g, _v) {}
deba@1703
   331
klao@1909
   332
      UEdgeMap& operator=(const UEdgeMap& cmap) {
klao@1909
   333
	return operator=<UEdgeMap>(cmap);
deba@1703
   334
      }
deba@1703
   335
deba@1703
   336
      template <typename CMap>
klao@1909
   337
      UEdgeMap& operator=(const CMap& cmap) {
klao@1909
   338
	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
deba@1703
   339
	const typename Parent::Graph* graph = Parent::getGraph();
klao@1909
   340
	UEdge it;
deba@1703
   341
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1703
   342
	  Parent::set(it, cmap[it]);
deba@1703
   343
	}
deba@1703
   344
	return *this;
deba@1703
   345
      }
deba@1703
   346
    };
deba@1703
   347
deba@1828
   348
  };
deba@1703
   349
deba@1828
   350
  template <typename _Base>
deba@1910
   351
  class StaticMappableBpUGraphExtender : public _Base {
deba@1828
   352
  public:
deba@1828
   353
deba@1828
   354
    typedef _Base Parent;
deba@1910
   355
    typedef StaticMappableBpUGraphExtender Graph;
deba@1828
   356
deba@1828
   357
    typedef typename Parent::Node Node;
deba@1910
   358
    typedef typename Parent::ANode ANode;
deba@1910
   359
    typedef typename Parent::BNode BNode;
deba@1828
   360
    typedef typename Parent::Edge Edge;
klao@1909
   361
    typedef typename Parent::UEdge UEdge;
deba@1828
   362
    
deba@1828
   363
    template <typename _Value>
deba@1910
   364
    class ANodeMap 
deba@1910
   365
      : public IterableMapExtender<StaticMap<Graph, ANode, _Value> > {
deba@1828
   366
    public:
deba@1910
   367
      typedef StaticMappableBpUGraphExtender Graph;
deba@1910
   368
      typedef IterableMapExtender<StaticMap<Graph, ANode, _Value> > 
deba@1828
   369
      Parent;
deba@1828
   370
    
deba@1910
   371
      ANodeMap(const Graph& _g) 
deba@1828
   372
	: Parent(_g) {}
deba@1910
   373
      ANodeMap(const Graph& _g, const _Value& _v) 
deba@1828
   374
	: Parent(_g, _v) {}
deba@1828
   375
    
deba@1910
   376
      ANodeMap& operator=(const ANodeMap& cmap) {
deba@1910
   377
	return operator=<ANodeMap>(cmap);
deba@1828
   378
      }
deba@1828
   379
    
deba@1828
   380
deba@1828
   381
      /// \brief Template assign operator.
deba@1828
   382
      ///
deba@1828
   383
      /// The given parameter should be conform to the ReadMap
deba@1828
   384
      /// concept and could be indiced by the current item set of
deba@1910
   385
      /// the ANodeMap. In this case the value for each item
deba@1828
   386
      /// is assigned by the value of the given ReadMap. 
deba@1828
   387
      template <typename CMap>
deba@1910
   388
      ANodeMap& operator=(const CMap& cmap) {
deba@1910
   389
	checkConcept<concept::ReadMap<ANode, _Value>, CMap>();
deba@1828
   390
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1910
   391
	ANode it;
deba@1828
   392
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1828
   393
	  Parent::set(it, cmap[it]);
deba@1828
   394
	}
deba@1828
   395
	return *this;
deba@1828
   396
      }
deba@1828
   397
    
deba@1828
   398
    };
deba@1828
   399
deba@1828
   400
    template <typename _Value>
deba@1910
   401
    class BNodeMap 
deba@1910
   402
      : public IterableMapExtender<StaticMap<Graph, BNode, _Value> > {
deba@1828
   403
    public:
deba@1910
   404
      typedef StaticMappableBpUGraphExtender Graph;
deba@1910
   405
      typedef IterableMapExtender<StaticMap<Graph, BNode, _Value> > 
deba@1828
   406
      Parent;
deba@1828
   407
    
deba@1910
   408
      BNodeMap(const Graph& _g) 
deba@1828
   409
	: Parent(_g) {}
deba@1910
   410
      BNodeMap(const Graph& _g, const _Value& _v) 
deba@1828
   411
	: Parent(_g, _v) {}
deba@1828
   412
    
deba@1910
   413
      BNodeMap& operator=(const BNodeMap& cmap) {
deba@1910
   414
	return operator=<BNodeMap>(cmap);
deba@1828
   415
      }
deba@1828
   416
    
deba@1828
   417
deba@1828
   418
      /// \brief Template assign operator.
deba@1828
   419
      ///
deba@1828
   420
      /// The given parameter should be conform to the ReadMap
deba@1828
   421
      /// concept and could be indiced by the current item set of
deba@1910
   422
      /// the BNodeMap. In this case the value for each item
deba@1828
   423
      /// is assigned by the value of the given ReadMap. 
deba@1828
   424
      template <typename CMap>
deba@1910
   425
      BNodeMap& operator=(const CMap& cmap) {
deba@1910
   426
	checkConcept<concept::ReadMap<BNode, _Value>, CMap>();
deba@1828
   427
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1910
   428
	BNode it;
deba@1828
   429
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1828
   430
	  Parent::set(it, cmap[it]);
deba@1828
   431
	}
deba@1828
   432
	return *this;
deba@1828
   433
      }
deba@1828
   434
    
deba@1828
   435
    };
deba@1828
   436
deba@1828
   437
  protected:
deba@1828
   438
deba@1828
   439
    template <typename _Value>
deba@1828
   440
    class NodeMapBase : public Parent::NodeNotifier::ObserverBase {
deba@1828
   441
    public:
deba@1910
   442
      typedef StaticMappableBpUGraphExtender Graph;
deba@1828
   443
deba@1828
   444
      typedef Node Key;
deba@1828
   445
      typedef _Value Value;
deba@1828
   446
deba@1828
   447
      /// The reference type of the map;
deba@1910
   448
      typedef typename BNodeMap<_Value>::Reference Reference;
deba@1828
   449
      /// The pointer type of the map;
deba@1910
   450
      typedef typename BNodeMap<_Value>::Pointer Pointer;
deba@1828
   451
      
deba@1828
   452
      /// The const value type of the map.
deba@1828
   453
      typedef const Value ConstValue;
deba@1828
   454
      /// The const reference type of the map;
deba@1910
   455
      typedef typename BNodeMap<_Value>::ConstReference ConstReference;
deba@1828
   456
      /// The pointer type of the map;
deba@1910
   457
      typedef typename BNodeMap<_Value>::ConstPointer ConstPointer;
deba@1828
   458
deba@1828
   459
      typedef True ReferenceMapTag;
deba@1828
   460
deba@1828
   461
      NodeMapBase(const Graph& _g) 
deba@1910
   462
	: graph(&_g), bNodeMap(_g), aNodeMap(_g) {
deba@1828
   463
	Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
deba@1828
   464
      }
deba@1828
   465
      NodeMapBase(const Graph& _g, const _Value& _v) 
deba@1910
   466
	: graph(&_g), bNodeMap(_g, _v), 
deba@1910
   467
	  aNodeMap(_g, _v) {
deba@1828
   468
	Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node()));
deba@1828
   469
      }
deba@1828
   470
deba@1828
   471
      virtual ~NodeMapBase() {      
deba@1828
   472
	if (Parent::NodeNotifier::ObserverBase::attached()) {
deba@1828
   473
	  Parent::NodeNotifier::ObserverBase::detach();
deba@1828
   474
	}
deba@1828
   475
      }
deba@1828
   476
    
deba@1828
   477
      ConstReference operator[](const Key& node) const {
deba@1910
   478
	if (Parent::aNode(node)) {
deba@1910
   479
	  return aNodeMap[node];
deba@1828
   480
	} else {
deba@1910
   481
	  return bNodeMap[node];
deba@1828
   482
	}
deba@1828
   483
      } 
deba@1828
   484
deba@1828
   485
      Reference operator[](const Key& node) {
deba@1910
   486
	if (Parent::aNode(node)) {
deba@1910
   487
	  return aNodeMap[node];
deba@1828
   488
	} else {
deba@1910
   489
	  return bNodeMap[node];
deba@1828
   490
	}
deba@1828
   491
      }
deba@1828
   492
deba@1828
   493
      void set(const Key& node, const Value& value) {
deba@1910
   494
	if (Parent::aNode(node)) {
deba@1910
   495
	  aNodeMap.set(node, value);
deba@1828
   496
	} else {
deba@1910
   497
	  bNodeMap.set(node, value);
deba@1828
   498
	}
deba@1828
   499
      }
deba@1828
   500
deba@1828
   501
    protected:
deba@1828
   502
      
deba@1828
   503
      virtual void add(const Node&) {}
deba@1828
   504
      virtual void erase(const Node&) {}
deba@1828
   505
      virtual void clear() {}
deba@1828
   506
      virtual void build() {}
deba@1828
   507
deba@1828
   508
      const Graph* getGraph() const { return graph; }
deba@1828
   509
      
deba@1828
   510
    private:
deba@1828
   511
      const Graph* graph;
deba@1910
   512
      BNodeMap<_Value> bNodeMap;
deba@1910
   513
      ANodeMap<_Value> aNodeMap;
deba@1828
   514
    };
deba@1828
   515
    
deba@1828
   516
  public:
deba@1828
   517
deba@1828
   518
    template <typename _Value>
deba@1828
   519
    class NodeMap 
deba@1828
   520
      : public IterableMapExtender<NodeMapBase<_Value> > {
deba@1828
   521
    public:
deba@1910
   522
      typedef StaticMappableBpUGraphExtender Graph;
deba@1828
   523
      typedef IterableMapExtender< NodeMapBase<_Value> > Parent;
deba@1828
   524
    
deba@1828
   525
      NodeMap(const Graph& _g) 
deba@1828
   526
	: Parent(_g) {}
deba@1828
   527
      NodeMap(const Graph& _g, const _Value& _v) 
deba@1828
   528
	: Parent(_g, _v) {}
deba@1828
   529
    
deba@1828
   530
      NodeMap& operator=(const NodeMap& cmap) {
deba@1828
   531
	return operator=<NodeMap>(cmap);
deba@1828
   532
      }
deba@1828
   533
    
deba@1828
   534
deba@1828
   535
      /// \brief Template assign operator.
deba@1828
   536
      ///
deba@1828
   537
      /// The given parameter should be conform to the ReadMap
deba@1828
   538
      /// concept and could be indiced by the current item set of
deba@1828
   539
      /// the NodeMap. In this case the value for each item
deba@1828
   540
      /// is assigned by the value of the given ReadMap. 
deba@1828
   541
      template <typename CMap>
deba@1828
   542
      NodeMap& operator=(const CMap& cmap) {
deba@1828
   543
	checkConcept<concept::ReadMap<Node, _Value>, CMap>();
deba@1828
   544
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1828
   545
	Node it;
deba@1828
   546
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1828
   547
	  Parent::set(it, cmap[it]);
deba@1828
   548
	}
deba@1828
   549
	return *this;
deba@1828
   550
      }
deba@1828
   551
    
deba@1828
   552
    };
deba@1828
   553
deba@1828
   554
deba@1828
   555
deba@1828
   556
    template <typename _Value>
deba@1828
   557
    class EdgeMap 
deba@1828
   558
      : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > {
deba@1828
   559
    public:
deba@1910
   560
      typedef StaticMappableBpUGraphExtender Graph;
deba@1828
   561
      typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent;
deba@1828
   562
    
deba@1828
   563
      EdgeMap(const Graph& _g) 
deba@1828
   564
	: Parent(_g) {}
deba@1828
   565
      EdgeMap(const Graph& _g, const _Value& _v) 
deba@1828
   566
	: Parent(_g, _v) {}
deba@1828
   567
    
deba@1828
   568
      EdgeMap& operator=(const EdgeMap& cmap) {
deba@1828
   569
	return operator=<EdgeMap>(cmap);
deba@1828
   570
      }
deba@1828
   571
    
deba@1828
   572
      template <typename CMap>
deba@1828
   573
      EdgeMap& operator=(const CMap& cmap) {
deba@1828
   574
	checkConcept<concept::ReadMap<Edge, _Value>, CMap>();
deba@1828
   575
	const typename Parent::Graph* graph = Parent::getGraph();
deba@1828
   576
	Edge it;
deba@1828
   577
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1828
   578
	  Parent::set(it, cmap[it]);
deba@1828
   579
	}
deba@1828
   580
	return *this;
deba@1828
   581
      }
deba@1828
   582
    };
deba@1828
   583
deba@1828
   584
    template <typename _Value>
klao@1909
   585
    class UEdgeMap 
klao@1909
   586
      : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > {
deba@1828
   587
    public:
deba@1910
   588
      typedef StaticMappableBpUGraphExtender Graph;
klao@1909
   589
      typedef IterableMapExtender<StaticMap<Graph, UEdge, _Value> > 
deba@1828
   590
      Parent;
deba@1828
   591
    
klao@1909
   592
      UEdgeMap(const Graph& _g) 
deba@1828
   593
	: Parent(_g) {}
klao@1909
   594
      UEdgeMap(const Graph& _g, const _Value& _v) 
deba@1828
   595
	: Parent(_g, _v) {}
deba@1828
   596
    
klao@1909
   597
      UEdgeMap& operator=(const UEdgeMap& cmap) {
klao@1909
   598
	return operator=<UEdgeMap>(cmap);
deba@1828
   599
      }
deba@1828
   600
    
deba@1828
   601
      template <typename CMap>
klao@1909
   602
      UEdgeMap& operator=(const CMap& cmap) {
klao@1909
   603
	checkConcept<concept::ReadMap<UEdge, _Value>, CMap>();
deba@1828
   604
	const typename Parent::Graph* graph = Parent::getGraph();
klao@1909
   605
	UEdge it;
deba@1828
   606
	for (graph->first(it); it != INVALID; graph->next(it)) {
deba@1828
   607
	  Parent::set(it, cmap[it]);
deba@1828
   608
	}
deba@1828
   609
	return *this;
deba@1828
   610
      }
deba@1828
   611
    };
deba@1828
   612
  
deba@1703
   613
  };
deba@1703
   614
deba@1703
   615
}
deba@1703
   616
deba@1703
   617
#endif