109 /// \brief Constructor to attach the new map into the notifier. |
109 /// \brief Constructor to attach the new map into the notifier. |
110 /// |
110 /// |
111 /// It constructs a map and attachs it into the notifier. |
111 /// It constructs a map and attachs it into the notifier. |
112 /// It adds all the items of the graph to the map. |
112 /// It adds all the items of the graph to the map. |
113 DebugMap(const Graph& graph) { |
113 DebugMap(const Graph& graph) { |
114 Parent::attach(graph.getNotifier(Item())); |
114 Parent::attach(graph.notifier(Item())); |
115 container.resize(Parent::getNotifier()->maxId() + 1); |
115 container.resize(Parent::notifier()->maxId() + 1); |
116 flag.resize(Parent::getNotifier()->maxId() + 1, false); |
116 flag.resize(Parent::notifier()->maxId() + 1, false); |
117 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
117 const typename Parent::Notifier* notifier = Parent::notifier(); |
118 Item it; |
118 Item it; |
119 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
119 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
120 flag[Parent::getNotifier()->id(it)] = true; |
120 flag[Parent::notifier()->id(it)] = true; |
121 } |
121 } |
122 } |
122 } |
123 |
123 |
124 /// \brief Constructor uses given value to initialize the map. |
124 /// \brief Constructor uses given value to initialize the map. |
125 /// |
125 /// |
126 /// It constructs a map uses a given value to initialize the map. |
126 /// It constructs a map uses a given value to initialize the map. |
127 /// It adds all the items of the graph to the map. |
127 /// It adds all the items of the graph to the map. |
128 DebugMap(const Graph& graph, const Value& value) { |
128 DebugMap(const Graph& graph, const Value& value) { |
129 Parent::attach(graph.getNotifier(Item())); |
129 Parent::attach(graph.notifier(Item())); |
130 container.resize(Parent::getNotifier()->maxId() + 1, value); |
130 container.resize(Parent::notifier()->maxId() + 1, value); |
131 flag.resize(Parent::getNotifier()->maxId() + 1, false); |
131 flag.resize(Parent::notifier()->maxId() + 1, false); |
132 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
132 const typename Parent::Notifier* notifier = Parent::notifier(); |
133 Item it; |
133 Item it; |
134 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
134 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
135 flag[Parent::getNotifier()->id(it)] = true; |
135 flag[Parent::notifier()->id(it)] = true; |
136 } |
136 } |
137 } |
137 } |
138 |
138 |
139 /// \brief Copy constructor |
139 /// \brief Copy constructor |
140 /// |
140 /// |
141 /// Copy constructor. |
141 /// Copy constructor. |
142 DebugMap(const DebugMap& _copy) : Parent() { |
142 DebugMap(const DebugMap& _copy) : Parent() { |
143 if (_copy.attached()) { |
143 if (_copy.attached()) { |
144 Parent::attach(*_copy.getNotifier()); |
144 Parent::attach(*_copy.notifier()); |
145 container = _copy.container; |
145 container = _copy.container; |
146 } |
146 } |
147 flag.resize(Parent::getNotifier()->maxId() + 1, false); |
147 flag.resize(Parent::notifier()->maxId() + 1, false); |
148 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
148 const typename Parent::Notifier* notifier = Parent::notifier(); |
149 Item it; |
149 Item it; |
150 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
150 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
151 flag[Parent::getNotifier()->id(it)] = true; |
151 flag[Parent::notifier()->id(it)] = true; |
152 LEMON_ASSERT(_copy.flag[Parent::getNotifier()->id(it)], MapError()); |
152 LEMON_ASSERT(_copy.flag[Parent::notifier()->id(it)], MapError()); |
153 } |
153 } |
154 } |
154 } |
155 |
155 |
156 /// \brief Destructor |
156 /// \brief Destructor |
157 /// |
157 /// |
158 /// Destructor. |
158 /// Destructor. |
159 ~DebugMap() { |
159 ~DebugMap() { |
160 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
160 const typename Parent::Notifier* notifier = Parent::notifier(); |
161 if (notifier != 0) { |
161 if (notifier != 0) { |
162 Item it; |
162 Item it; |
163 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
163 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
164 LEMON_ASSERT(flag[Parent::getNotifier()->id(it)], MapError()); |
164 LEMON_ASSERT(flag[Parent::notifier()->id(it)], MapError()); |
165 flag[Parent::getNotifier()->id(it)] = false; |
165 flag[Parent::notifier()->id(it)] = false; |
166 } |
166 } |
167 } |
167 } |
168 for (int i = 0; i < (int)flag.size(); ++i) { |
168 for (int i = 0; i < (int)flag.size(); ++i) { |
169 LEMON_ASSERT(!flag[i], MapError()); |
169 LEMON_ASSERT(!flag[i], MapError()); |
170 } |
170 } |
204 /// \brief The subcript operator. |
204 /// \brief The subcript operator. |
205 /// |
205 /// |
206 /// The subscript operator. The map can be subscripted by the |
206 /// The subscript operator. The map can be subscripted by the |
207 /// actual items of the graph. |
207 /// actual items of the graph. |
208 Reference operator[](const Key& key) { |
208 Reference operator[](const Key& key) { |
209 LEMON_ASSERT(flag[Parent::getNotifier()->id(key)], MapError()); |
209 LEMON_ASSERT(flag[Parent::notifier()->id(key)], MapError()); |
210 return container[Parent::getNotifier()->id(key)]; |
210 return container[Parent::notifier()->id(key)]; |
211 } |
211 } |
212 |
212 |
213 /// \brief The const subcript operator. |
213 /// \brief The const subcript operator. |
214 /// |
214 /// |
215 /// The const subscript operator. The map can be subscripted by the |
215 /// The const subscript operator. The map can be subscripted by the |
216 /// actual items of the graph. |
216 /// actual items of the graph. |
217 ConstReference operator[](const Key& key) const { |
217 ConstReference operator[](const Key& key) const { |
218 LEMON_ASSERT(flag[Parent::getNotifier()->id(key)], MapError()); |
218 LEMON_ASSERT(flag[Parent::notifier()->id(key)], MapError()); |
219 return container[Parent::getNotifier()->id(key)]; |
219 return container[Parent::notifier()->id(key)]; |
220 } |
220 } |
221 |
221 |
222 |
222 |
223 /// \brief The setter function of the map. |
223 /// \brief The setter function of the map. |
224 /// |
224 /// |
232 /// \brief Adds a new key to the map. |
232 /// \brief Adds a new key to the map. |
233 /// |
233 /// |
234 /// It adds a new key to the map. It called by the observer notifier |
234 /// It adds a new key to the map. It called by the observer notifier |
235 /// and it overrides the add() member function of the observer base. |
235 /// and it overrides the add() member function of the observer base. |
236 virtual void add(const Key& key) { |
236 virtual void add(const Key& key) { |
237 int id = Parent::getNotifier()->id(key); |
237 int id = Parent::notifier()->id(key); |
238 if (id >= (int)container.size()) { |
238 if (id >= (int)container.size()) { |
239 container.resize(id + 1); |
239 container.resize(id + 1); |
240 flag.resize(id + 1, false); |
240 flag.resize(id + 1, false); |
241 } |
241 } |
242 LEMON_ASSERT(!flag[Parent::getNotifier()->id(key)], MapError()); |
242 LEMON_ASSERT(!flag[Parent::notifier()->id(key)], MapError()); |
243 flag[Parent::getNotifier()->id(key)] = true; |
243 flag[Parent::notifier()->id(key)] = true; |
244 if (strictCheck) { |
244 if (strictCheck) { |
245 std::vector<bool> fl(flag.size(), false); |
245 std::vector<bool> fl(flag.size(), false); |
246 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
246 const typename Parent::Notifier* notifier = Parent::notifier(); |
247 Item it; |
247 Item it; |
248 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
248 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
249 int id = Parent::getNotifier()->id(it); |
249 int id = Parent::notifier()->id(it); |
250 fl[id] = true; |
250 fl[id] = true; |
251 } |
251 } |
252 LEMON_ASSERT(fl == flag, MapError()); |
252 LEMON_ASSERT(fl == flag, MapError()); |
253 } |
253 } |
254 } |
254 } |
258 /// It adds more new keys to the map. It called by the observer notifier |
258 /// It adds more new keys to the map. It called by the observer notifier |
259 /// and it overrides the add() member function of the observer base. |
259 /// and it overrides the add() member function of the observer base. |
260 virtual void add(const std::vector<Key>& keys) { |
260 virtual void add(const std::vector<Key>& keys) { |
261 int max = container.size() - 1; |
261 int max = container.size() - 1; |
262 for (int i = 0; i < (int)keys.size(); ++i) { |
262 for (int i = 0; i < (int)keys.size(); ++i) { |
263 int id = Parent::getNotifier()->id(keys[i]); |
263 int id = Parent::notifier()->id(keys[i]); |
264 if (id >= max) { |
264 if (id >= max) { |
265 max = id; |
265 max = id; |
266 } |
266 } |
267 } |
267 } |
268 container.resize(max + 1); |
268 container.resize(max + 1); |
269 flag.resize(max + 1, false); |
269 flag.resize(max + 1, false); |
270 for (int i = 0; i < (int)keys.size(); ++i) { |
270 for (int i = 0; i < (int)keys.size(); ++i) { |
271 LEMON_ASSERT(!flag[Parent::getNotifier()->id(keys[i])], MapError()); |
271 LEMON_ASSERT(!flag[Parent::notifier()->id(keys[i])], MapError()); |
272 flag[Parent::getNotifier()->id(keys[i])] = true; |
272 flag[Parent::notifier()->id(keys[i])] = true; |
273 } |
273 } |
274 if (strictCheck) { |
274 if (strictCheck) { |
275 std::vector<bool> fl(flag.size(), false); |
275 std::vector<bool> fl(flag.size(), false); |
276 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
276 const typename Parent::Notifier* notifier = Parent::notifier(); |
277 Item it; |
277 Item it; |
278 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
278 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
279 int id = Parent::getNotifier()->id(it); |
279 int id = Parent::notifier()->id(it); |
280 fl[id] = true; |
280 fl[id] = true; |
281 } |
281 } |
282 LEMON_ASSERT(fl == flag, MapError()); |
282 LEMON_ASSERT(fl == flag, MapError()); |
283 } |
283 } |
284 } |
284 } |
288 /// Erase a key from the map. It called by the observer notifier |
288 /// Erase a key from the map. It called by the observer notifier |
289 /// and it overrides the erase() member function of the observer base. |
289 /// and it overrides the erase() member function of the observer base. |
290 virtual void erase(const Key& key) { |
290 virtual void erase(const Key& key) { |
291 if (strictCheck) { |
291 if (strictCheck) { |
292 std::vector<bool> fl(flag.size(), false); |
292 std::vector<bool> fl(flag.size(), false); |
293 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
293 const typename Parent::Notifier* notifier = Parent::notifier(); |
294 Item it; |
294 Item it; |
295 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
295 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
296 int id = Parent::getNotifier()->id(it); |
296 int id = Parent::notifier()->id(it); |
297 fl[id] = true; |
297 fl[id] = true; |
298 } |
298 } |
299 LEMON_ASSERT(fl == flag, MapError()); |
299 LEMON_ASSERT(fl == flag, MapError()); |
300 } |
300 } |
301 container[Parent::getNotifier()->id(key)] = Value(); |
301 container[Parent::notifier()->id(key)] = Value(); |
302 LEMON_ASSERT(flag[Parent::getNotifier()->id(key)], MapError()); |
302 LEMON_ASSERT(flag[Parent::notifier()->id(key)], MapError()); |
303 flag[Parent::getNotifier()->id(key)] = false; |
303 flag[Parent::notifier()->id(key)] = false; |
304 } |
304 } |
305 |
305 |
306 /// \brief Erase more keys from the map. |
306 /// \brief Erase more keys from the map. |
307 /// |
307 /// |
308 /// Erase more keys from the map. It called by the observer notifier |
308 /// Erase more keys from the map. It called by the observer notifier |
309 /// and it overrides the erase() member function of the observer base. |
309 /// and it overrides the erase() member function of the observer base. |
310 virtual void erase(const std::vector<Key>& keys) { |
310 virtual void erase(const std::vector<Key>& keys) { |
311 if (strictCheck) { |
311 if (strictCheck) { |
312 std::vector<bool> fl(flag.size(), false); |
312 std::vector<bool> fl(flag.size(), false); |
313 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
313 const typename Parent::Notifier* notifier = Parent::notifier(); |
314 Item it; |
314 Item it; |
315 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
315 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
316 int id = Parent::getNotifier()->id(it); |
316 int id = Parent::notifier()->id(it); |
317 fl[id] = true; |
317 fl[id] = true; |
318 } |
318 } |
319 LEMON_ASSERT(fl == flag, MapError()); |
319 LEMON_ASSERT(fl == flag, MapError()); |
320 } |
320 } |
321 for (int i = 0; i < (int)keys.size(); ++i) { |
321 for (int i = 0; i < (int)keys.size(); ++i) { |
322 container[Parent::getNotifier()->id(keys[i])] = Value(); |
322 container[Parent::notifier()->id(keys[i])] = Value(); |
323 LEMON_ASSERT(flag[Parent::getNotifier()->id(keys[i])], MapError()); |
323 LEMON_ASSERT(flag[Parent::notifier()->id(keys[i])], MapError()); |
324 flag[Parent::getNotifier()->id(keys[i])] = false; |
324 flag[Parent::notifier()->id(keys[i])] = false; |
325 } |
325 } |
326 } |
326 } |
327 |
327 |
328 /// \brief Buildes the map. |
328 /// \brief Buildes the map. |
329 /// |
329 /// |
333 if (strictCheck) { |
333 if (strictCheck) { |
334 for (int i = 0; i < (int)flag.size(); ++i) { |
334 for (int i = 0; i < (int)flag.size(); ++i) { |
335 LEMON_ASSERT(flag[i], MapError()); |
335 LEMON_ASSERT(flag[i], MapError()); |
336 } |
336 } |
337 } |
337 } |
338 int size = Parent::getNotifier()->maxId() + 1; |
338 int size = Parent::notifier()->maxId() + 1; |
339 container.reserve(size); |
339 container.reserve(size); |
340 container.resize(size); |
340 container.resize(size); |
341 flag.reserve(size); |
341 flag.reserve(size); |
342 flag.resize(size, false); |
342 flag.resize(size, false); |
343 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
343 const typename Parent::Notifier* notifier = Parent::notifier(); |
344 Item it; |
344 Item it; |
345 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
345 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
346 int id = Parent::getNotifier()->id(it); |
346 int id = Parent::notifier()->id(it); |
347 LEMON_ASSERT(!flag[id], MapError()); |
347 LEMON_ASSERT(!flag[id], MapError()); |
348 flag[id] = true; |
348 flag[id] = true; |
349 } |
349 } |
350 } |
350 } |
351 |
351 |
352 /// \brief Clear the map. |
352 /// \brief Clear the map. |
353 /// |
353 /// |
354 /// It erase all items from the map. It called by the observer notifier |
354 /// It erase all items from the map. It called by the observer notifier |
355 /// and it overrides the clear() member function of the observer base. |
355 /// and it overrides the clear() member function of the observer base. |
356 virtual void clear() { |
356 virtual void clear() { |
357 const typename Parent::Notifier* notifier = Parent::getNotifier(); |
357 const typename Parent::Notifier* notifier = Parent::notifier(); |
358 Item it; |
358 Item it; |
359 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
359 for (notifier->first(it); it != INVALID; notifier->next(it)) { |
360 int id = Parent::getNotifier()->id(it); |
360 int id = Parent::notifier()->id(it); |
361 LEMON_ASSERT(flag[id], MapError()); |
361 LEMON_ASSERT(flag[id], MapError()); |
362 flag[id] = false; |
362 flag[id] = false; |
363 } |
363 } |
364 if (strictCheck) { |
364 if (strictCheck) { |
365 for (int i = 0; i < (int)flag.size(); ++i) { |
365 for (int i = 0; i < (int)flag.size(); ++i) { |