0
2
0
| ... | ... |
@@ -28,48 +28,50 @@ |
| 28 | 28 |
|
| 29 | 29 |
//\file |
| 30 | 30 |
//\brief Extenders for iterable maps. |
| 31 | 31 |
|
| 32 | 32 |
namespace lemon {
|
| 33 | 33 |
|
| 34 | 34 |
// \ingroup graphbits |
| 35 | 35 |
// |
| 36 | 36 |
// \brief Extender for maps |
| 37 | 37 |
template <typename _Map> |
| 38 | 38 |
class MapExtender : public _Map {
|
| 39 | 39 |
typedef _Map Parent; |
| 40 | 40 |
typedef typename Parent::GraphType GraphType; |
| 41 | 41 |
|
| 42 | 42 |
public: |
| 43 | 43 |
|
| 44 | 44 |
typedef MapExtender Map; |
| 45 | 45 |
typedef typename Parent::Key Item; |
| 46 | 46 |
|
| 47 | 47 |
typedef typename Parent::Key Key; |
| 48 | 48 |
typedef typename Parent::Value Value; |
| 49 | 49 |
typedef typename Parent::Reference Reference; |
| 50 | 50 |
typedef typename Parent::ConstReference ConstReference; |
| 51 | 51 |
|
| 52 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
| 53 |
|
|
| 52 | 54 |
class MapIt; |
| 53 | 55 |
class ConstMapIt; |
| 54 | 56 |
|
| 55 | 57 |
friend class MapIt; |
| 56 | 58 |
friend class ConstMapIt; |
| 57 | 59 |
|
| 58 | 60 |
public: |
| 59 | 61 |
|
| 60 | 62 |
MapExtender(const GraphType& graph) |
| 61 | 63 |
: Parent(graph) {}
|
| 62 | 64 |
|
| 63 | 65 |
MapExtender(const GraphType& graph, const Value& value) |
| 64 | 66 |
: Parent(graph, value) {}
|
| 65 | 67 |
|
| 66 | 68 |
private: |
| 67 | 69 |
MapExtender& operator=(const MapExtender& cmap) {
|
| 68 | 70 |
return operator=<MapExtender>(cmap); |
| 69 | 71 |
} |
| 70 | 72 |
|
| 71 | 73 |
template <typename CMap> |
| 72 | 74 |
MapExtender& operator=(const CMap& cmap) {
|
| 73 | 75 |
Parent::operator=(cmap); |
| 74 | 76 |
return *this; |
| 75 | 77 |
} |
| ... | ... |
@@ -170,48 +172,50 @@ |
| 170 | 172 |
protected: |
| 171 | 173 |
const Map& map; |
| 172 | 174 |
|
| 173 | 175 |
}; |
| 174 | 176 |
}; |
| 175 | 177 |
|
| 176 | 178 |
// \ingroup graphbits |
| 177 | 179 |
// |
| 178 | 180 |
// \brief Extender for maps which use a subset of the items. |
| 179 | 181 |
template <typename _Graph, typename _Map> |
| 180 | 182 |
class SubMapExtender : public _Map {
|
| 181 | 183 |
typedef _Map Parent; |
| 182 | 184 |
typedef _Graph GraphType; |
| 183 | 185 |
|
| 184 | 186 |
public: |
| 185 | 187 |
|
| 186 | 188 |
typedef SubMapExtender Map; |
| 187 | 189 |
typedef typename Parent::Key Item; |
| 188 | 190 |
|
| 189 | 191 |
typedef typename Parent::Key Key; |
| 190 | 192 |
typedef typename Parent::Value Value; |
| 191 | 193 |
typedef typename Parent::Reference Reference; |
| 192 | 194 |
typedef typename Parent::ConstReference ConstReference; |
| 193 | 195 |
|
| 196 |
typedef typename Parent::ReferenceMapTag ReferenceMapTag; |
|
| 197 |
|
|
| 194 | 198 |
class MapIt; |
| 195 | 199 |
class ConstMapIt; |
| 196 | 200 |
|
| 197 | 201 |
friend class MapIt; |
| 198 | 202 |
friend class ConstMapIt; |
| 199 | 203 |
|
| 200 | 204 |
public: |
| 201 | 205 |
|
| 202 | 206 |
SubMapExtender(const GraphType& _graph) |
| 203 | 207 |
: Parent(_graph), graph(_graph) {}
|
| 204 | 208 |
|
| 205 | 209 |
SubMapExtender(const GraphType& _graph, const Value& _value) |
| 206 | 210 |
: Parent(_graph, _value), graph(_graph) {}
|
| 207 | 211 |
|
| 208 | 212 |
private: |
| 209 | 213 |
SubMapExtender& operator=(const SubMapExtender& cmap) {
|
| 210 | 214 |
return operator=<MapExtender>(cmap); |
| 211 | 215 |
} |
| 212 | 216 |
|
| 213 | 217 |
template <typename CMap> |
| 214 | 218 |
SubMapExtender& operator=(const CMap& cmap) {
|
| 215 | 219 |
checkConcept<concepts::ReadMap<Key, Value>, CMap>(); |
| 216 | 220 |
Item it; |
| 217 | 221 |
for (graph.first(it); it != INVALID; graph.next(it)) {
|
| ... | ... |
@@ -161,49 +161,50 @@ |
| 161 | 161 |
/// (The type of objects associated with the keys). |
| 162 | 162 |
typedef T Value; |
| 163 | 163 |
/// The reference type of the map. |
| 164 | 164 |
typedef R Reference; |
| 165 | 165 |
/// The const reference type of the map. |
| 166 | 166 |
typedef CR ConstReference; |
| 167 | 167 |
|
| 168 | 168 |
public: |
| 169 | 169 |
|
| 170 | 170 |
/// Returns a reference to the value associated with the given key. |
| 171 | 171 |
Reference operator[](const Key &) {
|
| 172 | 172 |
return *static_cast<Value *>(0); |
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 | 175 |
/// Returns a const reference to the value associated with the given key. |
| 176 | 176 |
ConstReference operator[](const Key &) const {
|
| 177 | 177 |
return *static_cast<Value *>(0); |
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
/// Sets the value associated with the given key. |
| 181 | 181 |
void set(const Key &k,const Value &t) { operator[](k)=t; }
|
| 182 | 182 |
|
| 183 | 183 |
template<typename _ReferenceMap> |
| 184 | 184 |
struct Constraints {
|
| 185 |
|
|
| 185 |
typename enable_if<typename _ReferenceMap::ReferenceMapTag, void>::type |
|
| 186 |
constraints() {
|
|
| 186 | 187 |
checkConcept<ReadWriteMap<K, T>, _ReferenceMap >(); |
| 187 | 188 |
ref = m[key]; |
| 188 | 189 |
m[key] = val; |
| 189 | 190 |
m[key] = ref; |
| 190 | 191 |
m[key] = cref; |
| 191 | 192 |
own_ref = m[own_key]; |
| 192 | 193 |
m[own_key] = own_val; |
| 193 | 194 |
m[own_key] = own_ref; |
| 194 | 195 |
m[own_key] = own_cref; |
| 195 | 196 |
m[key] = m[own_key]; |
| 196 | 197 |
m[own_key] = m[key]; |
| 197 | 198 |
} |
| 198 | 199 |
const Key& key; |
| 199 | 200 |
Value& val; |
| 200 | 201 |
Reference ref; |
| 201 | 202 |
ConstReference cref; |
| 202 | 203 |
const typename _ReferenceMap::Key& own_key; |
| 203 | 204 |
typename _ReferenceMap::Value& own_val; |
| 204 | 205 |
typename _ReferenceMap::Reference own_ref; |
| 205 | 206 |
typename _ReferenceMap::ConstReference own_cref; |
| 206 | 207 |
_ReferenceMap& m; |
| 207 | 208 |
}; |
| 208 | 209 |
}; |
| 209 | 210 |
|
0 comments (0 inline)