00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef LEMON_CONCEPT_MAPS_H
00020 #define LEMON_CONCEPT_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 K, typename T>
00038 class ReadMap
00039 {
00040 public:
00042 typedef K Key;
00044 typedef T Value;
00045
00046
00048 Value operator[](const Key &) const {return Value();}
00049
00050 template<typename _ReadMap>
00051 struct Constraints {
00052
00053 void constraints() {
00054 Value val = m[key];
00055 val = m[key];
00056 typename _ReadMap::Value own_val = m[own_key];
00057 own_val = m[own_key];
00058
00059 ignore_unused_variable_warning(val);
00060 ignore_unused_variable_warning(own_val);
00061 ignore_unused_variable_warning(key);
00062 }
00063 Key& key;
00064 typename _ReadMap::Key& own_key;
00065 _ReadMap& m;
00066 };
00067
00068 };
00069
00070
00072 template<typename K, typename T>
00073 class WriteMap
00074 {
00075 public:
00077 typedef K Key;
00079 typedef T Value;
00080
00082 void set(const Key &,const Value &) {}
00083
00085 WriteMap() {}
00086
00087 template <typename _WriteMap>
00088 struct Constraints {
00089 void constraints() {
00090
00091 m.set(key, val);
00092 m.set(own_key, own_val);
00093 ignore_unused_variable_warning(key);
00094 ignore_unused_variable_warning(val);
00095 ignore_unused_variable_warning(own_key);
00096 ignore_unused_variable_warning(own_val);
00097 }
00098
00099 Value& val;
00100 typename _WriteMap::Value own_val;
00101 Key& key;
00102 typename _WriteMap::Key& own_key;
00103 _WriteMap& m;
00104
00105 };
00106 };
00107
00109 template<typename K, typename T>
00110 class ReadWriteMap : public ReadMap<K,T>,
00111 public WriteMap<K,T>
00112 {
00113 public:
00115 typedef K Key;
00117 typedef T Value;
00118
00120 Value operator[](const Key &) const {return Value();}
00122 void set(const Key & ,const Value &) {}
00123
00124 template<typename _ReadWriteMap>
00125 struct Constraints {
00126 void constraints() {
00127 checkConcept<ReadMap<K, T>, _ReadWriteMap >();
00128 checkConcept<WriteMap<K, T>, _ReadWriteMap >();
00129 }
00130 };
00131 };
00132
00133
00135 template<typename K, typename T, typename R, typename CR>
00136 class ReferenceMap : public ReadWriteMap<K,T>
00137 {
00138 public:
00140 typedef True ReferenceMapTag;
00142 typedef K Key;
00144 typedef T Value;
00146 typedef R Reference;
00148 typedef CR ConstReference;
00149
00150 protected:
00151 Value tmp;
00152 public:
00153
00155 Reference operator[](const Key &) { return tmp; }
00157 ConstReference operator[](const Key &) const
00158 { return tmp; }
00160 void set(const Key &k,const Value &t) { operator[](k)=t; }
00161
00162
00163 template<typename _ReferenceMap>
00164 struct ReferenceMapConcept {
00165
00166 void constraints() {
00167 checkConcept<ReadWriteMap, _ReferenceMap >();
00168 m[key] = val;
00169 val = m[key];
00170 m[key] = ref;
00171 ref = m[key];
00172 m[own_key] = own_val;
00173 own_val = m[own_key];
00174 m[own_key] = own_ref;
00175 own_ref = m[own_key];
00176 }
00177
00178 typename _ReferenceMap::Key& own_key;
00179 typename _ReferenceMap::Value& own_val;
00180 typename _ReferenceMap::Reference& own_ref;
00181 Key& key;
00182 Value& val;
00183 Reference& ref;
00184 _ReferenceMap& m;
00185 };
00186 };
00187
00188
00189
00190 }
00191 }
00192 #endif // LEMON_CONCEPT_MAPS_H