3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_MATRIX_MAPS_H
20 #define LEMON_MATRIX_MAPS_H
24 #include <lemon/bits/utility.h>
25 #include <lemon/maps.h>
27 #include <lemon/concept/matrix_maps.h>
31 /// \brief Maps indexed with pairs of items.
33 /// \todo This file has the same name as the concept file in concept/,
34 /// and this is not easily detectable in docs...
37 /// \brief Map for the coloumn view of the matrix
39 /// Map for the coloumn view of the matrix.
40 template <typename _MatrixMap>
41 class MatrixRowMap : public MatrixMapTraits<_MatrixMap> {
43 typedef _MatrixMap MatrixMap;
44 typedef typename MatrixMap::SecondKey Key;
45 typedef typename MatrixMap::Value Value;
48 MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row)
49 : matrix(_matrix), row(_row) {}
51 /// \brief Subscription operator
53 /// Subscription operator.
54 typename MatrixMapTraits<MatrixMap>::ReturnValue
56 return matrix(row, col);
59 /// \brief Setter function
62 void set(Key col, const Value& val) {
63 matrix.set(row, col, val);
66 /// \brief Subscription operator
68 /// Subscription operator.
69 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
70 operator[](Key col) const {
71 return matrix(row, col);
76 typename MatrixMap::FirstKey row;
79 /// \brief Map for the row view of the matrix
81 /// Map for the row view of the matrix.
82 template <typename _MatrixMap>
83 class ConstMatrixRowMap : public MatrixMapTraits<_MatrixMap> {
85 typedef _MatrixMap MatrixMap;
86 typedef typename MatrixMap::SecondKey Key;
87 typedef typename MatrixMap::Value Value;
90 ConstMatrixRowMap(const MatrixMap& _matrix,
91 typename MatrixMap::FirstKey _row)
92 : matrix(_matrix), row(_row) {}
94 /// \brief Subscription operator
96 /// Subscription operator.
97 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
98 operator[](Key col) const {
99 return matrix(row, col);
103 const MatrixMap& matrix;
104 typename MatrixMap::FirstKey row;
107 /// \brief Gives back a row view of the matrix map
109 /// Gives back a row view of the matrix map.
110 template <typename MatrixMap>
111 MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
112 typename MatrixMap::FirstKey row) {
113 return MatrixRowMap<MatrixMap>(matrixMap, row);
116 template <typename MatrixMap>
117 ConstMatrixRowMap<MatrixMap>
118 matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
119 return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
122 /// \brief Map for the row view of the matrix
124 /// Map for the row view of the matrix.
125 template <typename _MatrixMap>
126 class MatrixColMap : public MatrixMapTraits<_MatrixMap> {
128 typedef _MatrixMap MatrixMap;
129 typedef typename MatrixMap::FirstKey Key;
130 typedef typename MatrixMap::Value Value;
132 MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col)
133 : matrix(_matrix), col(_col) {}
135 /// \brief Subscription operator
137 /// Subscription operator.
138 typename MatrixMapTraits<MatrixMap>::ReturnValue
139 operator[](Key row) {
140 return matrix(row, col);
143 /// \brief Setter function
146 void set(Key row, const Value& val) {
147 matrix.set(row, col, val);
150 /// \brief Subscription operator
152 /// Subscription operator.
153 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
154 operator[](Key row) const {
155 return matrix(row, col);
160 typename MatrixMap::SecondKey col;
163 /// \brief Map for the col view of the matrix
165 /// Map for the col view of the matrix.
166 template <typename _MatrixMap>
167 class ConstMatrixColMap : public MatrixMapTraits<_MatrixMap> {
169 typedef _MatrixMap MatrixMap;
170 typedef typename MatrixMap::FirstKey Key;
171 typedef typename MatrixMap::Value Value;
173 ConstMatrixColMap(const MatrixMap& _matrix,
174 typename MatrixMap::SecondKey _col)
175 : matrix(_matrix), col(_col) {}
177 /// \brief Subscription operator
179 /// Subscription operator.
180 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
181 operator[](Key row) const {
182 return matrix(row, col);
186 const MatrixMap& matrix;
187 typename MatrixMap::SecondKey col;
190 /// \brief Gives back a col view of the matrix map
192 /// Gives back a col view of the matrix map.
193 template <typename MatrixMap>
194 MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
195 typename MatrixMap::SecondKey col) {
196 return MatrixColMap<MatrixMap>(matrixMap, col);
199 template <typename MatrixMap>
200 ConstMatrixColMap<MatrixMap>
201 matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
202 return ConstMatrixColMap<MatrixMap>(matrixMap, col);
205 /// \brief Container for store values for each ordered pair of graph items
207 /// This data structure can strore for each pair of the same item
208 /// type a value. It increase the size of the container when the
209 /// associated graph modified, so it updated automaticly whenever
211 template <typename _Graph, typename _Item, typename _Value>
212 class DynamicMatrixMap
213 : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
215 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
218 typedef _Graph Graph;
221 typedef _Item FirstKey;
222 typedef _Item SecondKey;
223 typedef _Value Value;
225 typedef True ReferenceMapTag;
229 typedef std::vector<Value> Container;
233 typedef typename Container::reference Reference;
234 typedef typename Container::const_reference ConstReference;
236 /// \brief Creates an item matrix for the given graph
238 /// Creates an item matrix for the given graph.
239 DynamicMatrixMap(const Graph& _graph)
240 : values(size(_graph.maxId(Key()) + 1)) {
241 Parent::attach(_graph.getNotifier(Key()));
244 /// \brief Creates an item matrix for the given graph
246 /// Creates an item matrix for the given graph and assigns for each
247 /// pairs of keys the given parameter.
248 DynamicMatrixMap(const Graph& _graph, const Value& _val)
249 : values(size(_graph.maxId(Key()) + 1), _val) {
250 Parent::attach(_graph.getNotifier(Key()));
253 ///\brief The assignement operator.
255 ///It allow to assign a map to an other.
256 DynamicMatrixMap& operator=(const DynamicMatrixMap& _cmap){
257 return operator=<DynamicMatrixMap>(_cmap);
260 ///\brief Template assignement operator.
262 ///It copy the element of the given map to its own container. The
263 ///type of the two map shall be the same.
264 template <typename CMap>
265 DynamicMatrixMap& operator=(const CMap& _cmap){
266 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
267 typename Parent::Notifier* notifier = Parent::getNotifier();
269 for(notifier->first(first); first != INVALID;
270 notifier->next(first)){
271 for(notifier->first(second); second != INVALID;
272 notifier->next(second)){
273 set(first, second, _cmap(first, second));
279 /// \brief Gives back the value assigned to the \c first - \c second
282 /// Gives back the value assigned to the \c first - \c second ordered pair.
283 ConstReference operator()(const Key& first, const Key& second) const {
284 return values[index(Parent::getNotifier()->id(first),
285 Parent::getNotifier()->id(second))];
288 /// \brief Gives back the value assigned to the \c first - \c second
291 /// Gives back the value assigned to the \c first - \c second ordered pair.
292 Reference operator()(const Key& first, const Key& second) {
293 return values[index(Parent::getNotifier()->id(first),
294 Parent::getNotifier()->id(second))];
297 /// \brief Setter function for the matrix map.
299 /// Setter function for the matrix map.
300 void set(const Key& first, const Key& second, const Value& val) {
301 values[index(Parent::getNotifier()->id(first),
302 Parent::getNotifier()->id(second))] = val;
307 static int index(int i, int j) {
311 return i * i + i + j;
315 static int size(int s) {
319 virtual void add(const Key& key) {
320 if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
321 values.resize(size(Parent::getNotifier()->id(key) + 1));
325 virtual void erase(const Key&) {}
327 virtual void build() {
328 values.resize(size(Parent::getNotifier()->maxId() + 1));
331 virtual void clear() {
336 std::vector<Value> values;
339 /// \brief Container for store values for each unordered pair of graph items
341 /// This data structure can strore for each pair of the same item
342 /// type a value. It increase the size of the container when the
343 /// associated graph modified, so it updated automaticly whenever
345 template <typename _Graph, typename _Item, typename _Value>
346 class DynamicSymMatrixMap
347 : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
349 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
352 typedef _Graph Graph;
355 typedef _Item FirstKey;
356 typedef _Item SecondKey;
357 typedef _Value Value;
359 typedef True ReferenceMapTag;
363 typedef std::vector<Value> Container;
367 typedef typename Container::reference Reference;
368 typedef typename Container::const_reference ConstReference;
370 /// \brief Creates an item matrix for the given graph
372 /// Creates an item matrix for the given graph.
373 DynamicSymMatrixMap(const Graph& _graph)
374 : values(size(_graph.maxId(Key()) + 1)) {
375 Parent::attach(_graph.getNotifier(Key()));
378 /// \brief Creates an item matrix for the given graph
380 /// Creates an item matrix for the given graph and assigns for each
381 /// pairs of keys the given parameter.
382 DynamicSymMatrixMap(const Graph& _graph, const Value& _val)
383 : values(size(_graph.maxId(Key()) + 1), _val) {
384 Parent::attach(_graph.getNotifier(Key()));
388 ///\brief The assignement operator.
390 ///It allow to assign a map to an other.
391 DynamicSymMatrixMap& operator=(const DynamicSymMatrixMap& _cmap){
392 return operator=<DynamicSymMatrixMap>(_cmap);
395 ///\brief Template assignement operator.
397 ///It copy the element of the given map to its own container. The
398 ///type of the two map shall be the same.
399 template <typename CMap>
400 DynamicSymMatrixMap& operator=(const CMap& _cmap){
401 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
402 typename Parent::Notifier* notifier = Parent::getNotifier();
404 for(notifier->first(first); first != INVALID;
405 notifier->next(first)){
406 for(notifier->first(second); second != first;
407 notifier->next(second)){
408 set(first, second, _cmap(first, second));
410 set(first, first, _cmap(first, first));
415 /// \brief Gives back the value assigned to the \c first - \c second
418 /// Gives back the value assigned to the \c first - \c second unordered
420 ConstReference operator()(const Key& first, const Key& second) const {
421 return values[index(Parent::getNotifier()->id(first),
422 Parent::getNotifier()->id(second))];
425 /// \brief Gives back the value assigned to the \c first - \c second
428 /// Gives back the value assigned to the \c first - \c second unordered
430 Reference operator()(const Key& first, const Key& second) {
431 return values[index(Parent::getNotifier()->id(first),
432 Parent::getNotifier()->id(second))];
435 /// \brief Setter function for the matrix map.
437 /// Setter function for the matrix map.
438 void set(const Key& first, const Key& second, const Value& val) {
439 values[index(Parent::getNotifier()->id(first),
440 Parent::getNotifier()->id(second))] = val;
445 static int index(int i, int j) {
447 return j * (j + 1) / 2 + i;
449 return i * (i + 1) / 2 + j;
453 static int size(int s) {
454 return s * (s + 1) / 2;
457 virtual void add(const Key& key) {
458 if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
459 values.resize(size(Parent::getNotifier()->id(key) + 1));
463 virtual void erase(const Key&) {}
465 virtual void build() {
466 values.resize(size(Parent::getNotifier()->maxId() + 1));
469 virtual void clear() {
474 std::vector<Value> values;
477 ///\brief Dynamic Asymmetric Matrix Map.
479 ///Dynamic Asymmetric Matrix Map. Container for store values for each
480 ///ordered pair of containers items. This data structure can store
481 ///data with different key types from different container types. It
482 ///increases the size of the container if the linked containers
483 ///content change, so it is updated automaticly whenever it is
486 ///This map meet with the concept::ReferenceMatrixMap<typename K1,
487 ///typename K2, typename V, typename R, typename CR> called as
488 ///"ReferenceMatrixMap".
490 ///\param _FirstContainer the desired type of first container. It is
491 ///ususally a Graph type, but can be any type with alteration
494 ///\param _FirstContainerItem the nested type of the
495 ///FirstContainer. It is usually a graph item as Node, Edge,
496 ///etc. This type will be the FirstKey type.
498 ///\param _SecondContainer the desired type of the second
499 ///container. It is usualy a Graph type, but can be any type with
500 ///alteration property.
502 ///\param _SecondContainerItem the nested type of the
503 ///SecondContainer. It is usually a graph item such as Node, Edge,
504 ///UEdge, etc. This type will be the SecondKey type.
506 ///\param _Value the type of the strored values in the container.
508 /// \author Janos Nagy
509 template <typename _FirstContainer, typename _FirstContainerItem,
510 typename _SecondContainer, typename _SecondContainerItem,
512 class DynamicAsymMatrixMap{
515 ///The first key type.
516 typedef _FirstContainerItem FirstKey;
518 ///The second key type.
519 typedef _SecondContainerItem SecondKey;
521 ///The value type of the map.
522 typedef _Value Value;
524 ///Indicates it is a reference map.
525 typedef True ReferenceMapTag;
529 ///\brief Proxy class for the first key type.
531 ///The proxy class belongs to the FirstKey type. It is necessary because
532 ///if one want use the same conatainer types and same nested types but on
533 ///other instances of containers than due to the type equiality of nested
534 ///types it requires a proxy mechanism.
537 ItemSetTraits<_FirstContainer,_FirstContainerItem>::
538 ItemNotifier::ObserverBase
543 friend class DynamicAsymMatrixMap;
546 FirstKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
549 ///\brief Add a new FirstKey to the map.
551 ///It adds a new FirstKey to the map. It is called by the
552 ///observer notifier and it is ovverride the add() virtual
553 ///member function in the observer base. It will call the
554 ///maps addFirstKey() function.
555 virtual void add(const FirstKey& _firstKey){
556 _owner.addFirstKey(_firstKey);
559 ///\brief Add more new FirstKey to the map.
561 ///It adds more new FirstKey to the map. It is called by the
562 ///observer notifier and it is ovverride the add() virtual
563 ///member function in the observer base. It will call the
564 ///map's addFirstKeys() function.
565 virtual void add(const std::vector<FirstKey>& _firstKeys){
566 _owner.addFirstKeys(_firstKeys);
569 ///\brief Erase a FirstKey from the map.
571 ///Erase a FirstKey from the map. It called by the observer
572 ///notifier and it overrides the erase() virtual member
573 ///function of the observer base. It will call the map's
574 ///eraseFirstKey() function.
575 virtual void erase(const FirstKey& _firstKey){
576 _owner.eraseFirstKey(_firstKey);
579 ///\brief Erase more FirstKey from the map.
581 ///Erase more FirstKey from the map. It called by the
582 ///observer notifier and it overrides the erase() virtual
583 ///member function of the observer base. It will call the
584 ///map's eraseFirstKeys() function.
585 virtual void erase(const std::vector<FirstKey>& _firstKeys){
586 _owner.eraseFirstKeys(_firstKeys);
589 ///\brief Builds the map.
591 ///It buildes the map. It called by the observer notifier
592 ///and it overrides the build() virtual member function of
593 ///the observer base. It will call the map's build()
595 virtual void build() {
597 //_owner.buildFirst();
600 ///\brief Clear the map.
602 ///It erases all items from the map. It called by the
603 ///observer notifier and it overrides the clear() virtual
604 ///memeber function of the observer base. It will call the
605 ///map's clear() function.
606 virtual void clear() {
608 //_owner.clearFirst();
612 ///The map type for it is linked.
613 DynamicAsymMatrixMap& _owner;
614 };///END OF FIRSTKEYPROXY
616 ///\brief Proxy class for the second key type.
618 ///The proxy class belongs to the SecondKey type. It is
619 ///necessary because if one want use the same conatainer types
620 ///and same nested types but on other instances of containers
621 ///than due to the type equiality of nested types it requires a
625 ItemSetTraits<_SecondContainer, _SecondContainerItem>::
626 ItemNotifier::ObserverBase {
630 friend class DynamicAsymMatrixMap;
632 SecondKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
636 ///\brief Add a new SecondKey to the map.
638 ///It adds a new SecondKey to the map. It is called by the
639 ///observer notifier and it is ovverride the add() virtual
640 ///member function in the observer base. It will call the
641 ///maps addSecondKey() function.
642 virtual void add(const SecondKey& _secondKey){
643 _owner.addSecondKey(_secondKey);
646 ///\brief Add more new SecondKey to the map.
648 ///It adds more new SecondKey to the map. It is called by
649 ///the observer notifier and it is ovverride the add()
650 ///virtual member function in the observer base. It will
651 ///call the maps addSecondKeys() function.
652 virtual void add(const std::vector<SecondKey>& _secondKeys){
653 _owner.addSecondKeys(_secondKeys);
656 ///\brief Erase a SecondKey from the map.
658 ///Erase a SecondKey from the map. It called by the observer
659 ///notifier and it overrides the erase() virtual member
660 ///function of the observer base. It will call the map's
661 ///eraseSecondKey() function.
662 virtual void erase(const SecondKey& _secondKey){
663 _owner.eraseSecondKey(_secondKey);
666 ///\brief Erase more SecondKeys from the map.
668 ///Erase more SecondKey from the map. It called by the
669 ///observer notifier and it overrides the erase() virtual
670 ///member function of the observer base. It will call the
671 ///map's eraseSecondKeys() function.
672 virtual void erase(const std::vector<SecondKey>& _secondKeys){
673 _owner.eraseSecondKeys(_secondKeys);
676 ///\brief Builds the map.
678 ///It buildes the map. It called by the observer notifier
679 ///and it overrides the build() virtual member function of
680 ///the observer base. It will call the map's build()
682 virtual void build() {
686 ///\brief Clear the map.
688 ///It erases all items from the map. It called by the
689 ///observer notifier and it overrides the clear() virtual
690 ///memeber function of the observer base. It will call the
691 ///map's clear() function.
692 virtual void clear() {
694 //_owner.clearFirst();
698 ///The type of map for which it is attached.
699 DynamicAsymMatrixMap& _owner;
700 };///END OF SECONDKEYPROXY
705 typedef std::vector<Value> Container;
707 ///The type of constainer which stores the values of the map.
708 typedef std::vector<Container> DContainer;
710 ///The std:vector type which contains the data
713 ///Member for the first proxy class
714 FirstKeyProxy _first_key_proxy;
716 ///Member for the second proxy class
717 SecondKeyProxy _second_key_proxy;
721 ///The refernce type of the map.
722 typedef typename Container::reference Reference;
724 ///The const reference type of the constainer.
725 typedef typename Container::const_reference ConstReference;
727 ///\brief Constructor what create the map for the two containers type.
729 ///Creates the matrix map and initialize the values with Value()
730 DynamicAsymMatrixMap(const _FirstContainer& _firstContainer,
731 const _SecondContainer& _secondContainer)
732 : values(DContainer(_firstContainer.maxId(FirstKey())+1,
733 Container(_secondContainer.maxId(SecondKey())+1))),
734 _first_key_proxy(*this),
735 _second_key_proxy(*this)
737 _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
738 _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
741 ///\brief Constructor what create the map for the two containers type.
743 ///Creates the matrix map and initialize the values with the given _value
744 DynamicAsymMatrixMap(const _FirstContainer& _firstContainer,
745 const _SecondContainer& _secondContainer,
747 : values(DContainer(_firstContainer.maxId(FirstKey())+1,
748 Container(_secondContainer.maxId(SecondKey())+1,
750 _first_key_proxy(*this),
751 _second_key_proxy(*this)
753 _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
754 _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
757 ///\brief Copy constructor.
759 ///The copy constructor of the map.
760 DynamicAsymMatrixMap(const DynamicAsymMatrixMap& _copy)
761 : _first_key_proxy(*this), _second_key_proxy(*this) {
762 if(_copy._first_key_proxy.attached() &&
763 _copy._second_key_proxy.attached()){
764 _first_key_proxy.attach(*_copy._first_key_proxy.getNotifier());
765 _second_key_proxy.attach(*_copy._second_key_proxy.getNotifier());
766 values = _copy.values;
772 ///Destructor what detach() from the attached objects. May this
773 ///function is not necessary because the destructor of
774 ///ObserverBase do the same.
775 ~DynamicAsymMatrixMap() {
776 if(_first_key_proxy.attached()){
777 _first_key_proxy.detach();
779 if(_second_key_proxy.attached()){
780 _second_key_proxy.detach();
784 ///\brief Gives back the value assigned to the \c first - \c
785 ///second ordered pair.
787 ///Gives back the value assigned to the \c first - \c second
789 Reference operator()(const FirstKey& _first, const SecondKey& _second) {
790 return values[_first_key_proxy.getNotifier()->id(_first)]
791 [_second_key_proxy.getNotifier()->id(_second)];
794 ///\brief Gives back the value assigned to the \c first - \c
795 ///second ordered pair.
797 ///Gives back the value assigned to the \c first - \c second
799 ConstReference operator()(const FirstKey& _first,
800 const SecondKey& _second) const {
801 return values[_first_key_proxy.getNotifier()->id(_first)]
802 [_second_key_proxy.getNotifier()->id(_second)];
805 ///\brief Setter function for this matrix map.
807 ///Setter function for this matrix map.
808 void set(const FirstKey& first, const SecondKey& second,
810 values[_first_key_proxy.getNotifier()->id(first)]
811 [_second_key_proxy.getNotifier()->id(second)] = value;
814 ///\brief The assignement operator.
816 ///It allow to assign a map to an other. It
817 DynamicAsymMatrixMap& operator=(const DynamicAsymMatrixMap& _cmap){
818 return operator=<DynamicAsymMatrixMap>(_cmap);
821 ///\brief Template assignement operator.
823 ///It copy the element of the given map to its own container. The
824 ///type of the two map shall be the same.
825 template <typename CMap>
826 DynamicAsymMatrixMap& operator=(const CMap& _cdmap){
827 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
828 const typename FirstKeyProxy::Notifier* notifierFirstKey =
829 _first_key_proxy.getNotifier();
830 const typename SecondKeyProxy::Notifier* notifierSecondKey =
831 _second_key_proxy.getNotifier();
833 SecondKey itemSecond;
834 for(notifierFirstKey->first(itemFirst); itemFirst != INVALID;
835 notifierFirstKey->next(itemFirst)){
836 for(notifierSecondKey->first(itemSecond); itemSecond != INVALID;
837 notifierSecondKey->next(itemSecond)){
838 set(itemFirst, itemSecond, _cdmap(itemFirst,itemSecond));
846 ///\brief Add a new FirstKey to the map.
848 ///It adds a new FirstKey to the map. It is called by the observer
849 ///class belongs to the FirstKey type.
850 void addFirstKey(const FirstKey& firstKey) {
851 int size = (int)values.size();
852 if( _first_key_proxy.getNotifier()->id(firstKey)+1 >= size ){
853 values.resize(_first_key_proxy.getNotifier()->id(firstKey)+1);
854 if( (int)values[0].size() != 0 ){
855 int innersize = (int)values[0].size();
856 for(int i=size; i!=(int)values.size();++i){
857 (values[i]).resize(innersize);
859 }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
860 int innersize = _second_key_proxy.getNotifier()->maxId();
861 for(int i = 0; i != (int)values.size(); ++i){
862 values[0].resize(innersize);
868 ///\brief Adds more new FirstKeys to the map.
870 ///It adds more new FirstKeys to the map. It called by the
871 ///observer class belongs to the FirstKey type.
872 void addFirstKeys(const std::vector<FirstKey>& firstKeys){
873 int max = values.size() - 1;
874 for(int i=0; i != (int)firstKeys.size(); ++i){
875 int id = _first_key_proxy.getNotifier()->id(firstKeys[i]);
880 int size = (int)values.size();
882 values.resize(max + 1);
883 if( (int)values[0].size() != 0){
884 int innersize = (int)values[0].size();
885 for(int i = size; i != (max + 1); ++i){
886 values[i].resize(innersize);
888 }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
889 int innersize = _second_key_proxy.getNotifier()->maxId();
890 for(int i = 0; i != (int)values.size(); ++i){
891 values[i].resize(innersize);
897 ///\brief Add a new SecondKey to the map.
899 ///It adds a new SecondKey to the map. It is called by the
900 ///observer class belongs to the SecondKey type.
901 void addSecondKey(const SecondKey& secondKey) {
902 if(values.size() == 0){
905 int id = _second_key_proxy.getNotifier()->id(secondKey);
906 if(id >= (int)values[0].size()){
907 for(int i=0;i!=(int)values.size();++i){
908 values[i].resize(id+1);
913 ///\brief Adds more new SecondKeys to the map.
915 ///It adds more new SecondKeys to the map. It called by the
916 ///observer class belongs to the SecondKey type.
917 void addSecondKeys(const std::vector<SecondKey>& secondKeys){
918 if(values.size() == 0){
921 int max = values[0].size();
922 for(int i = 0; i != (int)secondKeys.size(); ++i){
923 int id = _second_key_proxy.getNotifier()->id(secondKeys[i]);
928 if(max > (int)values[0].size()){
929 for(int i = 0; i != (int)values.size(); ++i){
930 values[i].resize(max + 1);
935 ///\brief Erase a FirstKey from the map.
937 ///Erase a FirstKey from the map. It called by the observer
938 ///class belongs to the FirstKey type.
939 void eraseFirstKey(const FirstKey& first) {
940 int id = _first_key_proxy.getNotifier()->id(first);
941 for(int i = 0; i != (int)values[id].size(); ++i){
942 values[id][i] = Value();
946 ///\brief Erase more FirstKey from the map.
948 ///Erase more FirstKey from the map. It called by the observer
949 ///class belongs to the FirstKey type.
950 void eraseFirstKeys(const std::vector<FirstKey>& firstKeys) {
951 for(int j = 0; j != (int)firstKeys.size(); ++j){
952 int id = _first_key_proxy.getNotifier()->id(firstKeys[j]);
953 for(int i = 0; i != (int)values[id].size(); ++i){
954 values[id][i] = Value();
959 ///\brief Erase a SecondKey from the map.
961 ///Erase a SecondKey from the map. It called by the observer class
962 ///belongs to the SecondKey type.
963 void eraseSecondKey(const SecondKey& second) {
964 if(values.size() == 0){
967 int id = _second_key_proxy.getNotifier()->id(second);
968 for(int i = 0; i != (int)values.size(); ++i){
969 values[i][id] = Value();
973 ///\brief Erase more SecondKey from the map.
975 ///Erase more SecondKey from the map. It called by the observer
976 ///class belongs to the SecondKey type.
977 void eraseSecondKeys(const std::vector<SecondKey>& secondKeys) {
978 if(values.size() == 0){
981 for(int j = 0; j != (int)secondKeys.size(); ++j){
982 int id = _second_key_proxy.getNotifier()->id(secondKeys[j]);
983 for(int i = 0; i != (int)values.size(); ++i){
984 values[i][id] = Value();
989 ///\brief Builds the map.
991 ///It buildes the map. It is called by the observer class belongs
992 ///to the FirstKey or SecondKey type.
994 values.resize(_first_key_proxy.getNotifier()->maxId());
995 for(int i=0; i!=(int)values.size(); ++i){
996 values[i].resize(_second_key_proxy.getNotifier()->maxId());
1000 ///\brief Clear the map.
1002 ///It erases all items from the map. It is called by the observer class
1003 ///belongs to the FirstKey or SecondKey type.
1005 for(int i=0; i!=(int)values.size(); ++i) {