gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 1 0
merge default
0 files changed with 10 insertions and 10 deletions:
↑ Collapse diff ↑
Show white space 192 line context
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-2007
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 27
///\brief Map concepts checking classes for testing and documenting.
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
      /// Map's key type.
44
      /// The key type of the map.
45 45
      typedef K Key;    
46
      /// Map's value type. (The type of objects associated with the keys).
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 a key.
50 50

	
51 51
      /// \bug Value shouldn't need to be default constructible.
52 52
      ///
53 53
      Value operator[](const Key &) const {return Value();}
54 54

	
55 55
      template<typename _ReadMap>
56 56
      struct Constraints {
57 57

	
58 58
	void constraints() {
59 59
	  Value val = m[key];
60 60
	  val = m[key];
61 61
	  typename _ReadMap::Value own_val = m[own_key]; 
62 62
	  own_val = m[own_key]; 
63 63

	
64 64
	  ignore_unused_variable_warning(val);
65 65
	  ignore_unused_variable_warning(own_val);
66 66
	  ignore_unused_variable_warning(key);
67 67
	}
68 68
	Key& key;
69 69
	typename _ReadMap::Key& own_key;
70 70
	_ReadMap& m;
71 71
      };
72 72
      
73 73
    };
74 74

	
75 75

	
76 76
    /// Writable map concept
77 77
    
78 78
    /// Writable map concept.
79 79
    ///
80 80
    template<typename K, typename T>
81 81
    class WriteMap
82 82
    {
83 83
    public:
84
      /// Map's key type.
84
      /// The key type of the map.
85 85
      typedef K Key;    
86
      /// Map's value type. (The type of objects associated with the keys).
86
      /// The value type of the map. (The type of objects associated with the keys).
87 87
      typedef T Value;
88 88

	
89 89
      /// Sets the value associated with a key.
90 90
      void set(const Key &,const Value &) {}
91 91

	
92 92
      ///Default constructor
93 93
      WriteMap() {}
94 94

	
95 95
      template <typename _WriteMap>
96 96
      struct Constraints {
97 97
	void constraints() {
98 98
	  // No constraints for constructor.
99 99
	  m.set(key, val);
100 100
	  m.set(own_key, own_val);
101 101
	  ignore_unused_variable_warning(key);
102 102
	  ignore_unused_variable_warning(val);
103 103
	  ignore_unused_variable_warning(own_key);
104 104
	  ignore_unused_variable_warning(own_val);
105 105
	}
106 106

	
107 107
	Value& val;
108 108
	typename _WriteMap::Value own_val;
109 109
	Key& key;
110 110
	typename _WriteMap::Key& own_key;
111 111
	_WriteMap& m;
112 112

	
113 113
      };
114 114
    };
115 115

	
116 116
    /// Read/Writable map concept
117 117
    
118 118
    /// Read/writable map concept.
119 119
    ///
120 120
    template<typename K, typename T>
121 121
    class ReadWriteMap : public ReadMap<K,T>,
122 122
			    public WriteMap<K,T>
123 123
    {
124 124
    public:
125
      /// Map's key type.
125
      /// The key type of the map.
126 126
      typedef K Key;    
127
      /// Map's value type. (The type of objects associated with the keys).
127
      /// The value type of the map. (The type of objects associated with the keys).
128 128
      typedef T Value;
129 129

	
130 130
      /// Returns the value associated with a key.
131 131
      Value operator[](const Key &) const {return Value();}
132 132
      /// Sets the value associated with a 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
      /// Map's key type.
155
      /// The key type of the map.
156 156
      typedef K Key;    
157
      /// Map's value type. (The type of objects associated with the keys).
157
      /// The value type of the map. (The type of objects associated with the keys).
158 158
      typedef T Value;
159
      /// Map's reference type.
159
      /// The reference type of the map.
160 160
      typedef R Reference;
161
      /// Map's const reference type.
161
      /// The const reference type of the map.
162 162
      typedef CR ConstReference;
163 163

	
164 164
    protected:
165 165
      Value tmp;
166 166
    public:
167 167

	
168 168
      ///Returns a reference to the value associated to a key.
169 169
      Reference operator[](const Key &) { return tmp; }
170 170
      ///Returns a const reference to the value associated to a key.
171 171
      ConstReference operator[](const Key &) const { return tmp; }
172 172
      /// Sets the value associated with a key.
173 173
      void set(const Key &k,const Value &t) { operator[](k)=t; }
174 174

	
175 175
      /// \todo Rethink this concept. 
176 176
      template<typename _ReferenceMap>
177 177
      struct ReferenceMapConcept {
178 178

	
179 179
	void constraints() {
180 180
	  checkConcept<ReadWriteMap, _ReferenceMap >();
181 181
	  m[key] = val;
182 182
	  val  = m[key];
183 183
	  m[key] = ref;
184 184
	  ref = m[key];
185 185
	  m[own_key] = own_val;
186 186
	  own_val  = m[own_key];
187 187
	  m[own_key] = own_ref;
188 188
	  own_ref = m[own_key];	  	  
189 189
	}
190 190

	
191 191
	typename _ReferenceMap::Key& own_key;
192 192
	typename _ReferenceMap::Value& own_val;
193 193
	typename _ReferenceMap::Reference& own_ref;
194 194
	Key& key;
195 195
	Value& val;
196 196
	Reference& ref;
197 197
	_ReferenceMap& m;
198 198
      };
199 199
    };
200 200

	
201 201
    // @}
202 202

	
203 203
  } //namespace concepts
204 204

	
205 205
} //namespace lemon
206 206

	
207 207
#endif // LEMON_CONCEPT_MAPS_H
0 comments (0 inline)