lemon/matrix_maps.h
author deba
Mon, 15 May 2006 16:21:50 +0000
changeset 2085 1970a93dfaa8
parent 2072 224d3781b00b
child 2088 68f8d17ced51
permissions -rw-r--r--
Bug fix by Jano
deba@1720
     1
/* -*- C++ -*-
deba@1720
     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
deba@1720
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@1720
     8
 *
deba@1720
     9
 * Permission to use, modify and distribute this software is granted
deba@1720
    10
 * provided that this copyright notice appears in all copies. For
deba@1720
    11
 * precise terms see the accompanying LICENSE file.
deba@1720
    12
 *
deba@1720
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@1720
    14
 * express or implied, and with no claim as to its suitability for any
deba@1720
    15
 * purpose.
deba@1720
    16
 *
deba@1720
    17
 */
deba@1720
    18
deba@1720
    19
#ifndef LEMON_MATRIX_MAPS_H
deba@1720
    20
#define LEMON_MATRIX_MAPS_H
deba@1720
    21
deba@1720
    22
deba@1720
    23
#include <vector>
deba@1993
    24
#include <lemon/bits/utility.h>
deba@1720
    25
#include <lemon/maps.h>
deba@1720
    26
deba@2039
    27
#include <lemon/concept/matrix_maps.h>
deba@1720
    28
deba@1720
    29
/// \file
alpar@2072
    30
/// \ingroup matrices
deba@1720
    31
/// \brief Maps indexed with pairs of items.
deba@1720
    32
///
deba@1720
    33
/// \todo This file has the same name as the concept file in concept/,
deba@1720
    34
///  and this is not easily detectable in docs...
deba@1720
    35
namespace lemon {
deba@1720
    36
deba@1720
    37
  /// \brief Map for the coloumn view of the matrix
deba@1720
    38
  ///
alpar@2072
    39
  /// \ingroup matrices
deba@1720
    40
  /// Map for the coloumn view of the matrix.
alpar@2072
    41
  ///
deba@1720
    42
  template <typename _MatrixMap>
deba@2039
    43
  class MatrixRowMap : public MatrixMapTraits<_MatrixMap> {
deba@1720
    44
  public:
deba@1720
    45
    typedef _MatrixMap MatrixMap;
deba@1720
    46
    typedef typename MatrixMap::SecondKey Key;
deba@1720
    47
    typedef typename MatrixMap::Value Value;
deba@1720
    48
deba@1720
    49
deba@2084
    50
    /// \brief Constructor of the row map
deba@2084
    51
    ///
deba@2084
    52
    /// Constructor of the row map.
deba@1751
    53
    MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row) 
deba@1720
    54
      : matrix(_matrix), row(_row) {}
deba@1720
    55
deba@1720
    56
    /// \brief Subscription operator
deba@1720
    57
    ///
deba@1720
    58
    /// Subscription operator.
deba@2039
    59
    typename MatrixMapTraits<MatrixMap>::ReturnValue
deba@1720
    60
    operator[](Key col) {
deba@1751
    61
      return matrix(row, col);
deba@1720
    62
    }
deba@1720
    63
deba@1720
    64
    /// \brief Setter function
deba@1720
    65
    ///
deba@1720
    66
    /// Setter function.
deba@1720
    67
    void set(Key col, const Value& val) {
deba@1751
    68
      matrix.set(row, col, val);
deba@1720
    69
    }
deba@1720
    70
      
deba@1720
    71
    /// \brief Subscription operator
deba@1720
    72
    ///
deba@1720
    73
    /// Subscription operator.
deba@2039
    74
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1720
    75
    operator[](Key col) const {
deba@1751
    76
      return matrix(row, col);
deba@1720
    77
    }
deba@1720
    78
deba@1720
    79
  private:
deba@1720
    80
    MatrixMap& matrix;
deba@1751
    81
    typename MatrixMap::FirstKey row;
deba@1720
    82
  };
deba@1720
    83
deba@1720
    84
  /// \brief Map for the row view of the matrix
deba@1720
    85
  ///
alpar@2072
    86
  /// \ingroup matrices
deba@1720
    87
  /// Map for the row view of the matrix.
alpar@2072
    88
  ///
deba@1720
    89
  template <typename _MatrixMap>
deba@2039
    90
  class ConstMatrixRowMap : public MatrixMapTraits<_MatrixMap> {
deba@1720
    91
  public:
deba@1720
    92
    typedef _MatrixMap MatrixMap;
deba@1751
    93
    typedef typename MatrixMap::SecondKey Key;
deba@1720
    94
    typedef typename MatrixMap::Value Value;
deba@1720
    95
deba@1751
    96
deba@2084
    97
    /// \brief Constructor of the row map
deba@2084
    98
    ///
deba@2084
    99
    /// Constructor of the row map.
deba@1720
   100
    ConstMatrixRowMap(const MatrixMap& _matrix, 
deba@1751
   101
		      typename MatrixMap::FirstKey _row) 
deba@1720
   102
      : matrix(_matrix), row(_row) {}
deba@1720
   103
deba@1720
   104
    /// \brief Subscription operator
deba@1720
   105
    ///
deba@1720
   106
    /// Subscription operator.
deba@2039
   107
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1720
   108
    operator[](Key col) const {
deba@1751
   109
      return matrix(row, col);
deba@1720
   110
    }
deba@1720
   111
deba@1720
   112
  private:
deba@1720
   113
    const MatrixMap& matrix;
deba@1751
   114
    typename MatrixMap::FirstKey row;
deba@1720
   115
  };
deba@1720
   116
deba@2084
   117
  /// \ingroup matrices
deba@2084
   118
  ///
deba@1720
   119
  /// \brief Gives back a row view of the matrix map
deba@1720
   120
  ///
deba@1720
   121
  /// Gives back a row view of the matrix map.
alpar@2072
   122
  ///
deba@2084
   123
  /// \sa MatrixRowMap
deba@2084
   124
  /// \sa ConstMatrixRowMap
deba@1720
   125
  template <typename MatrixMap>
deba@1720
   126
  MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
deba@1751
   127
				       typename MatrixMap::FirstKey row) {
deba@1720
   128
    return MatrixRowMap<MatrixMap>(matrixMap, row);
deba@1720
   129
  }
deba@1720
   130
deba@1720
   131
  template <typename MatrixMap>
deba@1751
   132
  ConstMatrixRowMap<MatrixMap>
deba@1751
   133
  matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
deba@1720
   134
    return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
deba@1720
   135
  }
deba@1720
   136
alpar@2072
   137
  /// \brief Map for the column view of the matrix
deba@1751
   138
  ///
alpar@2072
   139
  /// \ingroup matrices
alpar@2072
   140
  /// Map for the column view of the matrix.
alpar@2072
   141
  ///
deba@1751
   142
  template <typename _MatrixMap>
deba@2039
   143
  class MatrixColMap : public MatrixMapTraits<_MatrixMap> {
deba@1751
   144
  public:
deba@1751
   145
    typedef _MatrixMap MatrixMap;
deba@1751
   146
    typedef typename MatrixMap::FirstKey Key;
deba@1751
   147
    typedef typename MatrixMap::Value Value;
deba@1751
   148
deba@2084
   149
    /// \brief Constructor of the column map
deba@2084
   150
    ///
deba@2084
   151
    /// Constructor of the column map.
deba@1751
   152
    MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col) 
deba@1751
   153
      : matrix(_matrix), col(_col) {}
deba@1751
   154
deba@1751
   155
    /// \brief Subscription operator
deba@1751
   156
    ///
deba@1751
   157
    /// Subscription operator.
deba@2039
   158
    typename MatrixMapTraits<MatrixMap>::ReturnValue
deba@1751
   159
    operator[](Key row) {
deba@1751
   160
      return matrix(row, col);
deba@1751
   161
    }
deba@1751
   162
deba@1751
   163
    /// \brief Setter function
deba@1751
   164
    ///
deba@1751
   165
    /// Setter function.
deba@1751
   166
    void set(Key row, const Value& val) {
deba@1751
   167
      matrix.set(row, col, val);
deba@1751
   168
    }
deba@1751
   169
      
deba@1751
   170
    /// \brief Subscription operator
deba@1751
   171
    ///
deba@1751
   172
    /// Subscription operator.
deba@2039
   173
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1751
   174
    operator[](Key row) const {
deba@1751
   175
      return matrix(row, col);
deba@1751
   176
    }
deba@1751
   177
deba@1751
   178
  private:
deba@1751
   179
    MatrixMap& matrix;
deba@1751
   180
    typename MatrixMap::SecondKey col;
deba@1751
   181
  };
deba@1751
   182
alpar@2072
   183
  /// \brief Map for the column view of the matrix
deba@1751
   184
  ///
alpar@2072
   185
  /// \ingroup matrices
alpar@2072
   186
  /// Map for the column view of the matrix.
alpar@2072
   187
  ///
deba@1751
   188
  template <typename _MatrixMap>
deba@2039
   189
  class ConstMatrixColMap : public MatrixMapTraits<_MatrixMap> {
deba@1751
   190
  public:
deba@1751
   191
    typedef _MatrixMap MatrixMap;
deba@1751
   192
    typedef typename MatrixMap::FirstKey Key;
deba@1751
   193
    typedef typename MatrixMap::Value Value;
deba@1751
   194
deba@2084
   195
    /// \brief Constructor of the column map
deba@2084
   196
    ///
deba@2084
   197
    /// Constructor of the column map.
deba@1751
   198
    ConstMatrixColMap(const MatrixMap& _matrix, 
deba@1751
   199
		      typename MatrixMap::SecondKey _col) 
deba@1751
   200
      : matrix(_matrix), col(_col) {}
deba@1751
   201
deba@1751
   202
    /// \brief Subscription operator
deba@1751
   203
    ///
deba@1751
   204
    /// Subscription operator.
deba@2039
   205
    typename MatrixMapTraits<MatrixMap>::ConstReturnValue
deba@1751
   206
    operator[](Key row) const {
deba@1751
   207
      return matrix(row, col);
deba@1751
   208
    }
deba@1751
   209
deba@1751
   210
  private:
deba@1751
   211
    const MatrixMap& matrix;
deba@1751
   212
    typename MatrixMap::SecondKey col;
deba@1751
   213
  };
deba@1751
   214
deba@2084
   215
  /// \ingroup matrices
deba@2084
   216
  ///
alpar@2072
   217
  /// \brief Gives back a column view of the matrix map
deba@1751
   218
  ///
alpar@2072
   219
  /// Gives back a column view of the matrix map.
alpar@2072
   220
  ///
deba@2084
   221
  /// \sa MatrixColMap
deba@2084
   222
  /// \sa ConstMatrixColMap
deba@1751
   223
  template <typename MatrixMap>
deba@1751
   224
  MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
deba@1751
   225
				       typename MatrixMap::SecondKey col) {
deba@1751
   226
    return MatrixColMap<MatrixMap>(matrixMap, col);
deba@1751
   227
  }
deba@1751
   228
deba@1751
   229
  template <typename MatrixMap>
deba@1751
   230
  ConstMatrixColMap<MatrixMap> 
deba@1751
   231
  matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
deba@1751
   232
    return ConstMatrixColMap<MatrixMap>(matrixMap, col);
deba@1751
   233
  }
deba@1751
   234
deba@1720
   235
  /// \brief Container for store values for each ordered pair of graph items
deba@1720
   236
  ///
alpar@2072
   237
  /// \ingroup matrices
alpar@1757
   238
  /// This data structure can strore for each pair of the same item
deba@1720
   239
  /// type a value. It increase the size of the container when the 
deba@1720
   240
  /// associated graph modified, so it updated automaticly whenever
deba@1720
   241
  /// it is needed.
deba@1720
   242
  template <typename _Graph, typename _Item, typename _Value>
deba@1720
   243
  class DynamicMatrixMap 
deba@1999
   244
    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
deba@1720
   245
  public:
deba@1999
   246
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase 
deba@1999
   247
    Parent;
deba@1720
   248
deba@1720
   249
    typedef _Graph Graph;
deba@1720
   250
    typedef _Item Key;
deba@1720
   251
deba@1720
   252
    typedef _Item FirstKey;
deba@1720
   253
    typedef _Item SecondKey;
deba@1720
   254
    typedef _Value Value;
deba@1720
   255
deba@1720
   256
    typedef True ReferenceMapTag;
deba@1720
   257
deba@1720
   258
  private:
deba@1720
   259
		
deba@1720
   260
    typedef std::vector<Value> Container;
deba@1720
   261
deba@1720
   262
  public:
deba@1720
   263
deba@1720
   264
    typedef typename Container::reference Reference;
deba@1720
   265
    typedef typename Container::const_reference ConstReference;
deba@1720
   266
deba@1720
   267
    /// \brief Creates an item matrix for the given graph
deba@1720
   268
    ///
deba@1720
   269
    /// Creates an item matrix for the given graph.
deba@1720
   270
    DynamicMatrixMap(const Graph& _graph) 
deba@1999
   271
      : values(size(_graph.maxId(Key()) + 1)) {
deba@1999
   272
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   273
    }
deba@1720
   274
deba@1720
   275
    /// \brief Creates an item matrix for the given graph
deba@1720
   276
    ///
deba@1720
   277
    /// Creates an item matrix for the given graph and assigns for each
deba@1720
   278
    /// pairs of keys the given parameter.
deba@1720
   279
    DynamicMatrixMap(const Graph& _graph, const Value& _val) 
