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
40 /// Map for the coloumn view of the matrix.
42 template <typename _MatrixMap>
43 class MatrixRowMap : public MatrixMapTraits<_MatrixMap> {
45 typedef _MatrixMap MatrixMap;
46 typedef typename MatrixMap::SecondKey Key;
47 typedef typename MatrixMap::Value Value;
50 MatrixRowMap(MatrixMap& _matrix, typename MatrixMap::FirstKey _row)
51 : matrix(_matrix), row(_row) {}
53 /// \brief Subscription operator
55 /// Subscription operator.
56 typename MatrixMapTraits<MatrixMap>::ReturnValue
58 return matrix(row, col);
61 /// \brief Setter function
64 void set(Key col, const Value& val) {
65 matrix.set(row, col, val);
68 /// \brief Subscription operator
70 /// Subscription operator.
71 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
72 operator[](Key col) const {
73 return matrix(row, col);
78 typename MatrixMap::FirstKey row;
81 /// \brief Map for the row view of the matrix
84 /// Map for the row view of the matrix.
86 template <typename _MatrixMap>
87 class ConstMatrixRowMap : public MatrixMapTraits<_MatrixMap> {
89 typedef _MatrixMap MatrixMap;
90 typedef typename MatrixMap::SecondKey Key;
91 typedef typename MatrixMap::Value Value;
94 ConstMatrixRowMap(const MatrixMap& _matrix,
95 typename MatrixMap::FirstKey _row)
96 : matrix(_matrix), row(_row) {}
98 /// \brief Subscription operator
100 /// Subscription operator.
101 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
102 operator[](Key col) const {
103 return matrix(row, col);
107 const MatrixMap& matrix;
108 typename MatrixMap::FirstKey row;
111 /// \brief Gives back a row view of the matrix map
113 /// \ingroup matrices
114 /// Gives back a row view of the matrix map.
116 template <typename MatrixMap>
117 MatrixRowMap<MatrixMap> matrixRowMap(MatrixMap& matrixMap,
118 typename MatrixMap::FirstKey row) {
119 return MatrixRowMap<MatrixMap>(matrixMap, row);
122 template <typename MatrixMap>
123 ConstMatrixRowMap<MatrixMap>
124 matrixRowMap(const MatrixMap& matrixMap, typename MatrixMap::FirstKey row) {
125 return ConstMatrixRowMap<MatrixMap>(matrixMap, row);
128 /// \brief Map for the column view of the matrix
130 /// \ingroup matrices
131 /// Map for the column view of the matrix.
133 template <typename _MatrixMap>
134 class MatrixColMap : public MatrixMapTraits<_MatrixMap> {
136 typedef _MatrixMap MatrixMap;
137 typedef typename MatrixMap::FirstKey Key;
138 typedef typename MatrixMap::Value Value;
140 MatrixColMap(MatrixMap& _matrix, typename MatrixMap::SecondKey _col)
141 : matrix(_matrix), col(_col) {}
143 /// \brief Subscription operator
145 /// Subscription operator.
146 typename MatrixMapTraits<MatrixMap>::ReturnValue
147 operator[](Key row) {
148 return matrix(row, col);
151 /// \brief Setter function
154 void set(Key row, const Value& val) {
155 matrix.set(row, col, val);
158 /// \brief Subscription operator
160 /// Subscription operator.
161 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
162 operator[](Key row) const {
163 return matrix(row, col);
168 typename MatrixMap::SecondKey col;
171 /// \brief Map for the column view of the matrix
173 /// \ingroup matrices
174 /// Map for the column view of the matrix.
176 template <typename _MatrixMap>
177 class ConstMatrixColMap : public MatrixMapTraits<_MatrixMap> {
179 typedef _MatrixMap MatrixMap;
180 typedef typename MatrixMap::FirstKey Key;
181 typedef typename MatrixMap::Value Value;
183 ConstMatrixColMap(const MatrixMap& _matrix,
184 typename MatrixMap::SecondKey _col)
185 : matrix(_matrix), col(_col) {}
187 /// \brief Subscription operator
189 /// Subscription operator.
190 typename MatrixMapTraits<MatrixMap>::ConstReturnValue
191 operator[](Key row) const {
192 return matrix(row, col);
196 const MatrixMap& matrix;
197 typename MatrixMap::SecondKey col;
200 /// \brief Gives back a column view of the matrix map
202 /// \ingroup matrices
203 /// Gives back a column view of the matrix map.
205 template <typename MatrixMap>
206 MatrixColMap<MatrixMap> matrixColMap(MatrixMap& matrixMap,
207 typename MatrixMap::SecondKey col) {
208 return MatrixColMap<MatrixMap>(matrixMap, col);
211 template <typename MatrixMap>
212 ConstMatrixColMap<MatrixMap>
213 matrixColMap(const MatrixMap& matrixMap, typename MatrixMap::SecondKey col) {
214 return ConstMatrixColMap<MatrixMap>(matrixMap, col);
217 /// \brief Container for store values for each ordered pair of graph items
219 /// \ingroup matrices
220 /// This data structure can strore for each pair of the same item
221 /// type a value. It increase the size of the container when the
222 /// associated graph modified, so it updated automaticly whenever
224 template <typename _Graph, typename _Item, typename _Value>
225 class DynamicMatrixMap
226 : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
228 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
231 typedef _Graph Graph;
234 typedef _Item FirstKey;
235 typedef _Item SecondKey;
236 typedef _Value Value;
238 typedef True ReferenceMapTag;
242 typedef std::vector<Value> Container;
246 typedef typename Container::reference Reference;
247 typedef typename Container::const_reference ConstReference;
249 /// \brief Creates an item matrix for the given graph
251 /// Creates an item matrix for the given graph.
252 DynamicMatrixMap(const Graph& _graph)
253 : values(size(_graph.maxId(Key()) + 1)) {
254 Parent::attach(_graph.getNotifier(Key()));
257 /// \brief Creates an item matrix for the given graph
259 /// Creates an item matrix for the given graph and assigns for each
260 /// pairs of keys the given parameter.
261 DynamicMatrixMap(const Graph& _graph, const Value& _val)
262 : values(size(_graph.maxId(Key()) + 1), _val) {
263 Parent::attach(_graph.getNotifier(Key()));
266 ///\brief The assignement operator.
268 ///It allow to assign a map to an other.
269 DynamicMatrixMap& operator=(const DynamicMatrixMap& _cmap){
270 return operator=<DynamicMatrixMap>(_cmap);
273 ///\brief Template assignement operator.
275 ///It copy the element of the given map to its own container. The
276 ///type of the two map shall be the same.
277 template <typename CMap>
278 DynamicMatrixMap& operator=(const CMap& _cmap){
279 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
280 typename Parent::Notifier* notifier = Parent::getNotifier();
282 for(notifier->first(first); first != INVALID;
283 notifier->next(first)){
284 for(notifier->first(second); second != INVALID;
285 notifier->next(second)){
286 set(first, second, _cmap(first, second));
292 /// \brief Gives back the value assigned to the \c first - \c second
295 /// Gives back the value assigned to the \c first - \c second ordered pair.
296 ConstReference operator()(const Key& first, const Key& second) const {
297 return values[index(Parent::getNotifier()->id(first),
298 Parent::getNotifier()->id(second))];
301 /// \brief Gives back the value assigned to the \c first - \c second
304 /// Gives back the value assigned to the \c first - \c second ordered pair.
305 Reference operator()(const Key& first, const Key& second) {
306 return values[index(Parent::getNotifier()->id(first),
307 Parent::getNotifier()->id(second))];
310 /// \brief Setter function for the matrix map.
312 /// Setter function for the matrix map.
313 void set(const Key& first, const Key& second, const Value& val) {
314 values[index(Parent::getNotifier()->id(first),
315 Parent::getNotifier()->id(second))] = val;
320 static int index(int i, int j) {
324 return i * i + i + j;
328 static int size(int s) {
332 virtual void add(const Key& key) {
333 if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
334 values.resize(size(Parent::getNotifier()->id(key) + 1));
338 virtual void erase(const Key&) {}
340 virtual void build() {
341 values.resize(size(Parent::getNotifier()->maxId() + 1));
344 virtual void clear() {
349 std::vector<Value> values;
352 /// \brief Container for store values for each unordered pair of graph items
354 /// \ingroup matrices
355 /// This data structure can strore for each pair of the same item
356 /// type a value. It increase the size of the container when the
357 /// associated graph modified, so it updated automaticly whenever
359 template <typename _Graph, typename _Item, typename _Value>
360 class DynamicSymMatrixMap
361 : protected ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase {
363 typedef typename ItemSetTraits<_Graph, _Item>::ItemNotifier::ObserverBase
366 typedef _Graph Graph;
369 typedef _Item FirstKey;
370 typedef _Item SecondKey;
371 typedef _Value Value;
373 typedef True ReferenceMapTag;
377 typedef std::vector<Value> Container;
381 typedef typename Container::reference Reference;
382 typedef typename Container::const_reference ConstReference;
384 /// \brief Creates an item matrix for the given graph
386 /// Creates an item matrix for the given graph.
387 DynamicSymMatrixMap(const Graph& _graph)
388 : values(size(_graph.maxId(Key()) + 1)) {
389 Parent::attach(_graph.getNotifier(Key()));
392 /// \brief Creates an item matrix for the given graph
394 /// Creates an item matrix for the given graph and assigns for each
395 /// pairs of keys the given parameter.
396 DynamicSymMatrixMap(const Graph& _graph, const Value& _val)
397 : values(size(_graph.maxId(Key()) + 1), _val) {
398 Parent::attach(_graph.getNotifier(Key()));
402 ///\brief The assignement operator.
404 ///It allow to assign a map to an other.
406 DynamicSymMatrixMap& operator=(const DynamicSymMatrixMap& _cmap){
407 return operator=<DynamicSymMatrixMap>(_cmap);
410 ///\brief Template assignement operator.
412 ///It copy the element of the given map to its own container. The
413 ///type of the two map shall be the same.
414 template <typename CMap>
415 DynamicSymMatrixMap& operator=(const CMap& _cmap){
416 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
417 typename Parent::Notifier* notifier = Parent::getNotifier();
419 for(notifier->first(first); first != INVALID;
420 notifier->next(first)){
421 for(notifier->first(second); second != first;
422 notifier->next(second)){
423 set(first, second, _cmap(first, second));
425 set(first, first, _cmap(first, first));
430 /// \brief Gives back the value assigned to the \c first - \c second
433 /// Gives back the value assigned to the \c first - \c second unordered
435 ConstReference operator()(const Key& first, const Key& second) const {
436 return values[index(Parent::getNotifier()->id(first),
437 Parent::getNotifier()->id(second))];
440 /// \brief Gives back the value assigned to the \c first - \c second
443 /// Gives back the value assigned to the \c first - \c second unordered
445 Reference operator()(const Key& first, const Key& second) {
446 return values[index(Parent::getNotifier()->id(first),
447 Parent::getNotifier()->id(second))];
450 /// \brief Setter function for the matrix map.
452 /// Setter function for the matrix map.
454 void set(const Key& first, const Key& second, const Value& val) {
455 values[index(Parent::getNotifier()->id(first),
456 Parent::getNotifier()->id(second))] = val;
461 static int index(int i, int j) {
463 return j * (j + 1) / 2 + i;
465 return i * (i + 1) / 2 + j;
469 static int size(int s) {
470 return s * (s + 1) / 2;
473 virtual void add(const Key& key) {
474 if (size(Parent::getNotifier()->id(key) + 1) >= (int)values.size()) {
475 values.resize(size(Parent::getNotifier()->id(key) + 1));
479 virtual void erase(const Key&) {}
481 virtual void build() {
482 values.resize(size(Parent::getNotifier()->maxId() + 1));
485 virtual void clear() {
490 std::vector<Value> values;
493 ///\brief Dynamic Asymmetric Matrix Map.
496 ///Dynamic Asymmetric Matrix Map. Container for store values for each
497 ///ordered pair of containers items. This data structure can store
498 ///data with different key types from different container types. It
499 ///increases the size of the container if the linked containers
500 ///content change, so it is updated automaticly whenever it is
503 ///This map meet with the concept::ReferenceMatrixMap<typename K1,
504 ///typename K2, typename V, typename R, typename CR> called as
505 ///"ReferenceMatrixMap".
507 ///\param _FirstContainer the desired type of first container. It is
508 ///ususally a Graph type, but can be any type with alteration
511 ///\param _FirstContainerItem the nested type of the
512 ///FirstContainer. It is usually a graph item as Node, Edge,
513 ///etc. This type will be the FirstKey type.
515 ///\param _SecondContainer the desired type of the second
516 ///container. It is usualy a Graph type, but can be any type with
517 ///alteration property.
519 ///\param _SecondContainerItem the nested type of the
520 ///SecondContainer. It is usually a graph item such as Node, Edge,
521 ///UEdge, etc. This type will be the SecondKey type.
523 ///\param _Value the type of the strored values in the container.
525 /// \author Janos Nagy
526 template <typename _FirstContainer, typename _FirstContainerItem,
527 typename _SecondContainer, typename _SecondContainerItem,
529 class DynamicAsymMatrixMap{
532 ///The first key type.
533 typedef _FirstContainerItem FirstKey;
535 ///The second key type.
536 typedef _SecondContainerItem SecondKey;
538 ///The value type of the map.
539 typedef _Value Value;
541 ///Indicates it is a reference map.
542 typedef True ReferenceMapTag;
546 ///\brief Proxy class for the first key type.
548 ///The proxy class belongs to the FirstKey type. It is necessary because
549 ///if one want use the same conatainer types and same nested types but on
550 ///other instances of containers than due to the type equiality of nested
551 ///types it requires a proxy mechanism.
554 ItemSetTraits<_FirstContainer,_FirstContainerItem>::
555 ItemNotifier::ObserverBase
560 friend class DynamicAsymMatrixMap;
563 FirstKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
566 ///\brief Add a new FirstKey to the map.
568 ///It adds a new FirstKey to the map. It is called by the
569 ///observer notifier and it is ovverride the add() virtual
570 ///member function in the observer base. It will call the
571 ///maps addFirstKey() function.
572 virtual void add(const FirstKey& _firstKey){
573 _owner.addFirstKey(_firstKey);
576 ///\brief Add more new FirstKey to the map.
578 ///It adds more new FirstKey to the map. It is called by the
579 ///observer notifier and it is ovverride the add() virtual
580 ///member function in the observer base. It will call the
581 ///map's addFirstKeys() function.
582 virtual void add(const std::vector<FirstKey>& _firstKeys){
583 _owner.addFirstKeys(_firstKeys);
586 ///\brief Erase a FirstKey from the map.
588 ///Erase a FirstKey from the map. It called by the observer
589 ///notifier and it overrides the erase() virtual member
590 ///function of the observer base. It will call the map's
591 ///eraseFirstKey() function.
592 virtual void erase(const FirstKey& _firstKey){
593 _owner.eraseFirstKey(_firstKey);
596 ///\brief Erase more FirstKey from the map.
598 ///Erase more FirstKey from the map. It called by the
599 ///observer notifier and it overrides the erase() virtual
600 ///member function of the observer base. It will call the
601 ///map's eraseFirstKeys() function.
602 virtual void erase(const std::vector<FirstKey>& _firstKeys){
603 _owner.eraseFirstKeys(_firstKeys);
606 ///\brief Builds the map.
608 ///It buildes the map. It called by the observer notifier
609 ///and it overrides the build() virtual member function of
610 ///the observer base. It will call the map's build()
612 virtual void build() {
614 //_owner.buildFirst();
617 ///\brief Clear the map.
619 ///It erases all items from the map. It called by the
620 ///observer notifier and it overrides the clear() virtual
621 ///memeber function of the observer base. It will call the
622 ///map's clear() function.
623 virtual void clear() {
625 //_owner.clearFirst();
629 ///The map type for it is linked.
630 DynamicAsymMatrixMap& _owner;
631 };//END OF FIRSTKEYPROXY
633 ///\brief Proxy class for the second key type.
635 ///The proxy class belongs to the SecondKey type. It is
636 ///necessary because if one want use the same conatainer types
637 ///and same nested types but on other instances of containers
638 ///than due to the type equiality of nested types it requires a
642 ItemSetTraits<_SecondContainer, _SecondContainerItem>::
643 ItemNotifier::ObserverBase {
647 friend class DynamicAsymMatrixMap;
649 SecondKeyProxy(DynamicAsymMatrixMap& _map) : _owner(_map) { }
653 ///\brief Add a new SecondKey to the map.
655 ///It adds a new SecondKey to the map. It is called by the
656 ///observer notifier and it is ovverride the add() virtual
657 ///member function in the observer base. It will call the
658 ///maps addSecondKey() function.
659 virtual void add(const SecondKey& _secondKey){
660 _owner.addSecondKey(_secondKey);
663 ///\brief Add more new SecondKey to the map.
665 ///It adds more new SecondKey to the map. It is called by
666 ///the observer notifier and it is ovverride the add()
667 ///virtual member function in the observer base. It will
668 ///call the maps addSecondKeys() function.
669 virtual void add(const std::vector<SecondKey>& _secondKeys){
670 _owner.addSecondKeys(_secondKeys);
673 ///\brief Erase a SecondKey from the map.
675 ///Erase a SecondKey from the map. It called by the observer
676 ///notifier and it overrides the erase() virtual member
677 ///function of the observer base. It will call the map's
678 ///eraseSecondKey() function.
679 virtual void erase(const SecondKey& _secondKey){
680 _owner.eraseSecondKey(_secondKey);
683 ///\brief Erase more SecondKeys from the map.
685 ///Erase more SecondKey from the map. It called by the
686 ///observer notifier and it overrides the erase() virtual
687 ///member function of the observer base. It will call the
688 ///map's eraseSecondKeys() function.
689 virtual void erase(const std::vector<SecondKey>& _secondKeys){
690 _owner.eraseSecondKeys(_secondKeys);
693 ///\brief Builds the map.
695 ///It buildes the map. It called by the observer notifier
696 ///and it overrides the build() virtual member function of
697 ///the observer base. It will call the map's build()
699 virtual void build() {
703 ///\brief Clear the map.
705 ///It erases all items from the map. It called by the
706 ///observer notifier and it overrides the clear() virtual
707 ///memeber function of the observer base. It will call the
708 ///map's clear() function.
709 virtual void clear() {
711 //_owner.clearFirst();
715 ///The type of map for which it is attached.
716 DynamicAsymMatrixMap& _owner;
717 };//END OF SECONDKEYPROXY
722 typedef std::vector<Value> Container;
724 ///The type of constainer which stores the values of the map.
725 typedef std::vector<Container> DContainer;
727 ///The std:vector type which contains the data
730 ///Member for the first proxy class
731 FirstKeyProxy _first_key_proxy;
733 ///Member for the second proxy class
734 SecondKeyProxy _second_key_proxy;
738 ///The refernce type of the map.
739 typedef typename Container::reference Reference;
741 ///The const reference type of the constainer.
742 typedef typename Container::const_reference ConstReference;
744 ///\brief Constructor what create the map for the two containers type.
746 ///Creates the matrix map and initialize the values with Value()
747 DynamicAsymMatrixMap(const _FirstContainer& _firstContainer,
748 const _SecondContainer& _secondContainer)
749 : values(DContainer(_firstContainer.maxId(FirstKey())+1,
750 Container(_secondContainer.maxId(SecondKey())+1))),
751 _first_key_proxy(*this),
752 _second_key_proxy(*this)
754 _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
755 _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
758 ///\brief Constructor what create the map for the two containers type.
760 ///Creates the matrix map and initialize the values with the given _value
761 DynamicAsymMatrixMap(const _FirstContainer& _firstContainer,
762 const _SecondContainer& _secondContainer,
764 : values(DContainer(_firstContainer.maxId(FirstKey())+1,
765 Container(_secondContainer.maxId(SecondKey())+1,
767 _first_key_proxy(*this),
768 _second_key_proxy(*this)
770 _first_key_proxy.attach(_firstContainer.getNotifier(FirstKey()));
771 _second_key_proxy.attach(_secondContainer.getNotifier(SecondKey()));
774 ///\brief Copy constructor.
776 ///The copy constructor of the map.
777 DynamicAsymMatrixMap(const DynamicAsymMatrixMap& _copy)
778 : _first_key_proxy(*this), _second_key_proxy(*this) {
779 if(_copy._first_key_proxy.attached() &&
780 _copy._second_key_proxy.attached()){
781 _first_key_proxy.attach(*_copy._first_key_proxy.getNotifier());
782 _second_key_proxy.attach(*_copy._second_key_proxy.getNotifier());
783 values = _copy.values;
789 ///Destructor what detach() from the attached objects. May this
790 ///function is not necessary because the destructor of
791 ///ObserverBase do the same.
792 ~DynamicAsymMatrixMap() {
793 if(_first_key_proxy.attached()){
794 _first_key_proxy.detach();
796 if(_second_key_proxy.attached()){
797 _second_key_proxy.detach();
801 ///\brief Gives back the value assigned to the \c first - \c
802 ///second ordered pair.
804 ///Gives back the value assigned to the \c first - \c second
806 Reference operator()(const FirstKey& _first, const SecondKey& _second) {
807 return values[_first_key_proxy.getNotifier()->id(_first)]
808 [_second_key_proxy.getNotifier()->id(_second)];
811 ///\brief Gives back the value assigned to the \c first - \c
812 ///second ordered pair.
814 ///Gives back the value assigned to the \c first - \c second
816 ConstReference operator()(const FirstKey& _first,
817 const SecondKey& _second) const {
818 return values[_first_key_proxy.getNotifier()->id(_first)]
819 [_second_key_proxy.getNotifier()->id(_second)];
822 ///\brief Setter function for this matrix map.
824 ///Setter function for this matrix map.
825 void set(const FirstKey& first, const SecondKey& second,
827 values[_first_key_proxy.getNotifier()->id(first)]
828 [_second_key_proxy.getNotifier()->id(second)] = value;
831 ///\brief The assignement operator.
833 ///It allow to assign a map to an other. It
834 DynamicAsymMatrixMap& operator=(const DynamicAsymMatrixMap& _cmap){
835 return operator=<DynamicAsymMatrixMap>(_cmap);
838 ///\brief Template assignement operator.
840 ///It copy the element of the given map to its own container. The
841 ///type of the two map shall be the same.
842 template <typename CMap>
843 DynamicAsymMatrixMap& operator=(const CMap& _cdmap){
844 checkConcept<concept::ReadMatrixMap<FirstKey, SecondKey, Value>, CMap>();
845 const typename FirstKeyProxy::Notifier* notifierFirstKey =
846 _first_key_proxy.getNotifier();
847 const typename SecondKeyProxy::Notifier* notifierSecondKey =
848 _second_key_proxy.getNotifier();
850 SecondKey itemSecond;
851 for(notifierFirstKey->first(itemFirst); itemFirst != INVALID;
852 notifierFirstKey->next(itemFirst)){
853 for(notifierSecondKey->first(itemSecond); itemSecond != INVALID;
854 notifierSecondKey->next(itemSecond)){
855 set(itemFirst, itemSecond, _cdmap(itemFirst,itemSecond));
863 ///\brief Add a new FirstKey to the map.
865 ///It adds a new FirstKey to the map. It is called by the observer
866 ///class belongs to the FirstKey type.
867 void addFirstKey(const FirstKey& firstKey) {
868 int size = (int)values.size();
869 if( _first_key_proxy.getNotifier()->id(firstKey)+1 >= size ){
870 values.resize(_first_key_proxy.getNotifier()->id(firstKey)+1);
871 if( (int)values[0].size() != 0 ){
872 int innersize = (int)values[0].size();
873 for(int i=size; i!=(int)values.size();++i){
874 (values[i]).resize(innersize);
876 }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
877 int innersize = _second_key_proxy.getNotifier()->maxId();
878 for(int i = 0; i != (int)values.size(); ++i){
879 values[0].resize(innersize);
885 ///\brief Adds more new FirstKeys to the map.
887 ///It adds more new FirstKeys to the map. It called by the
888 ///observer class belongs to the FirstKey type.
889 void addFirstKeys(const std::vector<FirstKey>& firstKeys){
890 int max = values.size() - 1;
891 for(int i=0; i != (int)firstKeys.size(); ++i){
892 int id = _first_key_proxy.getNotifier()->id(firstKeys[i]);
897 int size = (int)values.size();
899 values.resize(max + 1);
900 if( (int)values[0].size() != 0){
901 int innersize = (int)values[0].size();
902 for(int i = size; i != (max + 1); ++i){
903 values[i].resize(innersize);
905 }else if(_second_key_proxy.getNotifier()->maxId() >= 0){
906 int innersize = _second_key_proxy.getNotifier()->maxId();
907 for(int i = 0; i != (int)values.size(); ++i){
908 values[i].resize(innersize);
914 ///\brief Add a new SecondKey to the map.
916 ///It adds a new SecondKey to the map. It is called by the
917 ///observer class belongs to the SecondKey type.
918 void addSecondKey(const SecondKey& secondKey) {
919 if(values.size() == 0){
922 int id = _second_key_proxy.getNotifier()->id(secondKey);
923 if(id >= (int)values[0].size()){
924 for(int i=0;i!=(int)values.size();++i){
925 values[i].resize(id+1);
930 ///\brief Adds more new SecondKeys to the map.
932 ///It adds more new SecondKeys to the map. It called by the
933 ///observer class belongs to the SecondKey type.
934 void addSecondKeys(const std::vector<SecondKey>& secondKeys){
935 if(values.size() == 0){
938 int max = values[0].size();
939 for(int i = 0; i != (int)secondKeys.size(); ++i){
940 int id = _second_key_proxy.getNotifier()->id(secondKeys[i]);
945 if(max > (int)values[0].size()){
946 for(int i = 0; i != (int)values.size(); ++i){
947 values[i].resize(max + 1);
952 ///\brief Erase a FirstKey from the map.
954 ///Erase a FirstKey from the map. It called by the observer
955 ///class belongs to the FirstKey type.
956 void eraseFirstKey(const FirstKey& first) {
957 int id = _first_key_proxy.getNotifier()->id(first);
958 for(int i = 0; i != (int)values[id].size(); ++i){
959 values[id][i] = Value();
963 ///\brief Erase more FirstKey from the map.
965 ///Erase more FirstKey from the map. It called by the observer
966 ///class belongs to the FirstKey type.
967 void eraseFirstKeys(const std::vector<FirstKey>& firstKeys) {
968 for(int j = 0; j != (int)firstKeys.size(); ++j){
969 int id = _first_key_proxy.getNotifier()->id(firstKeys[j]);
970 for(int i = 0; i != (int)values[id].size(); ++i){
971 values[id][i] = Value();
976 ///\brief Erase a SecondKey from the map.
978 ///Erase a SecondKey from the map. It called by the observer class
979 ///belongs to the SecondKey type.
980 void eraseSecondKey(const SecondKey& second) {
981 if(values.size() == 0){
984 int id = _second_key_proxy.getNotifier()->id(second);
985 for(int i = 0; i != (int)values.size(); ++i){
986 values[i][id] = Value();
990 ///\brief Erase more SecondKey from the map.
992 ///Erase more SecondKey from the map. It called by the observer
993 ///class belongs to the SecondKey type.
994 void eraseSecondKeys(const std::vector<SecondKey>& secondKeys) {
995 if(values.size() == 0){
998 for(int j = 0; j != (int)secondKeys.size(); ++j){
999 int id = _second_key_proxy.getNotifier()->id(secondKeys[j]);
1000 for(int i = 0; i != (int)values.size(); ++i){
1001 values[i][id] = Value();
1006 ///\brief Builds the map.
1008 ///It buildes the map. It is called by the observer class belongs
1009 ///to the FirstKey or SecondKey type.
1011 values.resize(_first_key_proxy.getNotifier()->maxId());
1012 for(int i=0; i!=(int)values.size(); ++i){
1013 values[i].resize(_second_key_proxy.getNotifier()->maxId());
1017 ///\brief Clear the map.
1019 ///It erases all items from the map. It is called by the observer class
1020 ///belongs to the FirstKey or SecondKey type.
1022 for(int i=0; i!=(int)values.size(); ++i) {