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