beautypg.com

HP Integrity NonStop J-Series User Manual

Page 202

background image

#define RW_STD_TYPEDEFS
#include
#include
#include
#include
#include
main(){
RWpistream istr(cin);
RWOrdered collection2;
// Even though this program does not need to have prior
// knowledge of exactly what it is restoring, the linker
// needs to know what the possibilities are so that the
// necessary code is linked in for use by RWFactory.
// RWFactory creates RWCollectable objects based on
// class ID's.
RWCollectableInt exemplarInt;
RWCollectableDate exemplarDate;
// Read the collection back in:
istr >> collection2;
// Note: The above statement is the code that restores
// the collection. The rest of this example shows us
// what is in the collection.
// Create a temporary string with value "George"
// in order to search for a string with the same value:
RWCollectableString temp("George");
// Find a "George":
// collection2 is searched for an occurrence of a
// string with value "George".
// The pointer "g" will point to such a string:
RWCollectableString* g;
g = (RWCollectableString*)collection2.find(&temp);
// "g" now points to a string with the value "George"
// How many occurrences of g are there in the collection?
size_t georgeCount = 0;
size_t stringCount = 0;
size_t integerCount = 0;
size_t dateCount = 0;
size_t unknownCount = 0;
// Create an iterator:
RWOrderedIterator sci(collection2);
RWCollectable* item;
// Iterate through the collection, item by item,
// returning a pointer for each item:
while ( item = sci() ) {
// Test whether this pointer equals g.

This manual is related to the following products: