350 |
350 |
351 }; |
351 }; |
352 |
352 |
353 |
353 |
354 template <typename _Base> |
354 template <typename _Base> |
355 class MappableUBipartiteGraphExtender : public _Base { |
355 class MappableBpUGraphExtender : public _Base { |
356 public: |
356 public: |
357 |
357 |
358 typedef _Base Parent; |
358 typedef _Base Parent; |
359 typedef MappableUBipartiteGraphExtender Graph; |
359 typedef MappableBpUGraphExtender Graph; |
360 |
360 |
361 typedef typename Parent::Node Node; |
361 typedef typename Parent::Node Node; |
362 typedef typename Parent::UpperNode UpperNode; |
362 typedef typename Parent::ANode ANode; |
363 typedef typename Parent::LowerNode LowerNode; |
363 typedef typename Parent::BNode BNode; |
364 typedef typename Parent::Edge Edge; |
364 typedef typename Parent::Edge Edge; |
365 typedef typename Parent::UEdge UEdge; |
365 typedef typename Parent::UEdge UEdge; |
366 |
366 |
367 template <typename _Value> |
367 template <typename _Value> |
368 class UpperNodeMap |
368 class ANodeMap |
369 : public IterableMapExtender<DefaultMap<Graph, UpperNode, _Value> > { |
369 : public IterableMapExtender<DefaultMap<Graph, ANode, _Value> > { |
370 public: |
370 public: |
371 typedef MappableUBipartiteGraphExtender Graph; |
371 typedef MappableBpUGraphExtender Graph; |
372 typedef IterableMapExtender<DefaultMap<Graph, UpperNode, _Value> > |
372 typedef IterableMapExtender<DefaultMap<Graph, ANode, _Value> > |
373 Parent; |
373 Parent; |
374 |
374 |
375 UpperNodeMap(const Graph& _g) |
375 ANodeMap(const Graph& _g) |
376 : Parent(_g) {} |
376 : Parent(_g) {} |
377 UpperNodeMap(const Graph& _g, const _Value& _v) |
377 ANodeMap(const Graph& _g, const _Value& _v) |
378 : Parent(_g, _v) {} |
378 : Parent(_g, _v) {} |
379 |
379 |
380 UpperNodeMap& operator=(const UpperNodeMap& cmap) { |
380 ANodeMap& operator=(const ANodeMap& cmap) { |
381 return operator=<UpperNodeMap>(cmap); |
381 return operator=<ANodeMap>(cmap); |
382 } |
382 } |
383 |
383 |
384 |
384 |
385 /// \brief Template assign operator. |
385 /// \brief Template assign operator. |
386 /// |
386 /// |
387 /// The given parameter should be conform to the ReadMap |
387 /// The given parameter should be conform to the ReadMap |
388 /// concept and could be indiced by the current item set of |
388 /// concept and could be indiced by the current item set of |
389 /// the UpperNodeMap. In this case the value for each item |
389 /// the ANodeMap. In this case the value for each item |
390 /// is assigned by the value of the given ReadMap. |
390 /// is assigned by the value of the given ReadMap. |
391 template <typename CMap> |
391 template <typename CMap> |
392 UpperNodeMap& operator=(const CMap& cmap) { |
392 ANodeMap& operator=(const CMap& cmap) { |
393 checkConcept<concept::ReadMap<UpperNode, _Value>, CMap>(); |
393 checkConcept<concept::ReadMap<ANode, _Value>, CMap>(); |
394 const typename Parent::Graph* graph = Parent::getGraph(); |
394 const typename Parent::Graph* graph = Parent::getGraph(); |
395 UpperNode it; |
395 ANode it; |
396 for (graph->first(it); it != INVALID; graph->next(it)) { |
396 for (graph->first(it); it != INVALID; graph->next(it)) { |
397 Parent::set(it, cmap[it]); |
397 Parent::set(it, cmap[it]); |
398 } |
398 } |
399 return *this; |
399 return *this; |
400 } |
400 } |
401 |
401 |
402 }; |
402 }; |
403 |
403 |
404 template <typename _Value> |
404 template <typename _Value> |
405 class LowerNodeMap |
405 class BNodeMap |
406 : public IterableMapExtender<DefaultMap<Graph, LowerNode, _Value> > { |
406 : public IterableMapExtender<DefaultMap<Graph, BNode, _Value> > { |
407 public: |
407 public: |
408 typedef MappableUBipartiteGraphExtender Graph; |
408 typedef MappableBpUGraphExtender Graph; |
409 typedef IterableMapExtender<DefaultMap<Graph, LowerNode, _Value> > |
409 typedef IterableMapExtender<DefaultMap<Graph, BNode, _Value> > |
410 Parent; |
410 Parent; |
411 |
411 |
412 LowerNodeMap(const Graph& _g) |
412 BNodeMap(const Graph& _g) |
413 : Parent(_g) {} |
413 : Parent(_g) {} |
414 LowerNodeMap(const Graph& _g, const _Value& _v) |
414 BNodeMap(const Graph& _g, const _Value& _v) |
415 : Parent(_g, _v) {} |
415 : Parent(_g, _v) {} |
416 |
416 |
417 LowerNodeMap& operator=(const LowerNodeMap& cmap) { |
417 BNodeMap& operator=(const BNodeMap& cmap) { |
418 return operator=<LowerNodeMap>(cmap); |
418 return operator=<BNodeMap>(cmap); |
419 } |
419 } |
420 |
420 |
421 |
421 |
422 /// \brief Template assign operator. |
422 /// \brief Template assign operator. |
423 /// |
423 /// |
424 /// The given parameter should be conform to the ReadMap |
424 /// The given parameter should be conform to the ReadMap |
425 /// concept and could be indiced by the current item set of |
425 /// concept and could be indiced by the current item set of |
426 /// the LowerNodeMap. In this case the value for each item |
426 /// the BNodeMap. In this case the value for each item |
427 /// is assigned by the value of the given ReadMap. |
427 /// is assigned by the value of the given ReadMap. |
428 template <typename CMap> |
428 template <typename CMap> |
429 LowerNodeMap& operator=(const CMap& cmap) { |
429 BNodeMap& operator=(const CMap& cmap) { |
430 checkConcept<concept::ReadMap<LowerNode, _Value>, CMap>(); |
430 checkConcept<concept::ReadMap<BNode, _Value>, CMap>(); |
431 const typename Parent::Graph* graph = Parent::getGraph(); |
431 const typename Parent::Graph* graph = Parent::getGraph(); |
432 LowerNode it; |
432 BNode it; |
433 for (graph->first(it); it != INVALID; graph->next(it)) { |
433 for (graph->first(it); it != INVALID; graph->next(it)) { |
434 Parent::set(it, cmap[it]); |
434 Parent::set(it, cmap[it]); |
435 } |
435 } |
436 return *this; |
436 return *this; |
437 } |
437 } |
441 protected: |
441 protected: |
442 |
442 |
443 template <typename _Value> |
443 template <typename _Value> |
444 class NodeMapBase : public Parent::NodeNotifier::ObserverBase { |
444 class NodeMapBase : public Parent::NodeNotifier::ObserverBase { |
445 public: |
445 public: |
446 typedef MappableUBipartiteGraphExtender Graph; |
446 typedef MappableBpUGraphExtender Graph; |
447 |
447 |
448 typedef Node Key; |
448 typedef Node Key; |
449 typedef _Value Value; |
449 typedef _Value Value; |
450 |
450 |
451 /// The reference type of the map; |
451 /// The reference type of the map; |
452 typedef typename LowerNodeMap<_Value>::Reference Reference; |
452 typedef typename BNodeMap<_Value>::Reference Reference; |
453 /// The pointer type of the map; |
453 /// The pointer type of the map; |
454 typedef typename LowerNodeMap<_Value>::Pointer Pointer; |
454 typedef typename BNodeMap<_Value>::Pointer Pointer; |
455 |
455 |
456 /// The const value type of the map. |
456 /// The const value type of the map. |
457 typedef const Value ConstValue; |
457 typedef const Value ConstValue; |
458 /// The const reference type of the map; |
458 /// The const reference type of the map; |
459 typedef typename LowerNodeMap<_Value>::ConstReference ConstReference; |
459 typedef typename BNodeMap<_Value>::ConstReference ConstReference; |
460 /// The pointer type of the map; |
460 /// The pointer type of the map; |
461 typedef typename LowerNodeMap<_Value>::ConstPointer ConstPointer; |
461 typedef typename BNodeMap<_Value>::ConstPointer ConstPointer; |
462 |
462 |
463 typedef True ReferenceMapTag; |
463 typedef True ReferenceMapTag; |
464 |
464 |
465 NodeMapBase(const Graph& _g) |
465 NodeMapBase(const Graph& _g) |
466 : graph(&_g), lowerMap(_g), upperMap(_g) { |
466 : graph(&_g), bNodeMap(_g), aNodeMap(_g) { |
467 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); |
467 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); |
468 } |
468 } |
469 NodeMapBase(const Graph& _g, const _Value& _v) |
469 NodeMapBase(const Graph& _g, const _Value& _v) |
470 : graph(&_g), lowerMap(_g, _v), |
470 : graph(&_g), bNodeMap(_g, _v), |
471 upperMap(_g, _v) { |
471 aNodeMap(_g, _v) { |
472 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); |
472 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); |
473 } |
473 } |
474 |
474 |
475 virtual ~NodeMapBase() { |
475 virtual ~NodeMapBase() { |
476 if (Parent::NodeNotifier::ObserverBase::attached()) { |
476 if (Parent::NodeNotifier::ObserverBase::attached()) { |
477 Parent::NodeNotifier::ObserverBase::detach(); |
477 Parent::NodeNotifier::ObserverBase::detach(); |
478 } |
478 } |
479 } |
479 } |
480 |
480 |
481 ConstReference operator[](const Key& node) const { |
481 ConstReference operator[](const Key& node) const { |
482 if (Parent::upper(node)) { |
482 if (Parent::aNode(node)) { |
483 return upperMap[node]; |
483 return aNodeMap[node]; |
484 } else { |
484 } else { |
485 return lowerMap[node]; |
485 return bNodeMap[node]; |
486 } |
486 } |
487 } |
487 } |
488 |
488 |
489 Reference operator[](const Key& node) { |
489 Reference operator[](const Key& node) { |
490 if (Parent::upper(node)) { |
490 if (Parent::aNode(node)) { |
491 return upperMap[node]; |
491 return aNodeMap[node]; |
492 } else { |
492 } else { |
493 return lowerMap[node]; |
493 return bNodeMap[node]; |
494 } |
494 } |
495 } |
495 } |
496 |
496 |
497 void set(const Key& node, const Value& value) { |
497 void set(const Key& node, const Value& value) { |
498 if (Parent::upper(node)) { |
498 if (Parent::aNode(node)) { |
499 upperMap.set(node, value); |
499 aNodeMap.set(node, value); |
500 } else { |
500 } else { |
501 lowerMap.set(node, value); |
501 bNodeMap.set(node, value); |
502 } |
502 } |
503 } |
503 } |
504 |
504 |
505 protected: |
505 protected: |
506 |
506 |