deba@1999
   280
      : values(size(_graph.maxId(Key()) + 1), _val) {
deba@1999
   281
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   282
    }
deba@1720
   283
deba@2039
   284
    ///\brief The assignement operator.
deba@2039
   285
    ///
deba@2039
   286
    ///It allow to assign a map to an other.
deba@2039
   287
    DynamicMatrixMap& operator=(const DynamicMatrixMap& _cmap){
deba@2039
   288
      return operator=<DynamicMatrixMap>(_cmap);
deba@2039
   289
    }
deba@2039
   290
      
deba@2039
   291
    ///\brief Template assignement operator.
deba@2039
   292
    ///
deba@2039
   293
    ///It copy the element of the given map to its own container.  The
deba@2039
   294
    ///type of the two map shall be the same.
deba@2039
   295
    template <typename CMap>
deba@2039
   296
    DynamicMatrixMap& operator=(const CMap& _cmap){
deba@2039
   297
      checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   298
      typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2039
   299
      Key first, second;
deba@2039
   300
      for(notifier->first(first); first != INVALID; 
deba@2039
   301
          notifier->next(first)){
deba@2039
   302
        for(notifier->first(second); second != INVALID; 
deba@2039
   303
            notifier->next(second)){
deba@2039
   304
          set(first, second, _cmap(first, second));
deba@2039
   305
        }
deba@2039
   306
      }
deba@2039
   307
      return *this;
deba@2039
   308
    }
deba@2039
   309
deba@1720
   310
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   311
    /// ordered pair.
deba@1720
   312
    ///
deba@1720
   313
    /// Gives back the value assigned to the \c first - \c second ordered pair.
deba@1720
   314
    ConstReference operator()(const Key& first, const Key& second) const {
deba@1999
   315
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   316
                          Parent::getNotifier()->id(second))];
deba@1720
   317
    }
deba@1720
   318
    
deba@1720
   319
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   320
    /// ordered pair.
deba@1720
   321
    ///
deba@1720
   322
    /// Gives back the value assigned to the \c first - \c second ordered pair.
deba@1720
   323
    Reference operator()(const Key& first, const Key& second) {
deba@1999
   324
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   325
                          Parent::getNotifier()->id(second))];
deba@1720
   326
    }
deba@1720
   327
deba@1720
   328
    /// \brief Setter function for the matrix map.
deba@1720
   329
    ///
deba@1720
   330
    /// Setter function for the matrix map.
deba@1720
   331
    void set(const Key& first, const Key& second, const Value& val) {
deba@1999
   332
      values[index(Parent::getNotifier()->id(first), 
deba@1999
   333
                   Parent::getNotifier()->id(second))] = val;
deba@1720
   334
    }
deba@1720
   335
deba@1720
   336
  protected:
deba@1720
   337
deba@1720
   338
    static int index(int i, int j) {
deba@1720
   339
      if (i < j) {
deba@1720
   340
	return j * j + i;
deba@1720
   341
      } else {
deba@1720
   342
	return i * i + i + j;
deba@1720
   343
      }
deba@1720
   344
    }
deba@1720
   345
deba@1720
   346
    static int size(int s) {
deba@1720
   347
      return s * s;
deba@1720
   348
    }
deba@1720
   349
deba@1720
   350
    virtual void add(const Key& key) {
deba@1999
   351
      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
deba@1999
   352
	values.resize(size(Parent::getNotifier()->id(key) + 1));	
deba@1720
   353
      }
deba@1720
   354
    }
deba@1720
   355
deba@1720
   356
    virtual void erase(const Key&) {}
deba@1720
   357
deba@1720
   358
    virtual void build() {
deba@1999
   359
      values.resize(size(Parent::getNotifier()->maxId() + 1));
deba@1720
   360
    }
deba@1720
   361
deba@1720
   362
    virtual void clear() {
deba@1720
   363
      values.clear();
deba@1720
   364
    }   
deba@1720
   365
    
deba@1720
   366
  private:
deba@1720
   367
    std::vector<Value> values;
deba@1720
   368
  };
deba@1720
   369
deba@1720
   370
  /// \brief Container for store values for each unordered pair of graph items
deba@1720
   371
  ///
alpar@2072
   372
  /// \ingroup matrices
alpar@1757
   373
  /// This data structure can strore for each pair of the same item
deba@1720
   374
  /// type a value. It increase the size of the container when the 
deba@1720
   375
  /// associated graph modified, so it updated automaticly whenever
deba@1720
   376
  /// it is needed. 
deba@1720
   377
  template <typename _Graph, typename _Item, typename _Value>
deba@1720
   378
  class DynamicSymMatrixMap 
deba@1999
   379
    : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
deba@1720
   380
  public:
deba@1999
   381
    typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase 
deba@1999
   382
    Parent;
deba@1720
   383
deba@1720
   384
    typedef _Graph Graph;
deba@1720
   385
    typedef _Item Key;
deba@1720
   386
deba@1720
   387
    typedef _Item FirstKey;
deba@1720
   388
    typedef _Item SecondKey;
deba@1720
   389
    typedef _Value Value;
deba@1720
   390
deba@1720
   391
    typedef True ReferenceMapTag;
deba@1720
   392
deba@1720
   393
  private:
deba@1720
   394
		
deba@1720
   395
    typedef std::vector<Value> Container;
deba@1720
   396
deba@1720
   397
  public:
deba@1720
   398
deba@1720
   399
    typedef typename Container::reference Reference;
deba@1720
   400
    typedef typename Container::const_reference ConstReference;
deba@1720
   401
deba@1720
   402
    /// \brief Creates an item matrix for the given graph
deba@1720
   403
    ///
deba@1720
   404
    /// Creates an item matrix for the given graph.
deba@1720
   405
    DynamicSymMatrixMap(const Graph& _graph) 
deba@1999
   406
      : values(size(_graph.maxId(Key()) + 1)) {
deba@1999
   407
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   408
    }
deba@1720
   409
deba@1720
   410
    /// \brief Creates an item matrix for the given graph
deba@1720
   411
    ///
deba@1720
   412
    /// Creates an item matrix for the given graph and assigns for each
deba@1720
   413
    /// pairs of keys the given parameter.
deba@1720
   414
    DynamicSymMatrixMap(const Graph& _graph, const Value& _val) 
deba@1999
   415
      : values(size(_graph.maxId(Key()) + 1), _val) {
deba@1999
   416
      Parent::attach(_graph.getNotifier(Key()));
deba@1720
   417
    }
deba@1720
   418
deba@2039
   419
deba@2039
   420
    ///\brief The assignement operator.
deba@2039
   421
    ///
deba@2039
   422
    ///It allow to assign a map to an other.
alpar@2072
   423
    ///
deba@2039
   424
    DynamicSymMatrixMap& operator=(const DynamicSymMatrixMap& _cmap){
deba@2039
   425
      return operator=<DynamicSymMatrixMap>(_cmap);
deba@2039
   426
    }
deba@2039
   427
      
deba@2039
   428
    ///\brief Template assignement operator.
deba@2039
   429
    ///
deba@2039
   430
    ///It copy the element of the given map to its own container.  The
deba@2039
   431
    ///type of the two map shall be the same.
deba@2039
   432
    template <typename CMap>
deba@2039
   433
    DynamicSymMatrixMap& operator=(const CMap& _cmap){
deba@2039
   434
      checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   435
      typename Parent::Notifier* notifier = Parent::getNotifier();
deba@2039
   436
      Key first, second;
deba@2039
   437
      for(notifier->first(first); first != INVALID; 
deba@2039
   438
          notifier->next(first)){
deba@2039
   439
        for(notifier->first(second); second != first; 
deba@2039
   440
            notifier->next(second)){
deba@2039
   441
          set(first, second, _cmap(first, second));
deba@2039
   442
        }
deba@2039
   443
        set(first, first, _cmap(first, first));        
deba@2039
   444
      }
deba@2039
   445
      return *this;
deba@2039
   446
    }
deba@2039
   447
deba@1720
   448
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   449
    /// unordered pair.
deba@1720
   450
    ///
deba@1720
   451
    /// Gives back the value assigned to the \c first - \c second unordered 
deba@1720
   452
    /// pair.
deba@1720
   453
    ConstReference operator()(const Key& first, const Key& second) const {
deba@1999
   454
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   455
                          Parent::getNotifier()->id(second))];
deba@1720
   456
    }
deba@1720
   457
    
deba@1720
   458
    /// \brief Gives back the value assigned to the \c first - \c second
deba@1720
   459
    /// unordered pair.
deba@1720
   460
    ///
deba@1720
   461
    /// Gives back the value assigned to the \c first - \c second unordered 
deba@1720
   462
    /// pair.
deba@1720
   463
    Reference operator()(const Key& first, const Key& second) {
deba@1999
   464
      return values[index(Parent::getNotifier()->id(first), 
deba@1999
   465
                          Parent::getNotifier()->id(second))];
deba@1720
   466
    }
deba@1720
   467
deba@1720
   468
    /// \brief Setter function for the matrix map.
deba@1720
   469
    ///
deba@1720
   470
    /// Setter function for the matrix map.
alpar@2072
   471
    ///
deba@1720
   472
    void set(const Key& first, const Key& second, const Value& val) {
deba@1999
   473
      values[index(Parent::getNotifier()->id(first), 
deba@1999
   474
                   Parent::getNotifier()->id(second))] = val;
deba@1720
   475
    }
deba@1720
   476
deba@1720
   477
  protected:
deba@1720
   478
deba@1720
   479
    static int index(int i, int j) {
deba@1720
   480
      if (i < j) {
deba@1720
   481
	return j * (j + 1) / 2 + i;
deba@1720
   482
      } else {
deba@1720
   483
	return i * (i + 1) / 2 + j;
deba@1720
   484
      }
deba@1720
   485
    }
deba@1720
   486
deba@1720
   487
    static int size(int s) {
deba@1720
   488
      return s * (s + 1) / 2;
deba@1720
   489
    }
deba@1720
   490
deba@1720
   491
    virtual void add(const Key& key) {
deba@1999
   492
      if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
deba@1999
   493
	values.resize(size(Parent::getNotifier()->id(key) + 1));	
deba@1720
   494
      }
deba@1720
   495
    }
deba@1720
   496
deba@1720
   497
    virtual void erase(const Key&) {}
deba@1720
   498
deba@1720
   499
    virtual void build() {
deba@1999
   500
      values.resize(size(Parent::getNotifier()->maxId() + 1));
deba@1720
   501
    }
deba@1720
   502
deba@1720
   503
    virtual void clear() {
deba@1720
   504
      values.clear();
deba@1720
   505
    }   
deba@1720
   506
    
deba@1720
   507
  private:
deba@1720
   508
    std::vector<Value> values;
deba@1720
   509
  };
deba@2039
   510
  
deba@2039
   511
  ///\brief Dynamic Asymmetric Matrix Map.
deba@2039
   512
  ///
alpar@2072
   513
  ///\ingroup matrices
deba@2039
   514
  ///Dynamic Asymmetric Matrix Map.  Container for store values for each
deba@2039
   515
  ///ordered pair of containers items.  This data structure can store
deba@2039
   516
  ///data with different key types from different container types. It
deba@2039
   517
  ///increases the size of the container if the linked containers
deba@2039
   518
  ///content change, so it is updated automaticly whenever it is
deba@2039
   519
  ///needed.
deba@2039
   520
  ///
deba@2039
   521
  ///This map meet with the concept::ReferenceMatrixMap<typename K1,
deba@2039
   522
  ///typename K2, typename V, typename R, typename CR> called as
deba@2039
   523
  ///"ReferenceMatrixMap".
deba@2039
   524
  ///
deba@2039
   525
  ///\param _FirstContainer the desired type of first container. It is
deba@2039
   526
  ///ususally a Graph type, but can be any type with alteration
deba@2039
   527
  ///property.
deba@2039
   528
  ///  
deba@2039
   529
  ///\param _FirstContainerItem the nested type of the
deba@2039
   530
  ///FirstContainer. It is usually a graph item as Node, Edge,
deba@2039
   531
  ///etc. This type will be the FirstKey type.
deba@2039
   532
  ///
deba@2039
   533
  ///\param _SecondContainer the desired type of the second
deba@2039
   534
  ///container. It is usualy a Graph type, but can be any type with
deba@2039
   535
  ///alteration property.
deba@2039
   536
  ///
deba@2039
   537
  ///\param _SecondContainerItem the nested type of the
deba@2039
   538
  ///SecondContainer. It is usually a graph item such as Node, Edge,
deba@2039
   539
  ///UEdge, etc. This type will be the SecondKey type.
deba@2039
   540
  ///
deba@2039
   541
  ///\param _Value the type of the strored values in the container.
deba@2039
   542
  ///
deba@2039
   543
  /// \author Janos Nagy
deba@2039
   544
  template <typename _FirstContainer, typename _FirstContainerItem, 
deba@2039
   545
            typename _SecondContainer, typename _SecondContainerItem, 
deba@2039
   546
            typename _Value>
deba@2039
   547
  class DynamicAsymMatrixMap{
deba@2039
   548
  public:
deba@2039
   549
deba@2039
   550
    ///The first key type.
deba@2039
   551
    typedef _FirstContainerItem FirstKey;
deba@2039
   552
      
deba@2039
   553
    ///The second key type.
deba@2039
   554
    typedef _SecondContainerItem SecondKey;
deba@2039
   555
      
deba@2039
   556
    ///The value type of the map.
deba@2039
   557
    typedef _Value Value;
deba@2039
   558
      
deba@2039
   559
    ///Indicates it is a reference map.
deba@2039
   560
    typedef True ReferenceMapTag;
deba@2039
   561
    
deba@2039
   562
  protected:
deba@2039
   563
      
deba@2039
   564
    ///\brief Proxy class for the first key type.
deba@2039
   565
    ///
deba@2039
   566
    ///The proxy class belongs to the FirstKey type. It is necessary because
deba@2039
   567
    ///if one want use the same conatainer types and same nested types but on
deba@2039
   568
    ///other instances of containers than due to the type equiality of nested
deba@2039
   569
    ///types it requires a proxy mechanism. 
deba@2039
   570
    class FirstKeyProxy 
deba@2039
   571
      : protected 
deba@2039
   572
    ItemSetTraits<_FirstContainer,_FirstContainerItem>::
deba@2039
   573
    ItemNotifier::ObserverBase 
deba@2039
   574
    {
deba@2039
   575
        
deba@2039
   576
    public:
deba@2039
   577
deba@2039
   578
      friend class DynamicAsymMatrixMap;
deba@2039
   579
          
deba@2039
   580
      ///Constructor.
deba@2039
   581
      FirstKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
deba@2039
   582
    protected:
deba@2039
   583
deba@2039
   584
      ///\brief Add a new FirstKey to the map.
deba@2039
   585
      ///
deba@2039
   586
      ///It adds a new FirstKey to the map. It is called by the
deba@2039
   587
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   588
      ///member function in the observer base. It will call the
deba@2039
   589
      ///maps addFirstKey() function.
deba@2039
   590
      virtual void add(const FirstKey& _firstKey){
deba@2039
   591
        _owner.addFirstKey(_firstKey);
deba@2039
   592
      }
deba@2039
   593
          
deba@2039
   594
      ///\brief Add more new FirstKey to the map.
deba@2039
   595
      ///
deba@2039
   596
      ///It adds more new FirstKey to the map. It is called by the
deba@2039
   597
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   598
      ///member function in the observer base. It will call the
deba@2039
   599
      ///map's addFirstKeys() function.
deba@2039
   600
      virtual void add(const std::vector<FirstKey>& _firstKeys){
deba@2039
   601
        _owner.addFirstKeys(_firstKeys);
deba@2039
   602
      }
deba@2039
   603
          
deba@2039
   604
      ///\brief Erase a FirstKey from the map.
deba@2039
   605
      ///
deba@2039
   606
      ///Erase a FirstKey from the map. It called by the observer
deba@2039
   607
      ///notifier and it overrides the erase() virtual member
deba@2039
   608
      ///function of the observer base. It will call the map's
deba@2039
   609
      ///eraseFirstKey() function.
deba@2039
   610
      virtual void erase(const FirstKey& _firstKey){
deba@2039
   611
        _owner.eraseFirstKey(_firstKey);
deba@2039
   612
      }
deba@2039
   613
          
deba@2039
   614
      ///\brief Erase more FirstKey from the map.
deba@2039
   615
      ///
deba@2039
   616
      ///Erase more FirstKey from the map. It called by the
deba@2039
   617
      ///observer notifier and it overrides the erase() virtual
deba@2039
   618
      ///member function of the observer base. It will call the
deba@2039
   619
      ///map's eraseFirstKeys() function.
deba@2039
   620
      virtual void erase(const std::vector<FirstKey>& _firstKeys){
deba@2039
   621
        _owner.eraseFirstKeys(_firstKeys);
deba@2039
   622
      }
deba@2039
   623
          
deba@2039
   624
      ///\brief Builds the map.
deba@2039
   625
      ///
deba@2039
   626
      ///It buildes the map. It called by the observer notifier
deba@2039
   627
      ///and it overrides the build() virtual member function of
deba@2039
   628
      ///the observer base.  It will call the map's build()
deba@2039
   629
      ///function.
deba@2039
   630
      virtual void build() {
deba@2039
   631
        _owner.build();
deba@2039
   632
        //_owner.buildFirst();
deba@2039
   633
      }
deba@2039
   634
          
deba@2039
   635
      ///\brief Clear the map.
deba@2039
   636
      ///
deba@2039
   637
      ///It erases all items from the map. It called by the
deba@2039
   638
      ///observer notifier and it overrides the clear() virtual
deba@2039
   639
      ///memeber function of the observer base. It will call the
deba@2039
   640
      ///map's clear() function.
deba@2039
   641
      virtual void clear() {
deba@2039
   642
        _owner.clear();
deba@2039
   643
        //_owner.clearFirst();
deba@2039
   644
      }
deba@2039
   645
    private:
deba@2039
   646
          
deba@2039
   647
      ///The map type for it is linked.
deba@2039
   648
      DynamicAsymMatrixMap& _owner;
alpar@2072
   649
    };//END OF FIRSTKEYPROXY
deba@2039
   650
      
deba@2039
   651
      ///\brief Proxy class for the second key type.
deba@2039
   652
      ///
ladanyi@2047
   653
      ///The proxy class belongs to the SecondKey type. It is
deba@2039
   654
      ///necessary because if one want use the same conatainer types
deba@2039
   655
      ///and same nested types but on other instances of containers
deba@2039
   656
      ///than due to the type equiality of nested types it requires a
deba@2039
   657
      ///proxy mechanism.
deba@2039
   658
    class SecondKeyProxy
deba@2039
   659
      : protected 
deba@2039
   660
    ItemSetTraits<_SecondContainer, _SecondContainerItem>::
deba@2039
   661
    ItemNotifier::ObserverBase {
deba@2039
   662
        
deba@2039
   663
    public:
deba@2039
   664
deba@2039
   665
      friend class DynamicAsymMatrixMap;
deba@2039
   666
      ///Constructor.
deba@2039
   667
      SecondKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
deba@2039
   668
deba@2039
   669
    protected:
deba@2039
   670
          
deba@2039
   671
      ///\brief Add a new SecondKey to the map.
deba@2039
   672
      ///
deba@2039
   673
      ///It adds a new SecondKey to the map. It is called by the
deba@2039
   674
      ///observer notifier and it is ovverride the add() virtual
deba@2039
   675
      ///member function in the observer base. It will call the
deba@2039
   676
      ///maps addSecondKey() function.
deba@2039
   677
      virtual void add(const SecondKey& _secondKey){
deba@2039
   678
        _owner.addSecondKey(_secondKey);
deba@2039
   679
      }
deba@2039
   680
    
deba@2039
   681
      ///\brief Add more new SecondKey to the map.
deba@2039
   682
      ///
deba@2039
   683
      ///It adds more new SecondKey to the map. It is called by
deba@2039
   684
      ///the observer notifier and it is ovverride the add()
deba@2039
   685
      ///virtual member function in the observer base. It will
deba@2039
   686
      ///call the maps addSecondKeys() function.
deba@2039
   687
      virtual void add(const std::vector<SecondKey>& _secondKeys){
deba@2039
   688
        _owner.addSecondKeys(_secondKeys);
deba@2039
   689
      }
deba@2039
   690
          
deba@2039
   691
      ///\brief Erase a SecondKey from the map.
deba@2039
   692
      ///
deba@2039
   693
      ///Erase a SecondKey from the map. It called by the observer
deba@2039
   694
      ///notifier and it overrides the erase() virtual member
deba@2039
   695
      ///function of the observer base. It will call the map's
deba@2039
   696
      ///eraseSecondKey() function.
deba@2039
   697
      virtual void erase(const SecondKey& _secondKey){
deba@2039
   698
        _owner.eraseSecondKey(_secondKey);
deba@2039
   699
      }
deba@2039
   700
          
deba@2039
   701
      ///\brief Erase more SecondKeys from the map.
deba@2039
   702
      ///
deba@2039
   703
      ///Erase more SecondKey from the map. It called by the
deba@2039
   704
      ///observer notifier and it overrides the erase() virtual
deba@2039
   705
      ///member function of the observer base. It will call the
deba@2039
   706
      ///map's eraseSecondKeys() function.
deba@2039
   707
      virtual void erase(const std::vector<SecondKey>& _secondKeys){
deba@2039
   708
        _owner.eraseSecondKeys(_secondKeys);
deba@2039
   709
      }
deba@2039
   710
          
deba@2039
   711
      ///\brief Builds the map.
deba@2039
   712
      ///
deba@2039
   713
      ///It buildes the map. It called by the observer notifier
deba@2039
   714
      ///and it overrides the build() virtual member function of
deba@2039
   715
      ///the observer base.  It will call the map's build()
deba@2039
   716
      ///function.
deba@2039
   717
      virtual void build() {
deba@2039
   718
        _owner.build();
deba@2039
   719
      }
deba@2039
   720
          
deba@2039
   721
      ///\brief Clear the map.
deba@2039
   722
      ///
deba@2039
   723
      ///It erases all items from the map. It called by the
deba@2039
   724
      ///observer notifier and it overrides the clear() virtual
deba@2039
   725
      ///memeber function of the observer base. It will call the
deba@2039
   726
      ///map's clear() function.
deba@2039
   727
      virtual void clear() {
deba@2039
   728
        _owner.clear();
deba@2039
   729
        //_owner.clearFirst();
deba@2039
   730
      }
deba@2039
   731
    private:
deba@2039
   732
          
deba@2039
   733
      ///The type of map for which it is attached.
deba@2039
   734
      DynamicAsymMatrixMap& _owner;
alpar@2072
   735
    };//END OF SECONDKEYPROXY
deba@2039
   736
      
deba@2039
   737
  private:
deba@2039
   738
    
deba@2039
   739
    /// \e
deba@2039
   740
    typedef std::vector<Value> Container;
deba@2039
   741
      
deba@2039
   742
    ///The type of constainer which stores the values of the map.
deba@2039
   743
    typedef std::vector<Container> DContainer;
deba@2039
   744
deba@2039
   745
    ///The std:vector type which contains the data
deba@2039
   746
    DContainer values;
deba@2039
   747
      
deba@2039
   748
    ///Member for the first proxy class
deba@2039
   749
    FirstKeyProxy _first_key_proxy;
deba@2039
   750
      
deba@2039
   751
    ///Member for the second proxy class
deba@2039
   752
    SecondKeyProxy _second_key_proxy;
deba@2039
   753
deba@2039
   754
  public:
deba@2039
   755
    
deba@2039
   756
    ///The refernce type of the map.
deba@2039
   757
    typedef typename Container::reference Reference;
deba@2039
   758
      
deba@2039
   759
    ///The const reference type of the constainer.
deba@2039
   760
    typedef typename Container::const_reference ConstReference;
deba@2039
   761
deba@2039
   762
    ///\brief Constructor what create the map for the two containers type.
deba@2039
   763
    ///
deba@2039
   764
    ///Creates the matrix map and initialize the values with Value()
deba@2039
   765
    DynamicAsymMatrixMap(const _FirstContainer& _firstContainer, 
deba@2039
   766
                  const _SecondContainer& _secondContainer)
deba@2039
   767
      : values(DContainer(_firstContainer.maxId(FirstKey())+1,
deba@2039
   768
                          Container(_secondContainer.maxId(SecondKey())+1))),
deba@2039
   769
        _first_key_proxy(*this),
deba@2039
   770
        _second_key_proxy(*this)
deba@2039
   771
    {
deba@2039
   772
      _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
deba@2039
   773
      _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
deba@2039
   774
    }
deba@2039
   775
deba@2039
   776
    ///\brief Constructor what create the map for the two containers type.
deba@2039
   777
    ///
deba@2039
   778
    ///Creates the matrix map and initialize the values with the given _value
deba@2039
   779
    DynamicAsymMatrixMap(const _FirstContainer& _firstContainer, 
deba@2039
   780
                  const _SecondContainer& _secondContainer, 
deba@2039
   781
                  const Value& _value)
deba@2039
   782
      : values(DContainer(_firstContainer.maxId(FirstKey())+1,
deba@2039
   783
                          Container(_secondContainer.maxId(SecondKey())+1,
deba@2039
   784
                                    _value))),
deba@2039
   785
        _first_key_proxy(*this),
deba@2039
   786
        _second_key_proxy(*this)
deba@2039
   787
    {
deba@2039
   788
      _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
deba@2039
   789
      _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
deba@2039
   790
    }
deba@2039
   791
      
deba@2039
   792
    ///\brief Copy constructor.
deba@2039
   793
    ///
deba@2039
   794
    ///The copy constructor of the map.
deba@2039
   795
    DynamicAsymMatrixMap(const DynamicAsymMatrixMap& _copy) 
deba@2039
   796
      : _first_key_proxy(*this), _second_key_proxy(*this) {
deba@2039
   797
      if(_copy._first_key_proxy.attached() && 
deba@2039
   798
         _copy._second_key_proxy.attached()){
deba@2039
   799
        _first_key_proxy.attach(*_copy._first_key_proxy.getNotifier());
deba@2039
   800
        _second_key_proxy.attach(*_copy._second_key_proxy.getNotifier());
deba@2039
   801
        values = _copy.values;
deba@2039
   802
      }
deba@2039
   803
    }
deba@2039
   804
      
deba@2039
   805
    ///\brief Destructor
deba@2039
   806
    ///
deba@2039
   807
    ///Destructor what detach() from the attached objects.  May this
deba@2039
   808
    ///function is not necessary because the destructor of
deba@2039
   809
    ///ObserverBase do the same.
deba@2039
   810
    ~DynamicAsymMatrixMap() {
deba@2039
   811
      if(_first_key_proxy.attached()){
deba@2039
   812
        _first_key_proxy.detach();
deba@2039
   813
      }
deba@2039
   814
      if(_second_key_proxy.attached()){
deba@2039
   815
        _second_key_proxy.detach();
deba@2039
   816
      }
deba@2039
   817
    }
deba@2039
   818
      
deba@2039
   819
    ///\brief Gives back the value assigned to the \c first - \c
deba@2039
   820
    ///second ordered pair.
deba@2039
   821
    ///
deba@2039
   822
    ///Gives back the value assigned to the \c first - \c second
deba@2039
   823
    ///ordered pair.
deba@2039
   824
    Reference operator()(const FirstKey& _first, const SecondKey& _second) {
deba@2039
   825
      return values[_first_key_proxy.getNotifier()->id(_first)]
deba@2039
   826
        [_second_key_proxy.getNotifier()->id(_second)];
deba@2039
   827
    }
deba@2039
   828
deba@2039
   829
    ///\brief Gives back the value assigned to the \c first - \c
deba@2039
   830
    ///second ordered pair.
deba@2039
   831
    ///
deba@2039
   832
    ///Gives back the value assigned to the \c first - \c second
deba@2039
   833
    ///ordered pair.
deba@2039
   834
    ConstReference operator()(const FirstKey& _first, 
deba@2039
   835
                              const SecondKey& _second) const {
deba@2039
   836
      return values[_first_key_proxy.getNotifier()->id(_first)]
deba@2039
   837
        [_second_key_proxy.getNotifier()->id(_second)];
deba@2039
   838
    }
deba@2039
   839
deba@2039
   840
    ///\brief Setter function for this matrix map.
deba@2039
   841
    ///
deba@2039
   842
    ///Setter function for this matrix map.
deba@2039
   843
    void set(const FirstKey& first, const SecondKey& second, 
deba@2039
   844
             const Value& value){
deba@2039
   845
      values[_first_key_proxy.getNotifier()->id(first)]
deba@2039
   846
        [_second_key_proxy.getNotifier()->id(second)] = value;
deba@2039
   847
    }
deba@2039
   848
deba@2039
   849
    ///\brief The assignement operator.
deba@2039
   850
    ///
deba@2039
   851
    ///It allow to assign a map to an other. It
deba@2039
   852
    DynamicAsymMatrixMap& operator=(const DynamicAsymMatrixMap& _cmap){
deba@2039
   853
      return operator=<DynamicAsymMatrixMap>(_cmap);
deba@2039
   854
    }
deba@2039
   855
      
deba@2039
   856
    ///\brief Template assignement operator.
deba@2039
   857
    ///
deba@2039
   858
    ///It copy the element of the given map to its own container.  The
deba@2039
   859
    ///type of the two map shall be the same.
deba@2039
   860
    template <typename CMap>
deba@2039
   861
    DynamicAsymMatrixMap& operator=(const CMap& _cdmap){
deba@2039
   862
      checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
deba@2039
   863
      const typename FirstKeyProxy::Notifier* notifierFirstKey = 
deba@2039
   864
        _first_key_proxy.getNotifier();
deba@2039
   865
      const typename SecondKeyProxy::Notifier* notifierSecondKey = 
deba@2039
   866
        _second_key_proxy.getNotifier();
deba@2039
   867
      FirstKey itemFirst;
deba@2039
   868
      SecondKey itemSecond;
deba@2039
   869
      for(notifierFirstKey->first(itemFirst); itemFirst != INVALID; 
deba@2039
   870
          notifierFirstKey->next(itemFirst)){
deba@2039
   871
        for(notifierSecondKey->first(itemSecond); itemSecond != INVALID; 
deba@2039
   872
            notifierSecondKey->next(itemSecond)){
deba@2039
   873
          set(itemFirst, itemSecond, _cdmap(itemFirst,itemSecond));
deba@2039
   874
        }
deba@2039
   875
      }
deba@2039
   876
      return *this;
deba@2039
   877
    }
deba@2039
   878
      
deba@2039
   879
  protected:
deba@2039
   880
    
deba@2039
   881
    ///\brief Add a new FirstKey to the map.
deba@2039
   882
    ///
deba@2039
   883
    ///It adds a new FirstKey to the map. It is called by the observer
deba@2039
   884
    ///class belongs to the FirstKey type.
deba@2039
   885
    void addFirstKey(const FirstKey& firstKey) {
deba@2039
   886
      int size = (int)values.size();
deba@2039
   887
      if( _first_key_proxy.getNotifier()->id(firstKey)+1 >= size ){
deba@2039
   888
        values.resize(_first_key_proxy.getNotifier()->id(firstKey)+1);
deba@2039
   889
        if( (int)values[0].size() != 0 ){
deba@2039
   890
          int innersize = (int)values[0].size();
deba@2039
   891
          for(int i=size; i!=(int)values.size();++i){
deba@2039
   892
            (values[i]).resize(innersize);
deba@2039
   893
          }
deba@2039
   894
        }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
deba@2039
   895
          int innersize = _second_key_proxy.getNotifier()->maxId();
deba@2039
   896
          for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   897
            values[0].resize(innersize);
deba@2039
   898
          }
deba@2039
   899
        }
deba@2039
   900
      }
