Tools.h++ Manual
19-6 104011 Tandem Computers Incorporated
19
The class
Tangle
implements a (potentially) circularly linked list. What
happens? When function
operator<<()
is called for the first time for an
instance of
Tangle
, it sets up the
IdentityDictionary
, as described above,
and then calls the
Tangle
’s
saveGuts()
whose definition is shown above.
This definition stores any member data of
Tangle
, then calls
operator<<()
for the next link. This recursion continues on around the chain.
If the chain ends with a nil object (i.e.,
nextTangle
is zero), then
operator<<()
notes this internally and stops the recursion.
On the other hand, if the list is circular, then a call to
operator<<()
will
eventually be made for the first instance of
Tangle
again, the one that started
this whole chain. When this happens,
operator<<()
will recognize that it
}
}
RWDEFINE_COLLECTABLE(Tangle, 100)
main()
{
Tangle *head = 0, *head2 = 0;
for (int i=0; i<10; i++)
head = new Tangle(head,i);
checkList(head); // Check the original list
{
RWFile file("junk.dat");
file << head;
}
RWFile file2("junk.dat");
file2 >> head2;
checkList(head2); // Check the restored list
return 0;
}