Managing a heterogenous collection

Classes that mix in MPropertyStore often manage properties of different data types. For example, one MPropertyStore instance might store properties of types TTime, long, TText, Boolean, and TDoubleLong. Together, the properties managed by MPropertyStore form a heterogenous collection.

Heterogenous collections require type checking to avoid errors that can occur when retrieving a value or an instance of an incorrect type. To avoid these errors, the property classes use C++ templates for static type checking and runtime checking.

TProperty classes

Two kinds of property classes derive from TProperty:

When you instantiate one of these classes to create a property container, you pass the data type of the property as the template argument--in place of ABasicCType or AClassType.

TPrimitiveProperty<ABasicCType> can contain one of the basic C++ data types, or TDoubleLong. In place of ABasicCType, TPrimitiveProperty<ABasicCType> accepts:

signed char unsigned char TDoubleLong double
signed short unsigned short float signed long
unsigned long signed char unsigned char short
long

You can also use any type definition that corresponds to one of these values. For example, TPrimitiveProperty<Boolean> is acceptable.

TExtendedProperty<AClassType> can contain an instance of a class. For extended properties, the instance must be of a class that derives from MCollectible.

NOTE The MCollectible hierarchy will change in a future software release. Read Chapter 1, "Collections" to learn more about collections.

TPropertyID classes

TPropertyID has two concrete classes that use templates in the same way as the classes derived from TProperty. Instances TPrimitivePropertyID<ABasicCType> and TExtendedPropertyID<AClassType> provide the identifiers that correspond to instances of TPrimitiveProperty<ABasicCType> and TExtendedProperty<AClassType>.


Handling polymorphic class types

TExtendedProperty<AClassType> defines a Boolean function called AllowsPolymorphicValues.This member function flags whether or not a program can use the identifier to store and retrieve polymorphic values. The default for AllowsPolymorphicValues does not allow polymorphism.

Evaluating equality within a collection

When evaluating properties, the Properties interface considers two instances of property identifier equal if the name and polymorphism flag are both equal. If either of these components is not equal, the identifiers are not equal. If you add an identifier to a property collection that contains an equal identifier, the Properties interface replaces the original property instance with the new one.


[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