Microsoft DirectX 8.1 (C++)

Comparing Metaproperties (C++)

This topic applies to Windows XP Home Edition and Windows XP Professional only.

Metaproperty conditions are used to retrieve a subset of objects in a collection that match a specified comparison with one or more metaproperties.

Create a condition based on an existing MetaProperty object by using IMetaProperty::get_Cond, or use IMetaPropertyType::get_Cond to create a condition based on a hypothetical object. These methods return an IMetaPropertyCondition interface, which is then passed to the get_ItemsWithMetaPropertyCond method of a collection, such as IChannels::get_ItemsWithMetaPropertyCond. This method returns a subset of the collection containing only objects that meet the condition.

The following example code creates a collection of program objects which are rated suitable for people less than 18 years of age.

IGuideStore* pGuideStore;
 
// Initialization of pGuideStore is omitted.
// Error checking is omitted for simplicity.
.
.
.
IPrograms* pPrograms;
g_pGuideStore->get_Programs(&pPrograms);
 
// Retrieve the collection of all MetaPropertySet objects. 
 
IMetaPropertySets* pMetaPropertySets;
g_pGuideStore->get_MetaPropertySets(&pMetaPropertySets);
 
// Retrieve the standard MetaPropertyType.
 
IMetaPropertyType* pMetaPropertyType;
pMetaPropertySets->get_Lookup(
        _bstr_t(L"Ratings.MinimumAge"), &pMetaPropertyType);

// Create the condition.
 
VARIANT varAge;
varAge.vt = VT_I4;
varAge.lVal = 18;
 
IMetaPropertyCondition* pMetaPropertyCondition;
pMetaPropertyType->get_Cond(
        _bstr_t(L"<"), 0, varAge, &pMetaPropertyCondition);
 
// Retrieve the subset of programs that meet the condition.
 
IPrograms* pFamilyPrograms = 0;
pPrograms->get_ItemsWithMetaPropertyCond(pMetaPropertyCondition,
        &pFamilyPrograms);

Multiple conditions can be applied by first creating a MetaPropertyCondition object that combines the conditions of two other MetaPropertyCondition objects. Suppose you have pointers to two IMetaPropertyCondition interfaces, pMPC1 and pMPC2. Create a third MetaPropertyCondition object, pMPC3, by calling the IMetaPropertyCondition::get_And or IMetaPropertyCondition::get_Or method on pMPC1, passing in pMPC2 as a parameter. Then pass pMPC3 to get_ItemsWithMetaPropertyCond. If pMPC3 was created by using get_And, only objects that meet the condition of both pMPC1 and pMPC2 are retrieved in the new collection. If pMPC3 was created by using get_Or, objects that meet the condition of either pMPC1 or pMPC2 are retrieved.