Instruction Manual

Isomorphic Persistence of a Tools.h++ Class
The following example shows the isomorphic persistence of a templatized collection of
RWCollectable integers, RWTPtrDlist<RWCollectableInt>. RWTPtrDlist is a templatized,
reference-based, doubly-linked list that uses isomorphic persistence to store pointer references to
values in memory.
This example uses RWCollectableInt instead of int because ints use simple persistence. By using
RWCollectableInts, we can implement isomorphic persistence.
When RWTPtrDlist is saved and then restored, the pointer relationships of the restored list will have
the same morphology as the original list.
#include <assert.h>
#include <rw/tpdlist.h> // RWTPtrDlist
#include <rw/collint.h> // RWCollectableInt
#include <rw/rwfile.h> // RWFile
main (){
RWTPtrDlist<RWCollectableInt> dlist1;
RWCollectableInt *one = new RWCollectableInt(1);
dlist1.insert(one);
dlist1.insert(one);
{
RWFile f("dlist.dat");
f << dlist1; // Isomorphic persistence of dlist1.
}
assert(dlist1[0] == one && dlist1[0] == dlist1[1]);
// dlist1[0], dlist[1] and "one" all point to the
// same place.
RWTPtrDlist<RWCollectableInt> dlist2;
{
RWFile f("dlist.dat");