HP Integrity NonStop J-Series User Manual
Page 203

// That is, test for identity, not just equality:
if (item->isA() == __RWCOLLECTABLESTRING && item==g)
georgeCount++;
// Count the strings, dates and integers:
switch (item->isA()) {
case __RWCOLLECTABLESTRING: stringCount++; break;
case __RWCOLLECTABLEINT: integerCount++; break;
case __RWCOLLECTABLEDATE: dateCount++; break;
default: unknownCount++; break;
}
}
// Output results:
cout << "There are:\n\t"
<< stringCount << " RWCollectableString(s)\n\t"
<< integerCount << " RWCollectableInt(s)\n\t"
<< dateCount << " RWCollectableDate(s)\n\t"
<< unknownCount << " other RWCollectable(s)\n\n"
<< "There are "
<< georgeCount
<< " pointers to the same object \"George\"" << endl;
// Delete all objects created and return:
collection2.clearAndDestroy();
return 0;
}
Program Output:
There are:
2 RWCollectableString(s)
1 RWCollectableInt(s)
1 RWCollectableDate(s)
0 other RWCollectable(s)
There are 2 pointers to the same object "George"
Figure 8 illustrates the collection created in the first example and restored in the second. Notice
that both the memory map and the datatypes are identical in the saved and restored collection.
Figure 8. Polymorphic Persistence