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