gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Add missing 'explicit' keywords (#311)
0 2 0
default
2 files changed with 5 insertions and 5 deletions:
↑ Collapse diff ↑
Show white space 2048 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-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_BITS_EDGE_SET_EXTENDER_H
20 20
#define LEMON_BITS_EDGE_SET_EXTENDER_H
21 21

	
22 22
#include <lemon/core.h>
23 23
#include <lemon/error.h>
24 24
#include <lemon/bits/default_map.h>
25 25
#include <lemon/bits/map_extender.h>
26 26

	
27 27
//\ingroup digraphbits
28 28
//\file
29 29
//\brief Extenders for the arc set types
30 30
namespace lemon {
31 31

	
32 32
  // \ingroup digraphbits
33 33
  //
34 34
  // \brief Extender for the ArcSets
35 35
  template <typename Base>
36 36
  class ArcSetExtender : public Base {
37 37
    typedef Base Parent;
38 38

	
39 39
  public:
40 40

	
41 41
    typedef ArcSetExtender Digraph;
42 42

	
43 43
    // Base extensions
44 44

	
45 45
    typedef typename Parent::Node Node;
46 46
    typedef typename Parent::Arc Arc;
47 47

	
48 48
    int maxId(Node) const {
49 49
      return Parent::maxNodeId();
50 50
    }
51 51

	
52 52
    int maxId(Arc) const {
53 53
      return Parent::maxArcId();
54 54
    }
55 55

	
56 56
    Node fromId(int id, Node) const {
57 57
      return Parent::nodeFromId(id);
58 58
    }
59 59

	
60 60
    Arc fromId(int id, Arc) const {
61 61
      return Parent::arcFromId(id);
62 62
    }
63 63

	
64 64
    Node oppositeNode(const Node &n, const Arc &e) const {
65 65
      if (n == Parent::source(e))
66 66
	return Parent::target(e);
67 67
      else if(n==Parent::target(e))
68 68
	return Parent::source(e);
69 69
      else
70 70
	return INVALID;
71 71
    }
72 72

	
73 73

	
74 74
    // Alteration notifier extensions
75 75

	
76 76
    // The arc observer registry.
77 77
    typedef AlterationNotifier<ArcSetExtender, Arc> ArcNotifier;
78 78

	
79 79
  protected:
80 80

	
81 81
    mutable ArcNotifier arc_notifier;
82 82

	
83 83
  public:
84 84

	
85 85
    using Parent::notifier;
86 86

	
87 87
    // Gives back the arc alteration notifier.
88 88
    ArcNotifier& notifier(Arc) const {
89 89
      return arc_notifier;
90 90
    }
91 91

	
92 92
    // Iterable extensions
93 93

	
94 94
    class NodeIt : public Node { 
95 95
      const Digraph* digraph;
96 96
    public:
97 97

	
98 98
      NodeIt() {}
99 99

	
100 100
      NodeIt(Invalid i) : Node(i) { }
101 101

	
102 102
      explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
103 103
	_graph.first(static_cast<Node&>(*this));
104 104
      }
105 105

	
106 106
      NodeIt(const Digraph& _graph, const Node& node) 
107 107
	: Node(node), digraph(&_graph) {}
108 108

	
109 109
      NodeIt& operator++() { 
110 110
	digraph->next(*this);
111 111
	return *this; 
112 112
      }
113 113

	
114 114
    };
115 115

	
116 116

	
117 117
    class ArcIt : public Arc { 
118 118
      const Digraph* digraph;
119 119
    public:
120 120

	
121 121
      ArcIt() { }
122 122

	
123 123
      ArcIt(Invalid i) : Arc(i) { }
124 124

	
125 125
      explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
126 126
	_graph.first(static_cast<Arc&>(*this));
127 127
      }
128 128

	
129 129
      ArcIt(const Digraph& _graph, const Arc& e) : 
130 130
	Arc(e), digraph(&_graph) { }
131 131

	
132 132
      ArcIt& operator++() { 
133 133
	digraph->next(*this);
134 134
	return *this; 
135 135
      }
136 136

	
137 137
    };
138 138

	
139 139

	
140 140
    class OutArcIt : public Arc { 
141 141
      const Digraph* digraph;
142 142
    public:
143 143

	
144 144
      OutArcIt() { }
145 145

	
146 146
      OutArcIt(Invalid i) : Arc(i) { }
147 147

	
148 148
      OutArcIt(const Digraph& _graph, const Node& node) 
149 149
	: digraph(&_graph) {
150 150
	_graph.firstOut(*this, node);
151 151
      }
152 152

	
153 153
      OutArcIt(const Digraph& _graph, const Arc& arc) 
154 154
	: Arc(arc), digraph(&_graph) {}
155 155

	
156 156
      OutArcIt& operator++() { 
157 157
	digraph->nextOut(*this);
158 158
	return *this; 
159 159
      }
160 160

	
161 161
    };
162 162

	
163 163

	
164 164
    class InArcIt : public Arc { 
165 165
      const Digraph* digraph;
166 166
    public:
167 167

	
168 168
      InArcIt() { }
169 169

	
170 170
      InArcIt(Invalid i) : Arc(i) { }
171 171

	
172 172
      InArcIt(const Digraph& _graph, const Node& node) 
173 173
	: digraph(&_graph) {
174 174
	_graph.firstIn(*this, node);
175 175
      }
176 176

	
177 177
      InArcIt(const Digraph& _graph, const Arc& arc) : 
178 178
	Arc(arc), digraph(&_graph) {}
179 179

	
180 180
      InArcIt& operator++() { 
181 181
	digraph->nextIn(*this);
182 182
	return *this; 
183 183
      }
184 184

	
185 185
    };
186 186

	
187 187
    // \brief Base node of the iterator
188 188
    //
189 189
    // Returns the base node (ie. the source in this case) of the iterator
190 190
    Node baseNode(const OutArcIt &e) const {
191 191
      return Parent::source(static_cast<const Arc&>(e));
192 192
    }
193 193
    // \brief Running node of the iterator
194 194
    //
195 195
    // Returns the running node (ie. the target in this case) of the
196 196
    // iterator
197 197
    Node runningNode(const OutArcIt &e) const {
198 198
      return Parent::target(static_cast<const Arc&>(e));
199 199
    }
200 200

	
201 201
    // \brief Base node of the iterator
202 202
    //
203 203
    // Returns the base node (ie. the target in this case) of the iterator
204 204
    Node baseNode(const InArcIt &e) const {
205 205
      return Parent::target(static_cast<const Arc&>(e));
206 206
    }
207 207
    // \brief Running node of the iterator
208 208
    //
209 209
    // Returns the running node (ie. the source in this case) of the
210 210
    // iterator
211 211
    Node runningNode(const InArcIt &e) const {
212 212
      return Parent::source(static_cast<const Arc&>(e));
213 213
    }
214 214

	
215 215
    using Parent::first;
216 216

	
217 217
    // Mappable extension
218 218
    
219 219
    template <typename _Value>
220 220
    class ArcMap 
221 221
      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
222 222
      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
223 223

	
224 224
    public:
225 225
      explicit ArcMap(const Digraph& _g) 
226 226
	: Parent(_g) {}
227 227
      ArcMap(const Digraph& _g, const _Value& _v) 
228 228
	: Parent(_g, _v) {}
229 229

	
230 230
      ArcMap& operator=(const ArcMap& cmap) {
231 231
	return operator=<ArcMap>(cmap);
232 232
      }
233 233

	
234 234
      template <typename CMap>
235 235
      ArcMap& operator=(const CMap& cmap) {
236 236
        Parent::operator=(cmap);
237 237
	return *this;
238 238
      }
239 239

	
240 240
    };
241 241

	
242 242

	
243 243
    // Alteration extension
244 244

	
245 245
    Arc addArc(const Node& from, const Node& to) {
246 246
      Arc arc = Parent::addArc(from, to);
247 247
      notifier(Arc()).add(arc);
248 248
      return arc;
249 249
    }
250 250
    
251 251
    void clear() {
252 252
      notifier(Arc()).clear();
253 253
      Parent::clear();
254 254
    }
255 255

	
256 256
    void erase(const Arc& arc) {
257 257
      notifier(Arc()).erase(arc);
258 258
      Parent::erase(arc);
259 259
    }
260 260

	
261 261
    ArcSetExtender() {
262 262
      arc_notifier.setContainer(*this);
263 263
    }
264 264

	
265 265
    ~ArcSetExtender() {
266 266
      arc_notifier.clear();
267 267
    }
268 268

	
269 269
  };
270 270

	
271 271

	
272 272
  // \ingroup digraphbits
273 273
  //
274 274
  // \brief Extender for the EdgeSets
275 275
  template <typename Base>
276 276
  class EdgeSetExtender : public Base {
277 277
    typedef Base Parent;
278 278

	
279 279
  public:
280 280

	
281 281
    typedef EdgeSetExtender Graph;
282 282

	
283 283
    typedef typename Parent::Node Node;
284 284
    typedef typename Parent::Arc Arc;
285 285
    typedef typename Parent::Edge Edge;
286 286

	
287 287
    int maxId(Node) const {
288 288
      return Parent::maxNodeId();
289 289
    }
290 290

	
291 291
    int maxId(Arc) const {
292 292
      return Parent::maxArcId();
293 293
    }
294 294

	
295 295
    int maxId(Edge) const {
296 296
      return Parent::maxEdgeId();
297 297
    }
298 298

	
299 299
    Node fromId(int id, Node) const {
300 300
      return Parent::nodeFromId(id);
301 301
    }
302 302

	
303 303
    Arc fromId(int id, Arc) const {
304 304
      return Parent::arcFromId(id);
305 305
    }
306 306

	
307 307
    Edge fromId(int id, Edge) const {
308 308
      return Parent::edgeFromId(id);
309 309
    }
310 310

	
311 311
    Node oppositeNode(const Node &n, const Edge &e) const {
312 312
      if( n == Parent::u(e))
313 313
	return Parent::v(e);
314 314
      else if( n == Parent::v(e))
315 315
	return Parent::u(e);
316 316
      else
317 317
	return INVALID;
318 318
    }
319 319

	
320 320
    Arc oppositeArc(const Arc &e) const {
321 321
      return Parent::direct(e, !Parent::direction(e));
322 322
    }
323 323

	
324 324
    using Parent::direct;
325 325
    Arc direct(const Edge &e, const Node &s) const {
326 326
      return Parent::direct(e, Parent::u(e) == s);
327 327
    }
328 328

	
329 329
    typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier;
330 330
    typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier;
331 331

	
332 332

	
333 333
  protected:
334 334

	
335 335
    mutable ArcNotifier arc_notifier;
336 336
    mutable EdgeNotifier edge_notifier;
337 337

	
338 338
  public:
339 339

	
340 340
    using Parent::notifier;
341 341
    
342 342
    ArcNotifier& notifier(Arc) const {
343 343
      return arc_notifier;
344 344
    }
345 345

	
346 346
    EdgeNotifier& notifier(Edge) const {
347 347
      return edge_notifier;
348 348
    }
349 349

	
350 350

	
351 351
    class NodeIt : public Node { 
352 352
      const Graph* graph;
353 353
    public:
354 354

	
355 355
      NodeIt() {}
356 356

	
357 357
      NodeIt(Invalid i) : Node(i) { }
358 358

	
359 359
      explicit NodeIt(const Graph& _graph) : graph(&_graph) {
360 360
	_graph.first(static_cast<Node&>(*this));
361 361
      }
362 362

	
363 363
      NodeIt(const Graph& _graph, const Node& node) 
364 364
	: Node(node), graph(&_graph) {}
365 365

	
366 366
      NodeIt& operator++() { 
367 367
	graph->next(*this);
368 368
	return *this; 
369 369
      }
370 370

	
371 371
    };
372 372

	
373 373

	
374 374
    class ArcIt : public Arc { 
375 375
      const Graph* graph;
376 376
    public:
377 377

	
378 378
      ArcIt() { }
379 379

	
380 380
      ArcIt(Invalid i) : Arc(i) { }
381 381

	
382 382
      explicit ArcIt(const Graph& _graph) : graph(&_graph) {
383 383
	_graph.first(static_cast<Arc&>(*this));
384 384
      }
385 385

	
386 386
      ArcIt(const Graph& _graph, const Arc& e) : 
387 387
	Arc(e), graph(&_graph) { }
388 388

	
389 389
      ArcIt& operator++() { 
390 390
	graph->next(*this);
391 391
	return *this; 
392 392
      }
393 393

	
394 394
    };
395 395

	
396 396

	
397 397
    class OutArcIt : public Arc { 
398 398
      const Graph* graph;
399 399
    public:
400 400

	
401 401
      OutArcIt() { }
402 402

	
403 403
      OutArcIt(Invalid i) : Arc(i) { }
404 404

	
405 405
      OutArcIt(const Graph& _graph, const Node& node) 
406 406
	: graph(&_graph) {
407 407
	_graph.firstOut(*this, node);
408 408
      }
409 409

	
410 410
      OutArcIt(const Graph& _graph, const Arc& arc) 
411 411
	: Arc(arc), graph(&_graph) {}
412 412

	
413 413
      OutArcIt& operator++() { 
414 414
	graph->nextOut(*this);
415 415
	return *this; 
416 416
      }
417 417

	
418 418
    };
419 419

	
420 420

	
421 421
    class InArcIt : public Arc { 
422 422
      const Graph* graph;
423 423
    public:
424 424

	
425 425
      InArcIt() { }
426 426

	
427 427
      InArcIt(Invalid i) : Arc(i) { }
428 428

	
429 429
      InArcIt(const Graph& _graph, const Node& node) 
430 430
	: graph(&_graph) {
431 431
	_graph.firstIn(*this, node);
432 432
      }
433 433

	
434 434
      InArcIt(const Graph& _graph, const Arc& arc) : 
435 435
	Arc(arc), graph(&_graph) {}
436 436

	
437 437
      InArcIt& operator++() { 
438 438
	graph->nextIn(*this);
439 439
	return *this; 
440 440
      }
441 441

	
442 442
    };
443 443

	
444 444

	
445 445
    class EdgeIt : public Parent::Edge { 
446 446
      const Graph* graph;
447 447
    public:
448 448

	
449 449
      EdgeIt() { }
450 450

	
451 451
      EdgeIt(Invalid i) : Edge(i) { }
452 452

	
453 453
      explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
454 454
	_graph.first(static_cast<Edge&>(*this));
455 455
      }
456 456

	
457 457
      EdgeIt(const Graph& _graph, const Edge& e) : 
458 458
	Edge(e), graph(&_graph) { }
459 459

	
460 460
      EdgeIt& operator++() { 
461 461
	graph->next(*this);
462 462
	return *this; 
463 463
      }
464 464

	
465 465
    };
466 466

	
467 467
    class IncEdgeIt : public Parent::Edge {
468 468
      friend class EdgeSetExtender;
469 469
      const Graph* graph;
470 470
      bool direction;
471 471
    public:
472 472

	
473 473
      IncEdgeIt() { }
474 474

	
475 475
      IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
476 476

	
477 477
      IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
478 478
	_graph.firstInc(*this, direction, n);
479 479
      }
480 480

	
481 481
      IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n)
482 482
	: graph(&_graph), Edge(ue) {
483 483
	direction = (_graph.source(ue) == n);
484 484
      }
485 485

	
486 486
      IncEdgeIt& operator++() {
487 487
	graph->nextInc(*this, direction);
488 488
	return *this; 
489 489
      }
490 490
    };
491 491

	
492 492
    // \brief Base node of the iterator
493 493
    //
494 494
    // Returns the base node (ie. the source in this case) of the iterator
495 495
    Node baseNode(const OutArcIt &e) const {
496 496
      return Parent::source(static_cast<const Arc&>(e));
497 497
    }
498 498
    // \brief Running node of the iterator
499 499
    //
500 500
    // Returns the running node (ie. the target in this case) of the
501 501
    // iterator
502 502
    Node runningNode(const OutArcIt &e) const {
503 503
      return Parent::target(static_cast<const Arc&>(e));
504 504
    }
505 505

	
506 506
    // \brief Base node of the iterator
507 507
    //
508 508
    // Returns the base node (ie. the target in this case) of the iterator
509 509
    Node baseNode(const InArcIt &e) const {
510 510
      return Parent::target(static_cast<const Arc&>(e));
511 511
    }
512 512
    // \brief Running node of the iterator
513 513
    //
514 514
    // Returns the running node (ie. the source in this case) of the
515 515
    // iterator
516 516
    Node runningNode(const InArcIt &e) const {
517 517
      return Parent::source(static_cast<const Arc&>(e));
518 518
    }
519 519

	
520 520
    // Base node of the iterator
521 521
    //
522 522
    // Returns the base node of the iterator
523 523
    Node baseNode(const IncEdgeIt &e) const {
524 524
      return e.direction ? u(e) : v(e);
525 525
    }
526 526
    // Running node of the iterator
527 527
    //
528 528
    // Returns the running node of the iterator
529 529
    Node runningNode(const IncEdgeIt &e) const {
530 530
      return e.direction ? v(e) : u(e);
531 531
    }
532 532

	
533 533

	
534 534
    template <typename _Value>
535 535
    class ArcMap 
536 536
      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
537 537
      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
538 538

	
539 539
    public:
540
      ArcMap(const Graph& _g) 
540
      explicit ArcMap(const Graph& _g) 
541 541
	: Parent(_g) {}
542 542
      ArcMap(const Graph& _g, const _Value& _v) 
543 543
	: Parent(_g, _v) {}
544 544

	
545 545
      ArcMap& operator=(const ArcMap& cmap) {
546 546
	return operator=<ArcMap>(cmap);
547 547
      }
548 548

	
549 549
      template <typename CMap>
550 550
      ArcMap& operator=(const CMap& cmap) {
551 551
        Parent::operator=(cmap);
552 552
	return *this;
553 553
      }
554 554

	
555 555
    };
556 556

	
557 557

	
558 558
    template <typename _Value>
559 559
    class EdgeMap 
560 560
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
561 561
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
562 562

	
563 563
    public:
564
      EdgeMap(const Graph& _g) 
564
      explicit EdgeMap(const Graph& _g) 
565 565
	: Parent(_g) {}
566 566

	
567 567
      EdgeMap(const Graph& _g, const _Value& _v) 
568 568
	: Parent(_g, _v) {}
569 569

	
570 570
      EdgeMap& operator=(const EdgeMap& cmap) {
571 571
	return operator=<EdgeMap>(cmap);
572 572
      }
573 573

	
574 574
      template <typename CMap>
575 575
      EdgeMap& operator=(const CMap& cmap) {
576 576
        Parent::operator=(cmap);
577 577
	return *this;
578 578
      }
579 579

	
580 580
    };
581 581

	
582 582

	
583 583
    // Alteration extension
584 584

	
585 585
    Edge addEdge(const Node& from, const Node& to) {
586 586
      Edge edge = Parent::addEdge(from, to);
587 587
      notifier(Edge()).add(edge);
588 588
      std::vector<Arc> arcs;
589 589
      arcs.push_back(Parent::direct(edge, true));
590 590
      arcs.push_back(Parent::direct(edge, false));
591 591
      notifier(Arc()).add(arcs);
592 592
      return edge;
593 593
    }
594 594
    
595 595
    void clear() {
596 596
      notifier(Arc()).clear();
597 597
      notifier(Edge()).clear();
598 598
      Parent::clear();
599 599
    }
600 600

	
601 601
    void erase(const Edge& edge) {
602 602
      std::vector<Arc> arcs;
603 603
      arcs.push_back(Parent::direct(edge, true));
604 604
      arcs.push_back(Parent::direct(edge, false));
605 605
      notifier(Arc()).erase(arcs);
606 606
      notifier(Edge()).erase(edge);
607 607
      Parent::erase(edge);
608 608
    }
609 609

	
610 610

	
611 611
    EdgeSetExtender() {
612 612
      arc_notifier.setContainer(*this);
613 613
      edge_notifier.setContainer(*this);
614 614
    }
615 615

	
616 616
    ~EdgeSetExtender() {
617 617
      edge_notifier.clear();
618 618
      arc_notifier.clear();
619 619
    }
620 620
    
621 621
  };