deba@2039
   901
    }
deba@2039
   902
deba@2039
   903
    ///\brief Adds more new FirstKeys to the map.
deba@2039
   904
    ///
deba@2039
   905
    ///It adds more new FirstKeys to the map. It called by the
deba@2039
   906
    ///observer class belongs to the FirstKey type.
deba@2039
   907
    void addFirstKeys(const std::vector<FirstKey>& firstKeys){
deba@2039
   908
      int max = values.size() - 1;
deba@2039
   909
      for(int i=0; i != (int)firstKeys.size(); ++i){
deba@2039
   910
        int id = _first_key_proxy.getNotifier()->id(firstKeys[i]);
deba@2039
   911
        if(max < id){
deba@2039
   912
          max = id;
deba@2039
   913
        }
deba@2039
   914
      }
deba@2039
   915
      int size = (int)values.size();
deba@2039
   916
      if(max >= size){
deba@2039
   917
        values.resize(max + 1);
deba@2039
   918
        if( (int)values[0].size() != 0){
deba@2039
   919
          int innersize = (int)values[0].size();
deba@2039
   920
          for(int i = size; i != (max + 1); ++i){
deba@2039
   921
            values[i].resize(innersize);
deba@2039
   922
          }
deba@2039
   923
        }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
deba@2039
   924
          int innersize = _second_key_proxy.getNotifier()->maxId();
deba@2039
   925
          for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   926
            values[i].resize(innersize);
deba@2039
   927
          }
deba@2039
   928
        }
deba@2039
   929
      }
deba@2039
   930
    }
deba@2039
   931
deba@2039
   932
    ///\brief Add a new SecondKey to the map.
deba@2039
   933
    ///
deba@2039
   934
    ///It adds a new SecondKey to the map. It is called by the
deba@2039
   935
    ///observer class belongs to the SecondKey type.
deba@2039
   936
    void addSecondKey(const SecondKey& secondKey) {
deba@2039
   937
      if(values.size() == 0){
deba@2039
   938
        return;
deba@2039
   939
      }
deba@2039
   940
      int id = _second_key_proxy.getNotifier()->id(secondKey);
deba@2039
   941
      if(id >= (int)values[0].size()){
deba@2039
   942
        for(int i=0;i!=(int)values.size();++i){
deba@2039
   943
          values[i].resize(id+1);
deba@2039
   944
        }
deba@2039
   945
      }
deba@2039
   946
    }
deba@2039
   947
        
deba@2039
   948
    ///\brief Adds more new SecondKeys to the map.
deba@2039
   949
    ///
deba@2039
   950
    ///It adds more new SecondKeys to the map. It called by the
deba@2039
   951
    ///observer class belongs to the SecondKey type.
deba@2039
   952
    void addSecondKeys(const std::vector<SecondKey>& secondKeys){
deba@2039
   953
      if(values.size() == 0){
deba@2039
   954
        return;
deba@2039
   955
      }
deba@2039
   956
      int max = values[0].size();
deba@2039
   957
      for(int i = 0; i != (int)secondKeys.size(); ++i){
deba@2039
   958
        int id = _second_key_proxy.getNotifier()->id(secondKeys[i]);
deba@2039
   959
        if(max < id){
deba@2039
   960
          max = id;
deba@2039
   961
        }
deba@2039
   962
      }
deba@2039
   963
      if(max > (int)values[0].size()){
deba@2039
   964
        for(int i = 0; i != (int)values.size(); ++i){
deba@2039
   965
          values[i].resize(max + 1);
deba@2039
   966
        }
deba@2039
   967
      }
deba@2039
   968
    }
