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