622 622

	
623 623
}
624 624

	
625 625
#endif
Show white space 2048 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
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_BITS_GRAPH_EXTENDER_H
20 20
#define LEMON_BITS_GRAPH_EXTENDER_H
21 21

	
22 22
#include <lemon/core.h>
23 23

	
24 24
#include <lemon/bits/map_extender.h>
25 25
#include <lemon/bits/default_map.h>
26 26

	
27 27
#include <lemon/concept_check.h>
28 28
#include <lemon/concepts/maps.h>
29 29

	
30 30
//\ingroup graphbits
31 31
//\file
32 32
//\brief Extenders for the graph types
33 33
namespace lemon {
34 34

	
35 35
  // \ingroup graphbits
36 36
  //
37 37
  // \brief Extender for the digraph implementations
38 38
  template <typename Base>
39 39
  class DigraphExtender : public Base {
40 40
    typedef Base Parent;
41 41

	
42 42
  public:
43 43

	
44 44
    typedef DigraphExtender Digraph;
45 45

	
46 46
    // Base extensions
47 47

	
48 48
    typedef typename Parent::Node Node;
49 49
    typedef typename Parent::Arc Arc;
50 50

	
51 51
    int maxId(Node) const {
52 52
      return Parent::maxNodeId();
53 53
    }
54 54

	
55 55
    int maxId(Arc) const {
56 56
      return Parent::maxArcId();
57 57
    }
58 58

	
59 59
    Node fromId(int id, Node) const {
60 60
      return Parent::nodeFromId(id);
61 61
    }
62 62

	
63 63
    Arc fromId(int id, Arc) const {
64 64
      return Parent::arcFromId(id);
65 65
    }
66 66

	
67 67
    Node oppositeNode(const Node &node, const Arc &arc) const {
68 68
      if (node == Parent::source(arc))
69 69
        return Parent::target(arc);
70 70
      else if(node == Parent::target(arc))
71 71
        return Parent::source(arc);
72 72
      else
73 73
        return INVALID;
74 74
    }
75 75

	
76 76
    // Alterable extension
77 77

	
78 78
    typedef AlterationNotifier<DigraphExtender, Node> NodeNotifier;
79 79
    typedef AlterationNotifier<DigraphExtender, Arc> ArcNotifier;
80 80

	
81 81

	
82 82
  protected:
83 83

	
84 84
    mutable NodeNotifier node_notifier;
85 85
    mutable ArcNotifier arc_notifier;
86 86

	
87 87
  public:
88 88

	
89 89
    NodeNotifier& notifier(Node) const {
90 90
      return node_notifier;
91 91
    }
92 92

	
93 93
    ArcNotifier& notifier(Arc) const {
94 94
      return arc_notifier;
95 95
    }
96 96

	
97 97
    class NodeIt : public Node {
98 98
      const Digraph* _digraph;
99 99
    public:
100 100

	
101 101
      NodeIt() {}
102 102

	
103 103
      NodeIt(Invalid i) : Node(i) { }
104 104

	
105 105
      explicit NodeIt(const Digraph& digraph) : _digraph(&digraph) {
106 106
        _digraph->first(static_cast<Node&>(*this));
107 107
      }
108 108

	
109 109
      NodeIt(const Digraph& digraph, const Node& node)
110 110
        : Node(node), _digraph(&digraph) {}
111 111

	
112 112
      NodeIt& operator++() {
113 113
        _digraph->next(*this);
114 114
        return *this;
115 115
      }
116 116

	
117 117
    };
118 118

	
119 119

	
120 120
    class ArcIt : public Arc {
121 121
      const Digraph* _digraph;
122 122
    public:
123 123

	
124 124
      ArcIt() { }
125 125

	
126 126
      ArcIt(Invalid i) : Arc(i) { }
127 127

	
128 128
      explicit ArcIt(const Digraph& digraph) : _digraph(&digraph) {
129 129
        _digraph->first(static_cast<Arc&>(*this));
130 130
      }
131 131

	
132 132
      ArcIt(const Digraph& digraph, const Arc& arc) :
133 133
        Arc(arc), _digraph(&digraph) { }
134 134

	
135 135
      ArcIt& operator++() {
136 136
        _digraph->next(*this);
137 137
        return *this;
138 138
      }
139 139

	
140 140
    };
141 141

	
142 142

	
143 143
    class OutArcIt : public Arc {
144 144
      const Digraph* _digraph;
145 145
    public:
146 146

	
147 147
      OutArcIt() { }
148 148

	
149 149
      OutArcIt(Invalid i) : Arc(i) { }
150 150

	
151 151
      OutArcIt(const Digraph& digraph, const Node& node)
152 152
        : _digraph(&digraph) {
153 153
        _digraph->firstOut(*this, node);
154 154
      }
155 155

	
156 156
      OutArcIt(const Digraph& digraph, const Arc& arc)
157 157
        : Arc(arc), _digraph(&digraph) {}
158 158

	
159 159
      OutArcIt& operator++() {
160 160
        _digraph->nextOut(*this);
161 161
        return *this;
162 162
      }
163 163

	
164 164
    };
165 165

	
166 166

	
167 167
    class InArcIt : public Arc {
168 168
      const Digraph* _digraph;
169 169
    public:
170 170

	
171 171
      InArcIt() { }
172 172

	
173 173
      InArcIt(Invalid i) : Arc(i) { }
174 174

	
175 175
      InArcIt(const Digraph& digraph, const Node& node)
176 176
        : _digraph(&digraph) {
177 177
        _digraph->firstIn(*this, node);
178 178
      }
179 179

	
180 180
      InArcIt(const Digraph& digraph, const Arc& arc) :
181 181
        Arc(arc), _digraph(&digraph) {}
182 182

	
183 183
      InArcIt& operator++() {
184 184
        _digraph->nextIn(*this);
185 185
        return *this;
186 186
      }
187 187

	
188 188
    };
189 189

	
190 190
    // \brief Base node of the iterator
191 191
    //
192 192
    // Returns the base node (i.e. the source in this case) of the iterator
193 193
    Node baseNode(const OutArcIt &arc) const {
194 194
      return Parent::source(arc);
195 195
    }
196 196
    // \brief Running node of the iterator
197 197
    //
198 198
    // Returns the running node (i.e. the target in this case) of the
199 199
    // iterator
200 200
    Node runningNode(const OutArcIt &arc) const {
201 201
      return Parent::target(arc);
202 202
    }
203 203

	
204 204
    // \brief Base node of the iterator
205 205
    //
206 206
    // Returns the base node (i.e. the target in this case) of the iterator
207 207
    Node baseNode(const InArcIt &arc) const {
208 208
      return Parent::target(arc);
209 209
    }
210 210
    // \brief Running node of the iterator
211 211
    //
212 212
    // Returns the running node (i.e. the source in this case) of the
213 213
    // iterator
214 214
    Node runningNode(const InArcIt &arc) const {
215 215
      return Parent::source(arc);
216 216
    }
217 217

	
218 218

	
219 219
    template <typename _Value>
220 220
    class NodeMap
221 221
      : public MapExtender<DefaultMap<Digraph, Node, _Value> > {
222 222
      typedef MapExtender<DefaultMap<Digraph, Node, _Value> > Parent;
223 223

	
224 224
    public:
225 225
      explicit NodeMap(const Digraph& digraph)
226 226
        : Parent(digraph) {}
227 227
      NodeMap(const Digraph& digraph, const _Value& value)
228 228
        : Parent(digraph, value) {}
229 229

	
230 230
    private:
231 231
      NodeMap& operator=(const NodeMap& cmap) {
232 232
        return operator=<NodeMap>(cmap);
233 233
      }
234 234

	
235 235
      template <typename CMap>
236 236
      NodeMap& operator=(const CMap& cmap) {
237 237
        Parent::operator=(cmap);
238 238
        return *this;
239 239
      }
240 240

	
241 241
    };
242 242

	
243 243
    template <typename _Value>
244 244
    class ArcMap
245 245
      : public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
246 246
      typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent;
247 247

	
248 248
    public:
249 249
      explicit ArcMap(const Digraph& digraph)
250 250
        : Parent(digraph) {}
251 251
      ArcMap(const Digraph& digraph, const _Value& value)
252 252
        : Parent(digraph, value) {}
253 253

	
254 254
    private:
255 255
      ArcMap& operator=(const ArcMap& cmap) {
256 256
        return operator=<ArcMap>(cmap);
257 257
      }
258 258

	
259 259
      template <typename CMap>
260 260
      ArcMap& operator=(const CMap& cmap) {
261 261
        Parent::operator=(cmap);
262 262
        return *this;
263 263
      }
264 264
    };
265 265

	
266 266

	
267 267
    Node addNode() {
268 268
      Node node = Parent::addNode();
269 269
      notifier(Node()).add(node);
270 270
      return node;
271 271
    }
272 272

	
273 273
    Arc addArc(const Node& from, const Node& to) {
274 274
      Arc arc = Parent::addArc(from, to);
275 275
      notifier(Arc()).add(arc);
276 276
      return arc;
277 277
    }
278 278

	
279 279
    void clear() {
280 280
      notifier(Arc()).clear();
281 281
      notifier(Node()).clear();
282 282
      Parent::clear();
283 283
    }
284 284

	
285 285
    template <typename Digraph, typename NodeRefMap, typename ArcRefMap>
286 286
    void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
287 287
      Parent::build(digraph, nodeRef, arcRef);
288 288
      notifier(Node()).build();
289 289
      notifier(Arc()).build();
290 290
    }
