Changeset 1910:f95eea8c34b0 in lemon0.x for lemon/bits/static_map.h
 Timestamp:
 01/26/06 17:24:40 (14 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@2485
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/bits/static_map.h
r1909 r1910 3 3 * 4 4 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 5 * (Egervary Research Gro upon Combinatorial Optimization, EGRES).5 * (Egervary Research Groin on Combinatorial Optimization, EGRES). 6 6 * 7 7 * Permission to use, modify and distribute this software is granted … … 28 28 #include <lemon/concept/maps.h> 29 29 30 /// \ingro upgraphmaps30 /// \ingroin graphmaps 31 31 /// 32 32 ///\file … … 35 35 namespace lemon { 36 36 37 /// \ingro upgraphmaps37 /// \ingroin graphmaps 38 38 /// 39 39 /// \brief Graph map with static sized storage. 40 40 /// 41 41 /// The StaticMap template class is graph map structure what 42 /// does not update automatically the map when a key is added to or42 /// does not indate automatically the map when a key is added to or 43 43 /// erased from the map rather it throws an exception. This map factory 44 44 /// uses the allocators to implement the container functionality. … … 55 55 public: 56 56 57 /// \brief Exception class for uns upported exceptions.58 class Uns upportedOperation : public lemon::LogicError {57 /// \brief Exception class for unsinported exceptions. 58 class UnsinportedOperation : public lemon::LogicError { 59 59 public: 60 60 virtual const char* exceptionName() const { 61 return "lemon::StaticMap::Uns upportedOperation";61 return "lemon::StaticMap::UnsinportedOperation"; 62 62 } 63 63 }; … … 186 186 187 187 void add(const Key&) { 188 throw Uns upportedOperation();188 throw UnsinportedOperation(); 189 189 } 190 190 … … 194 194 /// and it overrides the erase() member function of the observer base. 195 195 void erase(const Key&) { 196 throw Uns upportedOperation();196 throw UnsinportedOperation(); 197 197 } 198 198 … … 347 347 348 348 template <typename _Base> 349 class StaticMappable UBipartiteGraphExtender : public _Base {349 class StaticMappableBpUGraphExtender : public _Base { 350 350 public: 351 351 352 352 typedef _Base Parent; 353 typedef StaticMappable UBipartiteGraphExtender Graph;353 typedef StaticMappableBpUGraphExtender Graph; 354 354 355 355 typedef typename Parent::Node Node; 356 typedef typename Parent:: UpperNode UpperNode;357 typedef typename Parent:: LowerNode LowerNode;356 typedef typename Parent::ANode ANode; 357 typedef typename Parent::BNode BNode; 358 358 typedef typename Parent::Edge Edge; 359 359 typedef typename Parent::UEdge UEdge; 360 360 361 361 template <typename _Value> 362 class UpperNodeMap363 : public IterableMapExtender<StaticMap<Graph, UpperNode, _Value> > {364 public: 365 typedef StaticMappable UBipartiteGraphExtender Graph;366 typedef IterableMapExtender<StaticMap<Graph, UpperNode, _Value> >362 class ANodeMap 363 : public IterableMapExtender<StaticMap<Graph, ANode, _Value> > { 364 public: 365 typedef StaticMappableBpUGraphExtender Graph; 366 typedef IterableMapExtender<StaticMap<Graph, ANode, _Value> > 367 367 Parent; 368 368 369 UpperNodeMap(const Graph& _g)370 : Parent(_g) {} 371 UpperNodeMap(const Graph& _g, const _Value& _v)372 : Parent(_g, _v) {} 373 374 UpperNodeMap& operator=(const UpperNodeMap& cmap) {375 return operator=< UpperNodeMap>(cmap);369 ANodeMap(const Graph& _g) 370 : Parent(_g) {} 371 ANodeMap(const Graph& _g, const _Value& _v) 372 : Parent(_g, _v) {} 373 374 ANodeMap& operator=(const ANodeMap& cmap) { 375 return operator=<ANodeMap>(cmap); 376 376 } 377 377 … … 381 381 /// The given parameter should be conform to the ReadMap 382 382 /// concept and could be indiced by the current item set of 383 /// the UpperNodeMap. In this case the value for each item383 /// the ANodeMap. In this case the value for each item 384 384 /// is assigned by the value of the given ReadMap. 385 385 template <typename CMap> 386 UpperNodeMap& operator=(const CMap& cmap) {387 checkConcept<concept::ReadMap< UpperNode, _Value>, CMap>();388 const typename Parent::Graph* graph = Parent::getGraph(); 389 UpperNode it;390 for (graph>first(it); it != INVALID; graph>next(it)) { 391 Parent::set(it, cmap[it]); 392 } 393 return *this; 394 } 395 396 }; 397 398 template <typename _Value> 399 class LowerNodeMap400 : public IterableMapExtender<StaticMap<Graph, LowerNode, _Value> > {401 public: 402 typedef StaticMappable UBipartiteGraphExtender Graph;403 typedef IterableMapExtender<StaticMap<Graph, LowerNode, _Value> >386 ANodeMap& operator=(const CMap& cmap) { 387 checkConcept<concept::ReadMap<ANode, _Value>, CMap>(); 388 const typename Parent::Graph* graph = Parent::getGraph(); 389 ANode it; 390 for (graph>first(it); it != INVALID; graph>next(it)) { 391 Parent::set(it, cmap[it]); 392 } 393 return *this; 394 } 395 396 }; 397 398 template <typename _Value> 399 class BNodeMap 400 : public IterableMapExtender<StaticMap<Graph, BNode, _Value> > { 401 public: 402 typedef StaticMappableBpUGraphExtender Graph; 403 typedef IterableMapExtender<StaticMap<Graph, BNode, _Value> > 404 404 Parent; 405 405 406 LowerNodeMap(const Graph& _g)407 : Parent(_g) {} 408 LowerNodeMap(const Graph& _g, const _Value& _v)409 : Parent(_g, _v) {} 410 411 LowerNodeMap& operator=(const LowerNodeMap& cmap) {412 return operator=< LowerNodeMap>(cmap);406 BNodeMap(const Graph& _g) 407 : Parent(_g) {} 408 BNodeMap(const Graph& _g, const _Value& _v) 409 : Parent(_g, _v) {} 410 411 BNodeMap& operator=(const BNodeMap& cmap) { 412 return operator=<BNodeMap>(cmap); 413 413 } 414 414 … … 418 418 /// The given parameter should be conform to the ReadMap 419 419 /// concept and could be indiced by the current item set of 420 /// the LowerNodeMap. In this case the value for each item420 /// the BNodeMap. In this case the value for each item 421 421 /// is assigned by the value of the given ReadMap. 422 422 template <typename CMap> 423 LowerNodeMap& operator=(const CMap& cmap) {424 checkConcept<concept::ReadMap< LowerNode, _Value>, CMap>();425 const typename Parent::Graph* graph = Parent::getGraph(); 426 LowerNode it;423 BNodeMap& operator=(const CMap& cmap) { 424 checkConcept<concept::ReadMap<BNode, _Value>, CMap>(); 425 const typename Parent::Graph* graph = Parent::getGraph(); 426 BNode it; 427 427 for (graph>first(it); it != INVALID; graph>next(it)) { 428 428 Parent::set(it, cmap[it]); … … 438 438 class NodeMapBase : public Parent::NodeNotifier::ObserverBase { 439 439 public: 440 typedef StaticMappable UBipartiteGraphExtender Graph;440 typedef StaticMappableBpUGraphExtender Graph; 441 441 442 442 typedef Node Key; … … 444 444 445 445 /// The reference type of the map; 446 typedef typename LowerNodeMap<_Value>::Reference Reference;446 typedef typename BNodeMap<_Value>::Reference Reference; 447 447 /// The pointer type of the map; 448 typedef typename LowerNodeMap<_Value>::Pointer Pointer;448 typedef typename BNodeMap<_Value>::Pointer Pointer; 449 449 450 450 /// The const value type of the map. 451 451 typedef const Value ConstValue; 452 452 /// The const reference type of the map; 453 typedef typename LowerNodeMap<_Value>::ConstReference ConstReference;453 typedef typename BNodeMap<_Value>::ConstReference ConstReference; 454 454 /// The pointer type of the map; 455 typedef typename LowerNodeMap<_Value>::ConstPointer ConstPointer;455 typedef typename BNodeMap<_Value>::ConstPointer ConstPointer; 456 456 457 457 typedef True ReferenceMapTag; 458 458 459 459 NodeMapBase(const Graph& _g) 460 : graph(&_g), lowerMap(_g), upperMap(_g) {460 : graph(&_g), bNodeMap(_g), aNodeMap(_g) { 461 461 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); 462 462 } 463 463 NodeMapBase(const Graph& _g, const _Value& _v) 464 : graph(&_g), lowerMap(_g, _v),465 upperMap(_g, _v) {464 : graph(&_g), bNodeMap(_g, _v), 465 aNodeMap(_g, _v) { 466 466 Parent::NodeNotifier::ObserverBase::attach(_g.getNotifier(Node())); 467 467 } … … 474 474 475 475 ConstReference operator[](const Key& node) const { 476 if (Parent:: upper(node)) {477 return upperMap[node];476 if (Parent::aNode(node)) { 477 return aNodeMap[node]; 478 478 } else { 479 return lowerMap[node];479 return bNodeMap[node]; 480 480 } 481 481 } 482 482 483 483 Reference operator[](const Key& node) { 484 if (Parent:: upper(node)) {485 return upperMap[node];484 if (Parent::aNode(node)) { 485 return aNodeMap[node]; 486 486 } else { 487 return lowerMap[node];487 return bNodeMap[node]; 488 488 } 489 489 } 490 490 491 491 void set(const Key& node, const Value& value) { 492 if (Parent:: upper(node)) {493 upperMap.set(node, value);492 if (Parent::aNode(node)) { 493 aNodeMap.set(node, value); 494 494 } else { 495 lowerMap.set(node, value);495 bNodeMap.set(node, value); 496 496 } 497 497 } … … 508 508 private: 509 509 const Graph* graph; 510 LowerNodeMap<_Value> lowerMap;511 UpperNodeMap<_Value> upperMap;510 BNodeMap<_Value> bNodeMap; 511 ANodeMap<_Value> aNodeMap; 512 512 }; 513 513 … … 518 518 : public IterableMapExtender<NodeMapBase<_Value> > { 519 519 public: 520 typedef StaticMappable UBipartiteGraphExtender Graph;520 typedef StaticMappableBpUGraphExtender Graph; 521 521 typedef IterableMapExtender< NodeMapBase<_Value> > Parent; 522 522 … … 556 556 : public IterableMapExtender<StaticMap<Graph, Edge, _Value> > { 557 557 public: 558 typedef StaticMappable UBipartiteGraphExtender Graph;558 typedef StaticMappableBpUGraphExtender Graph; 559 559 typedef IterableMapExtender<StaticMap<Graph, Edge, _Value> > Parent; 560 560 … … 584 584 : public IterableMapExtender<StaticMap<Graph, UEdge, _Value> > { 585 585 public: 586 typedef StaticMappable UBipartiteGraphExtender Graph;586 typedef StaticMappableBpUGraphExtender Graph; 587 587 typedef IterableMapExtender<StaticMap<Graph, UEdge, _Value> > 588 588 Parent;
Note: See TracChangeset
for help on using the changeset viewer.