| 1 | 1 |
/* -*- C++ -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_CONCEPT_MAPS_H |
| 20 | 20 |
#define LEMON_CONCEPT_MAPS_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/bits/utility.h> |
| 23 | 23 |
#include <lemon/concept_check.h> |
| 24 | 24 |
|
| 25 | 25 |
///\ingroup concept |
| 26 | 26 |
///\file |
| 27 |
///\brief |
|
| 27 |
///\brief The concept of maps. |
|
| 28 | 28 |
|
| 29 | 29 |
namespace lemon {
|
| 30 | 30 |
|
| 31 | 31 |
namespace concepts {
|
| 32 | 32 |
|
| 33 | 33 |
/// \addtogroup concept |
| 34 | 34 |
/// @{
|
| 35 | 35 |
|
| 36 | 36 |
/// Readable map concept |
| 37 | 37 |
|
| 38 | 38 |
/// Readable map concept. |
| 39 | 39 |
/// |
| 40 | 40 |
template<typename K, typename T> |
| 41 | 41 |
class ReadMap |
| 42 | 42 |
{
|
| 43 | 43 |
public: |
| 44 | 44 |
/// The key type of the map. |
| 45 | 45 |
typedef K Key; |
| 46 | 46 |
/// The value type of the map. (The type of objects associated with the keys). |
| 47 | 47 |
typedef T Value; |
| 48 | 48 |
|
| 49 | 49 |
/// Returns the value associated with the given key. |
| 50 | 50 |
Value operator[](const Key &) const {
|
| 51 | 51 |
return *static_cast<Value *>(0); |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 | 54 |
template<typename _ReadMap> |
| 55 | 55 |
struct Constraints {
|
| 56 | 56 |
void constraints() {
|
| 57 | 57 |
Value val = m[key]; |
| 58 | 58 |
val = m[key]; |
| 59 | 59 |
typename _ReadMap::Value own_val = m[own_key]; |
| 60 | 60 |
own_val = m[own_key]; |
| 61 | 61 |
|
| 62 | 62 |
ignore_unused_variable_warning(key); |
| 63 | 63 |
ignore_unused_variable_warning(val); |
| 64 | 64 |
ignore_unused_variable_warning(own_key); |
| 65 | 65 |
ignore_unused_variable_warning(own_val); |
| 66 | 66 |
} |
| 67 | 67 |
const Key& key; |
| 68 | 68 |
const typename _ReadMap::Key& own_key; |
| 69 | 69 |
const _ReadMap& m; |
| 70 | 70 |
}; |
| 71 | 71 |
|
| 72 | 72 |
}; |
| 73 | 73 |
|
| 74 | 74 |
|
| 75 | 75 |
/// Writable map concept |
| 76 | 76 |
|
| 77 | 77 |
/// Writable map concept. |
| 78 | 78 |
/// |
| 79 | 79 |
template<typename K, typename T> |
| 80 | 80 |
class WriteMap |
| 81 | 81 |
{
|
| 82 | 82 |
public: |
| 83 | 83 |
/// The key type of the map. |
| 84 | 84 |
typedef K Key; |
| 85 | 85 |
/// The value type of the map. (The type of objects associated with the keys). |
| 86 | 86 |
typedef T Value; |
| 87 | 87 |
|
| 88 | 88 |
/// Sets the value associated with the given key. |
| 89 | 89 |
void set(const Key &, const Value &) {}
|
| 90 | 90 |
|
| 91 | 91 |
/// Default constructor. |
| 92 | 92 |
WriteMap() {}
|
| 93 | 93 |
|
| 94 | 94 |
template <typename _WriteMap> |
| 95 | 95 |
struct Constraints {
|
| 96 | 96 |
void constraints() {
|
| 97 | 97 |
m.set(key, val); |
| 98 | 98 |
m.set(own_key, own_val); |
| 99 | 99 |
|
| 100 | 100 |
ignore_unused_variable_warning(key); |
| 101 | 101 |
ignore_unused_variable_warning(val); |
| 102 | 102 |
ignore_unused_variable_warning(own_key); |
| 103 | 103 |
ignore_unused_variable_warning(own_val); |
| 104 | 104 |
} |
| 105 | 105 |
const Key& key; |
| 106 | 106 |
const Value& val; |
| 107 | 107 |
const typename _WriteMap::Key& own_key; |
| 108 |
const typename _WriteMap::Value own_val; |
|
| 108 |
const typename _WriteMap::Value& own_val; |
|
| 109 | 109 |
_WriteMap& m; |
| 110 | 110 |
}; |
| 111 | 111 |
}; |
| 112 | 112 |
|
| 113 | 113 |
/// Read/writable map concept |
| 114 | 114 |
|
| 115 | 115 |
/// Read/writable map concept. |
| 116 | 116 |
/// |
| 117 | 117 |
template<typename K, typename T> |
| 118 | 118 |
class ReadWriteMap : public ReadMap<K,T>, |
| 119 | 119 |
public WriteMap<K,T> |
| 120 | 120 |
{
|
| 121 | 121 |
public: |
| 122 | 122 |
/// The key type of the map. |
| 123 | 123 |
typedef K Key; |
| 124 | 124 |
/// The value type of the map. (The type of objects associated with the keys). |
| 125 | 125 |
typedef T Value; |
| 126 | 126 |
|
| 127 | 127 |
/// Returns the value associated with the given key. |
| 128 | 128 |
Value operator[](const Key &) const {
|
| 129 | 129 |
return *static_cast<Value *>(0); |
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
/// Sets the value associated with the given key. |
| 133 | 133 |
void set(const Key &, const Value &) {}
|
| 134 | 134 |
|
| 135 | 135 |
template<typename _ReadWriteMap> |
| 136 | 136 |
struct Constraints {
|
| 137 | 137 |
void constraints() {
|
| 138 | 138 |
checkConcept<ReadMap<K, T>, _ReadWriteMap >(); |
| 139 | 139 |
checkConcept<WriteMap<K, T>, _ReadWriteMap >(); |
| 140 | 140 |
} |
| 141 | 141 |
}; |
| 142 | 142 |
}; |
| 143 | 143 |
|
| 144 | 144 |
|
| 145 | 145 |
/// Dereferable map concept |
| 146 | 146 |
|
| 147 | 147 |
/// Dereferable map concept. |
| 148 | 148 |
/// |
| 149 | 149 |
template<typename K, typename T, typename R, typename CR> |
| 150 | 150 |
class ReferenceMap : public ReadWriteMap<K,T> |
| 151 | 151 |
{
|
| 152 | 152 |
public: |
| 153 | 153 |
/// Tag for reference maps. |
| 154 | 154 |
typedef True ReferenceMapTag; |
| 155 | 155 |
/// The key type of the map. |
| 156 | 156 |
typedef K Key; |
0 comments (0 inline)