291 291

	
292 292
    void erase(const Node& node) {
293 293
      Arc arc;
294 294
      Parent::firstOut(arc, node);
295 295
      while (arc != INVALID ) {
296 296
        erase(arc);
297 297
        Parent::firstOut(arc, node);
298 298
      }
299 299

	
300 300
      Parent::firstIn(arc, node);
301 301
      while (arc != INVALID ) {
302 302
        erase(arc);
303 303
        Parent::firstIn(arc, node);
304 304
      }
305 305

	
306 306
      notifier(Node()).erase(node);
307 307
      Parent::erase(node);
308 308
    }
309 309

	
310 310
    void erase(const Arc& arc) {
311 311
      notifier(Arc()).erase(arc);
312 312
      Parent::erase(arc);
313 313
    }
314 314

	
315 315
    DigraphExtender() {
316 316
      node_notifier.setContainer(*this);
317 317
      arc_notifier.setContainer(*this);
318 318
    }
319 319

	
320 320

	
321 321
    ~DigraphExtender() {
322 322
      arc_notifier.clear();
323 323
      node_notifier.clear();
324 324
    }
325 325
  };
326 326

	
327 327
  // \ingroup _graphbits
328 328
  //
329 329
  // \brief Extender for the Graphs
330 330
  template <typename Base>
331 331
  class GraphExtender : public Base {
332 332
    typedef Base Parent;
333 333

	
334 334
  public:
335 335

	
336 336
    typedef GraphExtender Graph;
337 337

	
338 338
    typedef True UndirectedTag;
339 339

	
340 340
    typedef typename Parent::Node Node;
341 341
    typedef typename Parent::Arc Arc;
342 342
    typedef typename Parent::Edge Edge;
343 343

	
344 344
    // Graph extension
345 345

	
346 346
    int maxId(Node) const {
347 347
      return Parent::maxNodeId();
348 348
    }
349 349

	
350 350
    int maxId(Arc) const {
351 351
      return Parent::maxArcId();
352 352
    }
353 353

	
354 354
    int maxId(Edge) const {
355 355
      return Parent::maxEdgeId();
356 356
    }
357 357

	
358 358
    Node fromId(int id, Node) const {
359 359
      return Parent::nodeFromId(id);
360 360
    }
361 361

	
362 362
    Arc fromId(int id, Arc) const {
363 363
      return Parent::arcFromId(id);
364 364
    }
365 365

	
366 366
    Edge fromId(int id, Edge) const {
367 367
      return Parent::edgeFromId(id);
368 368
    }
369 369

	
370 370
    Node oppositeNode(const Node &n, const Edge &e) const {
371 371
      if( n == Parent::u(e))
372 372
        return Parent::v(e);
373 373
      else if( n == Parent::v(e))
374 374
        return Parent::u(e);
375 375
      else
376 376
        return INVALID;
377 377
    }
378 378

	
379 379
    Arc oppositeArc(const Arc &arc) const {
380 380
      return Parent::direct(arc, !Parent::direction(arc));
381 381
    }
382 382

	
383 383
    using Parent::direct;
384 384
    Arc direct(const Edge &edge, const Node &node) const {
385 385
      return Parent::direct(edge, Parent::u(edge) == node);
386 386
    }
387 387

	
388 388
    // Alterable extension
389 389

	
390 390
    typedef AlterationNotifier<GraphExtender, Node> NodeNotifier;
391 391
    typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier;
392 392
    typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier;
393 393

	
394 394

	
395 395
  protected:
396 396

	
397 397
    mutable NodeNotifier node_notifier;
398 398
    mutable ArcNotifier arc_notifier;
399 399
    mutable EdgeNotifier edge_notifier;
400 400

	
401 401
  public:
402 402

	
403 403
    NodeNotifier& notifier(Node) const {
404 404
      return node_notifier;
405 405
    }
406 406

	
407 407
    ArcNotifier& notifier(Arc) const {
408 408
      return arc_notifier;
409 409
    }
410 410

	
411 411
    EdgeNotifier& notifier(Edge) const {
412 412
      return edge_notifier;
413 413
    }
414 414

	
415 415

	
416 416

	
417 417
    class NodeIt : public Node {
418 418
      const Graph* _graph;
419 419
    public:
420 420

	
421 421
      NodeIt() {}
422 422

	
423 423
      NodeIt(Invalid i) : Node(i) { }
424 424

	
425 425
      explicit NodeIt(const Graph& graph) : _graph(&graph) {
426 426
        _graph->first(static_cast<Node&>(*this));
427 427
      }
428 428

	
429 429
      NodeIt(const Graph& graph, const Node& node)
430 430
        : Node(node), _graph(&graph) {}
431 431

	
432 432
      NodeIt& operator++() {
433 433
        _graph->next(*this);
434 434
        return *this;
435 435
      }
436 436

	
437 437
    };
438 438

	
439 439

	
440 440
    class ArcIt : public Arc {
441 441
      const Graph* _graph;
442 442
    public:
443 443

	
444 444
      ArcIt() { }
445 445

	
446 446
      ArcIt(Invalid i) : Arc(i) { }
447 447

	
448 448
      explicit ArcIt(const Graph& graph) : _graph(&graph) {
449 449
        _graph->first(static_cast<Arc&>(*this));
450 450
      }
451 451

	
452 452
      ArcIt(const Graph& graph, const Arc& arc) :
453 453
        Arc(arc), _graph(&graph) { }
454 454

	
455 455
      ArcIt& operator++() {
456 456
        _graph->next(*this);
457 457
        return *this;
458 458
      }
459 459

	
460 460
    };
461 461

	
462 462

	
463 463
    class OutArcIt : public Arc {
464 464
      const Graph* _graph;
465 465
    public:
466 466

	
467 467
      OutArcIt() { }
468 468

	
469 469
      OutArcIt(Invalid i) : Arc(i) { }
470 470

	
471 471
      OutArcIt(const Graph& graph, const Node& node)
472 472
        : _graph(&graph) {
473 473
        _graph->firstOut(*this, node);
474 474
      }
475 475

	
476 476
      OutArcIt(const Graph& graph, const Arc& arc)
477 477
        : Arc(arc), _graph(&graph) {}
478 478

	
479 479
      OutArcIt& operator++() {
480 480
        _graph->nextOut(*this);
481 481
        return *this;
482 482
      }
483 483

	
484 484
    };
485 485

	
486 486

	
487 487
    class InArcIt : public Arc {
488 488
      const Graph* _graph;
489 489
    public:
490 490

	
491 491
      InArcIt() { }
492 492

	
493 493
      InArcIt(Invalid i) : Arc(i) { }
494 494

	
495 495
      InArcIt(const Graph& graph, const Node& node)
496 496
        : _graph(&graph) {
497 497
        _graph->firstIn(*this, node);
498 498
      }
499 499

	
500 500
      InArcIt(const Graph& graph, const Arc& arc) :
501 501
        Arc(arc), _graph(&graph) {}
502 502

	
503 503
      InArcIt& operator++() {
504 504
        _graph->nextIn(*this);
505 505
        return *this;
506 506
      }
507 507

	
508 508
    };
509 509

	
510 510

	
511 511
    class EdgeIt : public Parent::Edge {
512 512
      const Graph* _graph;
513 513
    public:
514 514

	
515 515
      EdgeIt() { }
516 516

	
517 517
      EdgeIt(Invalid i) : Edge(i) { }
518 518

	
519 519
      explicit EdgeIt(const Graph& graph) : _graph(&graph) {
520 520
        _graph->first(static_cast<Edge&>(*this));
521 521
      }
522 522

	
523 523
      EdgeIt(const Graph& graph, const Edge& edge) :
524 524
        Edge(edge), _graph(&graph) { }
525 525

	
526 526
      EdgeIt& operator++() {
527 527
        _graph->next(*this);
528 528
        return *this;
529 529
      }
530 530

	
531 531
    };
532 532

	
533 533
    class IncEdgeIt : public Parent::Edge {
534 534
      friend class GraphExtender;
535 535
      const Graph* _graph;
536 536
      bool _direction;
537 537
    public:
538 538

	
539 539
      IncEdgeIt() { }
540 540

	
541 541
      IncEdgeIt(Invalid i) : Edge(i), _direction(false) { }
542 542

	
543 543
      IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) {
544 544
        _graph->firstInc(*this, _direction, node);
545 545
      }
546 546

	
547 547
      IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node)
548 548
        : _graph(&graph), Edge(edge) {
549 549
        _direction = (_graph->source(edge) == node);
550 550
      }
551 551

	
552 552
      IncEdgeIt& operator++() {
553 553
        _graph->nextInc(*this, _direction);
554 554
        return *this;
555 555
      }
556 556
    };
557 557

	
558 558
    // \brief Base node of the iterator
559 559
    //
560 560
    // Returns the base node (ie. the source in this case) of the iterator
561 561
    Node baseNode(const OutArcIt &arc) const {
562 562
      return Parent::source(static_cast<const Arc&>(arc));
563 563
    }
564 564
    // \brief Running node of the iterator
565 565
    //
566 566
    // Returns the running node (ie. the target in this case) of the
567 567
    // iterator
568 568
    Node runningNode(const OutArcIt &arc) const {
569 569
      return Parent::target(static_cast<const Arc&>(arc));
570 570
    }
571 571

	
572 572
    // \brief Base node of the iterator
573 573
    //
574 574
    // Returns the base node (ie. the target in this case) of the iterator
575 575
    Node baseNode(const InArcIt &arc) const {
576 576
      return Parent::target(static_cast<const Arc&>(arc));
577 577
    }
578 578
    // \brief Running node of the iterator
579 579
    //
580 580
    // Returns the running node (ie. the source in this case) of the
581 581
    // iterator
582 582
    Node runningNode(const InArcIt &arc) const {
583 583
      return Parent::source(static_cast<const Arc&>(arc));
584 584
    }
585 585

	
586 586
    // Base node of the iterator
587 587
    //
588 588
    // Returns the base node of the iterator
589 589
    Node baseNode(const IncEdgeIt &edge) const {
590 590
      return edge._direction ? u(edge) : v(edge);
591 591
    }
592 592
    // Running node of the iterator
593 593
    //
594 594
    // Returns the running node of the iterator
