The following example defines a universal printer class that accepts an arbitrary collection of jobs and prints their IDs. The elements are printed in the iteration order that is defined for the given collection. The key set running can be used as argument to the universal printer.
class JobPrinter { public: print (IACollection <Job*> const& jobs) { cout << "ID ..." ICursor *cursor = jobs.newCursor (); cout << "{ "; forICursor (*cursor) { cout << jobs.elementAt (*cursor)->id() &l2. ' '; } cout << "}\n"; delete cursor; } }; // ... typedef IKeySet <Job*, JobId> JobSet; JobSet running; // ... JobPrinter jobPrinter; jobPrinter.print(running);
Introduction
to the Collection Classes
Collection
Class Hierarchy
Overall
Implementation Structure
Collection
Class Polymorphism
Flat
Collections
Trees
Copying and Referencing
Collections
Adding and
Overloading Member Functions
Instantiating the
Collection Classes