gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Add a warning for List(Di)Graph::Snapshot (#311) and extend tests for snapshots
0 3 0
default
3 files changed with 23 insertions and 0 deletions:
↑ Collapse diff ↑
Ignore white space 64 line context
... ...
@@ -722,64 +722,67 @@
722 722
      /// Default constructor.
723 723
      /// You have to call save() to actually make a snapshot.
724 724
      Snapshot()
725 725
        : digraph(0), node_observer_proxy(*this),
726 726
          arc_observer_proxy(*this) {}
727 727

	
728 728
      /// \brief Constructor that immediately makes a snapshot.
729 729
      ///
730 730
      /// This constructor immediately makes a snapshot of the given digraph.
731 731
      Snapshot(ListDigraph &gr)
732 732
        : node_observer_proxy(*this),
733 733
          arc_observer_proxy(*this) {
734 734
        attach(gr);
735 735
      }
736 736

	
737 737
      /// \brief Make a snapshot.
738 738
      ///
739 739
      /// This function makes a snapshot of the given digraph.
740 740
      /// It can be called more than once. In case of a repeated
741 741
      /// call, the previous snapshot gets lost.
742 742
      void save(ListDigraph &gr) {
743 743
        if (attached()) {
744 744
          detach();
745 745
          clear();
746 746
        }
747 747
        attach(gr);
748 748
      }
749 749

	
750 750
      /// \brief Undo the changes until the last snapshot.
751 751
      ///
752 752
      /// This function undos the changes until the last snapshot
753 753
      /// created by save() or Snapshot(ListDigraph&).
754
      ///
755
      /// \warning This method invalidates the snapshot, i.e. repeated
756
      /// restoring is not supported unless you call save() again.
754 757
      void restore() {
755 758
        detach();
756 759
        for(std::list<Arc>::iterator it = added_arcs.begin();
757 760
            it != added_arcs.end(); ++it) {
758 761
          digraph->erase(*it);
759 762
        }
760 763
        for(std::list<Node>::iterator it = added_nodes.begin();
761 764
            it != added_nodes.end(); ++it) {
762 765
          digraph->erase(*it);
763 766
        }
764 767
        clear();
765 768
      }
766 769

	
767 770
      /// \brief Returns \c true if the snapshot is valid.
768 771
      ///
769 772
      /// This function returns \c true if the snapshot is valid.
770 773
      bool valid() const {
771 774
        return attached();
772 775
      }
773 776
    };
774 777

	
775 778
  };
776 779

	
777 780
  ///@}
778 781

	
779 782
  class ListGraphBase {
780 783

	
781 784
  protected:
782 785

	
783 786
    struct NodeT {
784 787
      int first_out;
785 788
      int prev, next;
... ...
@@ -1521,59 +1524,62 @@
1521 1524
      /// Default constructor.
1522 1525
      /// You have to call save() to actually make a snapshot.
1523 1526
      Snapshot()
1524 1527
        : graph(0), node_observer_proxy(*this),
1525 1528
          edge_observer_proxy(*this) {}
1526 1529

	
1527 1530
      /// \brief Constructor that immediately makes a snapshot.
1528 1531
      ///
1529 1532
      /// This constructor immediately makes a snapshot of the given graph.
1530 1533
      Snapshot(ListGraph &gr)
1531 1534
        : node_observer_proxy(*this),
1532 1535
          edge_observer_proxy(*this) {
1533 1536
        attach(gr);
1534 1537
      }
1535 1538

	
1536 1539
      /// \brief Make a snapshot.
1537 1540
      ///
1538 1541
      /// This function makes a snapshot of the given graph.
1539 1542
      /// It can be called more than once. In case of a repeated
1540 1543
      /// call, the previous snapshot gets lost.
1541 1544
      void save(ListGraph &gr) {
1542 1545
        if (attached()) {
1543 1546
          detach();
1544 1547
          clear();
1545 1548
        }
1546 1549
        attach(gr);
1547 1550
      }
1548 1551

	
1549 1552
      /// \brief Undo the changes until the last snapshot.
1550 1553
      ///
1551 1554
      /// This function undos the changes until the last snapshot
1552 1555
      /// created by save() or Snapshot(ListGraph&).
1556
      ///
1557
      /// \warning This method invalidates the snapshot, i.e. repeated
1558
      /// restoring is not supported unless you call save() again.
1553 1559
      void restore() {
1554 1560
        detach();
1555 1561
        for(std::list<Edge>::iterator it = added_edges.begin();
1556 1562
            it != added_edges.end(); ++it) {
1557 1563
          graph->erase(*it);
1558 1564
        }
1559 1565
        for(std::list<Node>::iterator it = added_nodes.begin();
1560 1566
            it != added_nodes.end(); ++it) {
1561 1567
          graph->erase(*it);
1562 1568
        }
1563 1569
        clear();
1564 1570
      }
1565 1571

	
1566 1572
      /// \brief Returns \c true if the snapshot is valid.
1567 1573
      ///
1568 1574
      /// This function returns \c true if the snapshot is valid.
1569 1575
      bool valid() const {
1570 1576
        return attached();
1571 1577
      }
1572 1578
    };
1573 1579
  };
1574 1580

	
1575 1581
  /// @}
1576 1582
} //namespace lemon
1577 1583

	
1578 1584

	
1579 1585
#endif
Ignore white space 6 line context
... ...
@@ -257,64 +257,72 @@
257 257
  G.addArc(n3, n);
258 258
  G.addArc(n, n3);
259 259

	
260 260
  checkGraphNodeList(G, 4);
261 261
  checkGraphArcList(G, 6);
262 262

	
263 263
  snapshot.restore();
264 264

	
265 265
  checkGraphNodeList(G, 3);
266 266
  checkGraphArcList(G, 4);
267 267

	
268 268
  checkGraphOutArcList(G, n1, 1);
269 269
  checkGraphOutArcList(G, n2, 3);
270 270
  checkGraphOutArcList(G, n3, 0);
271 271

	
272 272
  checkGraphInArcList(G, n1, 1);
273 273
  checkGraphInArcList(G, n2, 1);
274 274
  checkGraphInArcList(G, n3, 2);
275 275

	
276 276
  checkGraphConArcList(G, 4);
277 277

	
278 278
  checkNodeIds(G);
279 279
  checkArcIds(G);
280 280
  checkGraphNodeMap(G);
281 281
  checkGraphArcMap(G);
282 282

	
283 283
  G.addNode();
284 284
  snapshot.save(G);
285 285

	
286 286
  G.addArc(G.addNode(), G.addNode());
287 287

	
288 288
  snapshot.restore();
289
  snapshot.save(G);
290

	
291
  checkGraphNodeList(G, 4);
292
  checkGraphArcList(G, 4);
293

	
294
  G.addArc(G.addNode(), G.addNode());
295

	
296
  snapshot.restore();
289 297

	
290 298
  checkGraphNodeList(G, 4);
291 299
  checkGraphArcList(G, 4);
292 300
}
293 301

	
294 302
void checkConcepts() {
295 303
  { // Checking digraph components
296 304
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
297 305

	
298 306
    checkConcept<IDableDigraphComponent<>,
299 307
      IDableDigraphComponent<> >();
300 308

	
301 309
    checkConcept<IterableDigraphComponent<>,
302 310
      IterableDigraphComponent<> >();
303 311

	
304 312
    checkConcept<MappableDigraphComponent<>,
305 313
      MappableDigraphComponent<> >();
306 314
  }
307 315
  { // Checking skeleton digraph
308 316
    checkConcept<Digraph, Digraph>();
309 317
  }
310 318
  { // Checking ListDigraph
311 319
    checkConcept<Digraph, ListDigraph>();
312 320
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
313 321
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
314 322
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
315 323
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
316 324
  }
317 325
  { // Checking SmartDigraph
318 326
    checkConcept<Digraph, SmartDigraph>();
319 327
    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
320 328
    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
Ignore white space 6 line context
... ...
@@ -230,64 +230,73 @@
230 230
  G.addEdge(n3, n2);
231 231

	
232 232
  checkGraphNodeList(G, 4);
233 233
  checkGraphEdgeList(G, 6);
234 234
  checkGraphArcList(G, 12);
235 235

	
236 236
  snapshot.restore();
237 237

	
238 238
  checkGraphNodeList(G, 3);
239 239
  checkGraphEdgeList(G, 3);
240 240
  checkGraphArcList(G, 6);
241 241

	
242 242
  checkGraphIncEdgeArcLists(G, n1, 2);
243 243
  checkGraphIncEdgeArcLists(G, n2, 3);
244 244
  checkGraphIncEdgeArcLists(G, n3, 1);
245 245

	
246 246
  checkGraphConEdgeList(G, 3);
247 247
  checkGraphConArcList(G, 6);
248 248

	
249 249
  checkNodeIds(G);
250 250
  checkEdgeIds(G);
251 251
  checkArcIds(G);
252 252
  checkGraphNodeMap(G);
253 253
  checkGraphEdgeMap(G);
254 254
  checkGraphArcMap(G);
255 255

	
256 256
  G.addNode();
257 257
  snapshot.save(G);
258 258

	
259 259
  G.addEdge(G.addNode(), G.addNode());
260 260

	
261 261
  snapshot.restore();
262
  snapshot.save(G);
263

	
264
  checkGraphNodeList(G, 4);
265
  checkGraphEdgeList(G, 3);
266
  checkGraphArcList(G, 6);
267
  
268
  G.addEdge(G.addNode(), G.addNode());
269

	
270
  snapshot.restore();
262 271

	
263 272
  checkGraphNodeList(G, 4);
264 273
  checkGraphEdgeList(G, 3);
265 274
  checkGraphArcList(G, 6);
266 275
}
267 276

	
268 277
void checkFullGraph(int num) {
269 278
  typedef FullGraph Graph;
270 279
  GRAPH_TYPEDEFS(Graph);
271 280

	
272 281
  Graph G(num);
273 282
  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
274 283
        "Wrong size");
275 284

	
276 285
  G.resize(num);
277 286
  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
278 287
        "Wrong size");
279 288

	
280 289
  checkGraphNodeList(G, num);
281 290
  checkGraphEdgeList(G, num * (num - 1) / 2);
282 291

	
283 292
  for (NodeIt n(G); n != INVALID; ++n) {
284 293
    checkGraphOutArcList(G, n, num - 1);
285 294
    checkGraphInArcList(G, n, num - 1);
286 295
    checkGraphIncEdgeList(G, n, num - 1);
287 296
  }
288 297

	
289 298
  checkGraphConArcList(G, num * (num - 1));
290 299
  checkGraphConEdgeList(G, num * (num - 1) / 2);
291 300

	
292 301
  checkArcDirections(G);
293 302

	
0 comments (0 inline)