Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

maps.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * src/lemon/concept/maps.h - Part of LEMON, a generic C++ optimization library
00003  *
00004  * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
00005  * (Egervary Combinatorial Optimization Research Group, EGRES).
00006  *
00007  * Permission to use, modify and distribute this software is granted
00008  * provided that this copyright notice appears in all copies. For
00009  * precise terms see the accompanying LICENSE file.
00010  *
00011  * This software is provided "AS IS" with no warranty of any kind,
00012  * express or implied, and with no claim as to its suitability for any
00013  * purpose.
00014  *
00015  */
00016 
00017 #ifndef LEMON_CONCEPT_MAPS_H
00018 #define LEMON_CONCEPT_MAPS_H
00019 
00020 #include <lemon/concept_check.h>
00021 
00025 
00026 namespace lemon {
00027 
00028   namespace concept {
00029   
00032 
00034     template<typename K, typename T>
00035     class ReadMap
00036     {
00037     public:
00039       typedef K Key;    
00041       typedef T Value;
00042 
00043       // \bug Value don't need to be default constructible.
00045       Value operator[](const Key &) const {return Value();}
00046 
00047       template<typename _ReadMap>
00048       struct Constraints {
00049 
00050         void constraints() {
00051           Value val = m[key];
00052           val = m[key];
00053           typename _ReadMap::Value own_val = m[own_key]; 
00054           own_val = m[own_key]; 
00055 
00056           ignore_unused_variable_warning(val);
00057           ignore_unused_variable_warning(own_val);
00058           ignore_unused_variable_warning(key);
00059         }
00060         Key& key;
00061         typename _ReadMap::Key& own_key;
00062         _ReadMap& m;
00063       };
00064       
00065     };
00066 
00067 
00069     template<typename K, typename T>
00070     class WriteMap
00071     {
00072     public:
00074       typedef K Key;    
00076       typedef T Value;
00077 
00079       void set(const Key &k,const Value &t) {}
00080 
00082       WriteMap() {}
00083 
00084       template <typename _WriteMap>
00085       struct Constraints {
00086         void constraints() {
00087           // No constraints for constructor.
00088           m.set(key, val);
00089           m.set(own_key, own_val);
00090           ignore_unused_variable_warning(key);
00091           ignore_unused_variable_warning(val);
00092           ignore_unused_variable_warning(own_key);
00093           ignore_unused_variable_warning(own_val);
00094         }
00095 
00096         Value& val;
00097         typename _WriteMap::Value own_val;
00098         Key& key;
00099         typename _WriteMap::Key& own_key;
00100         WriteMap& m;
00101 
00102       };
00103     };
00104 
00106     template<typename K, typename T>
00107     class ReadWriteMap : public ReadMap<K,T>,
00108                             public WriteMap<K,T>
00109     {
00110     public:
00112       typedef K Key;    
00114       typedef T Value;
00115 
00117       Value operator[](const Key &k) const {return Value();}
00119       void set(const Key &k,const Value &t) {}
00120 
00121       template<typename _ReadWriteMap>
00122       struct Constraints {
00123         void constraints() {
00124           checkConcept<ReadMap<K, T>, _ReadWriteMap >();
00125           checkConcept<ReadMap<K, T>, _ReadWriteMap >();
00126         }
00127       };
00128     };
00129   
00130   
00132     template<typename K, typename T, typename R, typename CR>
00133     class ReferenceMap : public ReadWriteMap<K,T>
00134     {
00135     public:
00137       typedef K Key;    
00139       typedef T Value;
00141       typedef R Reference;
00143       typedef CR ConstReference;
00144 
00145     protected:
00146       Value tmp;
00147     public:
00148 
00150       Reference operator[](const Key &i) { return tmp; }
00152       ConstReference operator[](const Key &i) const
00153       { return tmp; }
00155       void set(const Key &k,const Value &t) { operator[](k)=t; }
00156 
00157       // \todo rethink this concept
00158       template<typename _ReferenceMap>
00159       struct ReferenceMapConcept {
00160 
00161         void constraints() {
00162           checkConcept<ReadWriteMap, _ReferenceMap >();
00163           m[key] = val;
00164           val  = m[key];
00165           m[key] = ref;
00166           ref = m[key];
00167           m[own_key] = own_val;
00168           own_val  = m[own_key];
00169           m[own_key] = own_ref;
00170           own_ref = m[own_key];           
00171         }
00172 
00173         typename _ReferenceMap::Key& own_key;
00174         typename _ReferenceMap::Value& own_val;
00175         typename _ReferenceMap::Reference& own_ref;
00176         Key& key;
00177         Value& val;
00178         Reference& ref;
00179         ReferenceMap& m;
00180       };
00181     };
00182 
00183     // @}
00184 
00185   } //namespace concept
00186 } //namespace lemon
00187 #endif // LEMON_CONCEPT_MAPS_H

Generated on Sat Mar 19 10:58:40 2005 for LEMON by  doxygen 1.4.1