matrix_maps.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  *
00003  * This file is a part of LEMON, a generic C++ optimization library
00004  *
00005  * Copyright (C) 2003-2006
00006  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00007  * (Egervary Research Group on Combinatorial Optimization, EGRES).
00008  *
00009  * Permission to use, modify and distribute this software is granted
00010  * provided that this copyright notice appears in all copies. For
00011  * precise terms see the accompanying LICENSE file.
00012  *
00013  * This software is provided "AS IS" with no warranty of any kind,
00014  * express or implied, and with no claim as to its suitability for any
00015  * purpose.
00016  *
00017  */
00018 
00019 #ifndef LEMON_CONCEPT_MATRIX_MAPS_H
00020 #define LEMON_CONCEPT_MATRIX_MAPS_H
00021 
00022 #include <lemon/utility.h>
00023 #include <lemon/concept_check.h>
00024 
00028 
00029 namespace lemon {
00030 
00031   namespace concept {
00032   
00035 
00037     template <typename K1, typename K2, typename V>
00038     class ReadMatrixMap
00039     {
00040     public:
00042       typedef K1 FirstKey;    
00044       typedef K2 SecondKey;    
00047       typedef V Value;
00048 
00049       // \bug Value don't need to be default constructible.
00051       Value operator()(const FirstKey&, const SecondKey&) const {
00052         return Value();
00053       }
00054 
00055       template <typename _ReadMatrixMap>
00056       struct Constraints {
00057 
00058         void constraints() {
00059           Value val = m(first_key, second_key);
00060           val = m(first_key, second_key);
00061           typename _ReadMatrixMap::Value own_val = 
00062             m(own_first_key, own_second_key); 
00063           own_val = m(own_first_key, own_second_key);
00064           ignore_unused_variable_warning(val);
00065           ignore_unused_variable_warning(own_val);
00066         }
00067 
00068         FirstKey& first_key;
00069         SecondKey& second_key;  
00070         typename _ReadMatrixMap::FirstKey& own_first_key;
00071         typename _ReadMatrixMap::SecondKey& own_second_key;
00072         _ReadMatrixMap& m;
00073       };
00074       
00075     };
00076 
00077 
00079     template <typename K1, typename K2, typename V>
00080     class WriteMatrixMap {
00081     public:
00083       typedef K1 FirstKey;    
00085       typedef K2 SecondKey;    
00088       typedef V Value;
00089 
00091       void set(const FirstKey&, const SecondKey& ,const Value&) {}
00092 
00093       template <typename _WriteMatrixMap>
00094       struct Constraints {
00095         void constraints() {
00096           // No constraints for constructor.
00097           m.set(first_key, second_key, val);
00098           m.set(own_first_key, own_second_key, own_val);
00099         }
00100 
00101         Value& val;
00102         typename _WriteMatrixMap::Value own_val;
00103         FirstKey& first_key;
00104         SecondKey& second_key;
00105         typename _WriteMatrixMap::FirstKey& own_first_key;
00106         typename _WriteMatrixMap::SecondKey& own_second_key;
00107         _WriteMatrixMap& m;
00108 
00109       };
00110     };
00111 
00113     template<typename K1, typename K2, typename V>
00114     class ReadWriteMatrixMap 
00115       : public ReadMatrixMap<K1, K2, V>, public WriteMatrixMap<K1, K2, V> {
00116     public:
00118       typedef K1 FirstKey;    
00120       typedef K2 SecondKey;    
00123       typedef V Value;
00124 
00126       Value operator()(const FirstKey&, const SecondKey&) const { 
00127         return Value(); 
00128       }
00130       void set(const FirstKey&, const SecondKey& ,const Value&) {}
00131 
00132       template<typename _ReadWriteMatrixMap>
00133       struct Constraints {
00134         void constraints() {
00135           checkConcept<ReadMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
00136           checkConcept<WriteMatrixMap<K1, K2, V>, _ReadWriteMatrixMap >();
00137         }
00138       };
00139     };
00140   
00141   
00143     template<typename K1, typename K2, typename V, typename R, typename CR>
00144     class ReferenceMatrixMap : public ReadWriteMatrixMap<K1, K2, V>
00145     {
00146     public:
00148       typedef True ReferenceMapTag;
00150       typedef K1 FirstKey;    
00152       typedef K1 SecondKey;    
00154       typedef V Value;
00156       typedef R Reference;
00158       typedef CR ConstReference;
00159 
00160     protected:
00161       Value tmp;
00162     public:
00163 
00165       Reference operator()(const FirstKey&, const SecondKey&) { 
00166         return tmp; 
00167       }
00169       ConstReference operator()(const FirstKey&, const SecondKey&) const { 
00170         return tmp; 
00171       }
00173       void set(const FirstKey&, const SecondKey& ,const Value&) {}
00174 
00175       // \todo rethink this concept
00176       template<typename _ReferenceMatrixMap>
00177       struct ReferenceMapConcept {
00178 
00179         void constraints() {
00180           checkConcept<ReadWriteMatrixMap, _ReferenceMatrixMap >();
00181           m(first_key, second_key) = val;
00182           val  = m(first_key, second_key);
00183           m(first_key, second_key) = ref;
00184           ref = m(first_key, second_key);
00185           m(own_first_key, own_second_key) = own_val;
00186           own_val  = m(own_first_key, own_second_key);
00187           m(own_first_key, own_second_key) = own_ref;
00188           own_ref = m(own_first_key, own_second_key); 
00189         }
00190 
00191         typename _ReferenceMatrixMap::Key& own_first_key;
00192         typename _ReferenceMatrixMap::Key& own_second_key;
00193         typename _ReferenceMatrixMap::Value& own_val;
00194         typename _ReferenceMatrixMap::Reference& own_ref;
00195         FirstKey& first_key;
00196         SecondKey& second_key;
00197         Value& val;
00198         Reference& ref;
00199         _ReferenceMatrixMap& m;
00200       };
00201     };
00202 
00203     // @}
00204 
00205   } //namespace concept
00206 } //namespace lemon
00207 #endif // LEMON_CONCEPT_MATRIX_MAPS_H

Generated on Fri Feb 3 18:39:12 2006 for LEMON by  doxygen 1.4.6