595 595
    Node runningNode(const IncEdgeIt &edge) const {
596 596
      return edge._direction ? v(edge) : u(edge);
597 597
    }
598 598

	
599 599
    // Mappable extension
600 600

	
601 601
    template <typename _Value>
602 602
    class NodeMap
603 603
      : public MapExtender<DefaultMap<Graph, Node, _Value> > {
604 604
      typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent;
605 605

	
606 606
    public:
607
      NodeMap(const Graph& graph)
607
      explicit NodeMap(const Graph& graph)
608 608
        : Parent(graph) {}
609 609
      NodeMap(const Graph& graph, const _Value& value)
610 610
        : Parent(graph, value) {}
611 611

	
612 612
    private:
613 613
      NodeMap& operator=(const NodeMap& cmap) {
614 614
        return operator=<NodeMap>(cmap);
615 615
      }
616 616

	
617 617
      template <typename CMap>
618 618
      NodeMap& operator=(const CMap& cmap) {
619 619
        Parent::operator=(cmap);
620 620
        return *this;
621 621
      }
622 622

	
623 623
    };
624 624

	
625 625
    template <typename _Value>
626 626
    class ArcMap
627 627
      : public MapExtender<DefaultMap<Graph, Arc, _Value> > {
628 628
      typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent;
629 629

	
630 630
    public:
631
      ArcMap(const Graph& graph)
631
      explicit ArcMap(const Graph& graph)
632 632
        : Parent(graph) {}
633 633
      ArcMap(const Graph& graph, const _Value& value)
634 634
        : Parent(graph, value) {}
635 635

	
636 636
    private:
637 637
      ArcMap& operator=(const ArcMap& cmap) {
638 638
        return operator=<ArcMap>(cmap);
639 639
      }
640 640

	
641 641
      template <typename CMap>
642 642
      ArcMap& operator=(const CMap& cmap) {
643 643
        Parent::operator=(cmap);
644 644
        return *this;
645 645
      }
646 646
    };
647 647

	
648 648

	
649 649
    template <typename _Value>
650 650
    class EdgeMap
651 651
      : public MapExtender<DefaultMap<Graph, Edge, _Value> > {
652 652
      typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent;
653 653

	
654 654
    public:
655
      EdgeMap(const Graph& graph)
655
      explicit EdgeMap(const Graph& graph)
656 656
        : Parent(graph) {}
657 657

	
658 658
      EdgeMap(const Graph& graph, const _Value& value)
659 659
        : Parent(graph, value) {}
660 660

	
661 661
    private:
662 662
      EdgeMap& operator=(const EdgeMap& cmap) {
663 663
        return operator=<EdgeMap>(cmap);
664 664
      }
665 665

	
666 666
      template <typename CMap>
667 667
      EdgeMap& operator=(const CMap& cmap) {
668 668
        Parent::operator=(cmap);
669 669
        return *this;
670 670
      }
671 671

	
672 672
    };
673 673

	
674 674
    // Alteration extension
675 675

	
676 676
    Node addNode() {
677 677
      Node node = Parent::addNode();
678 678
      notifier(Node()).add(node);
679 679
      return node;
680 680
    }
681 681

	
682 682
    Edge addEdge(const Node& from, const Node& to) {
683 683
      Edge edge = Parent::addEdge(from, to);
684 684
      notifier(Edge()).add(edge);
685 685
      std::vector<Arc> ev;
686 686
      ev.push_back(Parent::direct(edge, true));
687 687
      ev.push_back(Parent::direct(edge, false));
688 688
      notifier(Arc()).add(ev);
689 689
      return edge;
690 690
    }
691 691

	
692 692
    void clear() {
693 693
      notifier(Arc()).clear();
694 694
      notifier(Edge()).clear();
695 695
      notifier(Node()).clear();
696 696
      Parent::clear();
697 697
    }
698 698

	
699 699
    template <typename Graph, typename NodeRefMap, typename EdgeRefMap>
700 700
    void build(const Graph& graph, NodeRefMap& nodeRef,
701 701
               EdgeRefMap& edgeRef) {
702 702
      Parent::build(graph, nodeRef, edgeRef);
703 703
      notifier(Node()).build();
704 704
      notifier(Edge()).build();
705 705
      notifier(Arc()).build();
706 706
    }
707 707

	
708 708
    void erase(const Node& node) {
709 709
      Arc arc;
710 710
      Parent::firstOut(arc, node);
711 711
      while (arc != INVALID ) {
712 712
        erase(arc);
713 713
        Parent::firstOut(arc, node);
714 714
      }
715 715

	
716 716
      Parent::firstIn(arc, node);
717 717
      while (arc != INVALID ) {
718 718
        erase(arc);
719 719
        Parent::firstIn(arc, node);
720 720
      }
721 721

	
722 722
      notifier(Node()).erase(node);
723 723
      Parent::erase(node);
724 724
    }
725 725

	
726 726
    void erase(const Edge& edge) {
727 727
      std::vector<Arc> av;
728 728
      av.push_back(Parent::direct(edge, true));
729 729
      av.push_back(Parent::direct(edge, false));
730 730
      notifier(Arc()).erase(av);
731 731
      notifier(Edge()).erase(edge);
732 732
      Parent::erase(edge);
733 733
    }
734 734

	
735 735
    GraphExtender() {
736 736
      node_notifier.setContainer(*this);
737 737
      arc_notifier.setContainer(*this);
738 738
      edge_notifier.setContainer(*this);
739 739
    }
740 740

	
741 741
    ~GraphExtender() {
742 742
      edge_notifier.clear();
743 743
      arc_notifier.clear();
744 744
      node_notifier.clear();
745 745
    }
746 746

	
747 747
  };
748 748

	
749 749
}
750 750

	
751 751
#endif
0 comments (0 inline)