Isomorphic persistence of a tools.h++ class – HP Integrity NonStop J-Series User Manual
Page 181

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
RWCollectableInt
s, 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
#include
#include
#include
main (){
RWTPtrDlist
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
{
RWFile f("dlist.dat");