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