deba@2039
   969
    
deba@2039
   970
    ///\brief Erase a FirstKey from the map.
deba@2039
   971
    ///
deba@2039
   972
    ///Erase a FirstKey from the map. It called by the observer
deba@2039
   973
    ///class belongs to the FirstKey type.
deba@2039
   974
    void eraseFirstKey(const FirstKey& first) {
deba@2039
   975
      int id = _first_key_proxy.getNotifier()->id(first);
deba@2039
   976
      for(int i = 0; i != (int)values[id].size(); ++i){
deba@2039
   977
        values[id][i] = Value();
deba@2039
   978
      }
deba@2039
   979
    }
deba@2039
   980
        
deba@2039
   981
    ///\brief Erase more FirstKey from the map.
deba@2039
   982
    ///
deba@2039
   983
    ///Erase more FirstKey from the map. It called by the observer
deba@2039
   984
    ///class belongs to the FirstKey type.
deba@2039
   985
    void eraseFirstKeys(const std::vector<FirstKey>& firstKeys) {
deba@2039
   986
      for(int j = 0; j != (int)firstKeys.size(); ++j){
deba@2039
   987
        int id = _first_key_proxy.getNotifier()->id(firstKeys[j]);
deba@2039
   988
        for(int i = 0; i != (int)values[id].size(); ++i){
deba@2039
   989
          values[id][i] = Value();
deba@2039
   990
        }
deba@2039
   991
      }
deba@2039
   992
    }
deba@2039
   993
deba@2039
   994
    ///\brief Erase a SecondKey from the map.
deba@2039
   995
    ///
deba@2039
   996
    ///Erase a SecondKey from the map. It called by the observer class
deba@2039
   997
    ///belongs to the SecondKey type.
deba@2039
   998
    void eraseSecondKey(const SecondKey& second) {
deba@2039
   999
      if(values.size() == 0){
deba@2039
  1000
        return;
deba@2039
  1001
      }
deba@2039
  1002
      int id = _second_key_proxy.getNotifier()->id(second);
deba@2039
  1003
      for(int i = 0; i != (int)values.size(); ++i){
deba@2039
  1004
        values[i][id] = Value();
deba@2039
  1005
      }
deba@2039
  1006
    }
deba@2039
  1007
        
deba@2039
  1008
    ///\brief Erase more SecondKey from the map.
deba@2039
  1009
    ///
deba@2039
  1010
    ///Erase more SecondKey from the map. It called by the observer
deba@2039
  1011
    ///class belongs to the SecondKey type.
deba@2039
  1012
    void eraseSecondKeys(const std::vector<SecondKey>& secondKeys) {
deba@2039
  1013
      if(values.size() == 0){
deba@2039
  1014
        return;
deba@2039
  1015
      }
deba@2039
  1016
      for(int j = 0; j != (int)secondKeys.size(); ++j){
deba@2039
  1017
        int id = _second_key_proxy.getNotifier()->id(secondKeys[j]);
deba@2039
  1018
        for(int i = 0; i != (int)values.size(); ++i){
deba@2039
  1019
          values[i][id] = Value();
deba@2039
  1020
        }
deba@2039
  1021
      }
deba@2039
  1022
    }
deba@2039
  1023
deba@2039
  1024
    ///\brief Builds the map.
deba@2039
  1025
    ///
deba@2039
  1026
    ///It buildes the map. It is called by the observer class belongs
deba@2039
  1027
    ///to the FirstKey or SecondKey type.
deba@2039
  1028
    void build() {
deba@2039
  1029
      values.resize(_first_key_proxy.getNotifier()->maxId());
deba@2039
  1030
      for(int i=0; i!=(int)values.size(); ++i){
deba@2039
  1031
        values[i].resize(_second_key_proxy.getNotifier()->maxId());
deba@2039
  1032
      }
deba@2039
  1033
    }
deba@2039
  1034
    
deba@2039
  1035
    ///\brief Clear the map.
deba@2039
  1036
    ///
deba@2039
  1037
    ///It erases all items from the map. It is called by the observer class
deba@2039
  1038
    ///belongs to the FirstKey or SecondKey type.
deba@2039
  1039
    void clear() {
deba@2039
  1040
      for(int i=0; i!=(int)values.size(); ++i) {
deba@2039
  1041
        values[i].clear();
deba@2039
  1042
      }
deba@2039
  1043
      values.clear();
deba@2039
  1044
    }
deba@2039
  1045
 
deba@2039
  1046
  };
deba@2039
  1047
deba@2039
  1048
deba@1720
  1049
deba@1720
  1050
}
deba@1720
  1051
deba@1720
  1052
#endif