Comparators and collection elements

The protocol defined by MCollectible plays an important role for elements placed in collections. This protocol is used by the collections as well as by the comparators, streamers, and iterators associated with collections.

For this particular release of the CommonPoint application system many collection elements are instances of classes derived from MCollectible. You can put elements other than MCollectibles in collections as long as you do not require polymorphic streaming for your collection. Eventually you will be able to place any kind of object in collections. MCollectible defines the basic protocol used by comparators to determine identity and ordering relationships between collection elements.

This reliance on MCollectible to support ordering for comparators and persistence for streaming will not be necessary once full compiler support for C++'s run-time type information (RTTI) specification is fully supported by all CommonPoint C++ compilers. Be prepared to see MCollectible gradually phased out of CommonPoint frameworks. In the mean time it's important to know the basic protocol which all elements to be placed in collections must inherit to work properly with comparators and streamers.

To keep this discussion as simple as possible only two different types of MCollectible objects are used in example programs: instances of TCollectibleLong, and TStandardText. Only the restricted protocols shown in Figure 1 for TCollectibleLong and TStandardText are used to retrieve and print values associated with these two subclasses of MCollectible.


Figure 1 shows a more complete protocol for MCollectible that should give you a sense of how MCollectible objects are able to compare themselves against one another to determine equality and ordering relations. Comparators used in collections call this virtual function whenever it is necessary to determine the relationship between two collection elements.

Figure 1 shows the full set of MCollectible protocols that enable the use of various operators when comparing collection elements for equality and when ordering collection elements.



[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker