Microsoft DirectX 8.1 (C++) |
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 MetaProperty.Cond, or use MetaPropertyType.Cond to create a condition based on a hypothetical object. These methods return a MetaPropertyCondition object, which is then passed to the ItemsWithMetaPropertyCond property of a collection, such as Programs.ItemsWithMetaPropertyCond. This method returns a subset of the collection containing only objects that meet the condition.
The following example code retrieves a collection of programs that have a value of greater than 0 in the Sports category. Assume that g_gs is an initialized GuideStore object.
Private Function SportsPrograms as Programs
Dim allPrograms As Programs
Dim mpSets As MetaPropertySets
Dim mpType As MetaPropertyType
Dim mpCond As MetaPropertyCondition
' Get all MetaPropertySets.
Set mpSets = g_gs.MetaPropertySets
' Retrieve the standard MetaPropertyType named "Sports" from the
' MetaPropertySet named "Categories".
Set mpType = mpSets.Lookup("Categories.Sports")
' Create a MetaPropertyCondition specifying a metaproperty of type
' "Sports" that has a value of greater than 0.
Set mpCond = mpType.Cond(">", 0, 0)
' Retrieve the collection of all programs.
Set allPrograms = g_gs.Programs
' Retrieve a subset of programs that meet the condition.
Set SportsPrograms = allPrograms.ItemsWithMetaPropertyCond(mpCond)
End Function
The following example shows the same function in Visual Basic Scripting Edition, where myGuideStore is the GuideStore object.
<SCRIPT LANGUAGE = "VBScript">
<!--
Function SportsPrograms
Dim allPrograms
Dim mpSets
Dim mpType
Dim mpCond
' Get all MetaPropertySets.
Set mpSets = myGuideStore.MetaPropertySets
' Retrieve the standard MetaPropertyType named "Sports" from the
' MetaPropertySet named "Categories".
Set mpType = mpSets.Lookup("Categories.Sports")
' Create a MetaPropertyCondition specifying a metaproperty of type
' "Sports" that has a value of greater than 0.
Set mpCond = mpType.Cond(">", 0, 0)
' Retrieve the collection of all programs.
Set allPrograms = myGuideStore.Programs
' Retrieve a subset of programs that meet the condition.
Set SportsPrograms = allPrograms.ItemsWithMetaPropertyCond(mpCond)
End Function
-->
</SCRIPT>
Multiple conditions can be applied by first creating a MetaPropertyCondition object that combines the conditions of two other MetaPropertyCondition objects. Suppose you have two MetaPropertyCondition objects, MPC1 and MPC2. Create a third MetaPropertyCondition object, MPC3, by calling the MetaPropertyCondition.And or MetaPropertyCondition.Or property on MPC1, passing in MPC2 as a parameter. Then pass MPC3 to ItemsWithMetaPropertyCond. If MPC3 was created by using And, only objects that meet the condition of both MPC1 and MPC2 are retrieved in the new collection. If MPC3 was created by using Or, objects that meet the condition of either MPC1 or MPC2 are retrieved.
The following Visual Basic example code retrieves a collection of programs that have a metaproperty value greater than 0 in either the hockey or the football category.
Private Function HockeyAndFootballPrograms
Dim allPrograms As Programs
Dim mpCond As MetaPropertyCondition
Dim mpCond1 As MetaPropertyCondition
Dim mpCond2 As MetaPropertyCondition
Dim mpSets As MetaPropertySets
Dim mpType As MetaPropertyType
' Create two conditions.
Set mpSets = g_gs.MetaPropertySets
Set mpType = mpSets.Lookup("Categories.Hockey")
Set mpCond = mpType.Cond(">", 0, 0)
Set mpType = mpSets.Lookup("Categories.Football")
Set mpCond1 = mpType.Cond(">", 0, 0)
' Combine the conditions.
Set mpCond2 = mpCond.Or(mpCond1)
' Retrieve all programs.
Set allPrograms = g_gs.Programs
' Retrieve programs that match the combined condition.
Set HockeyAndFootballPrograms = _
allPrograms.ItemsWithMetaPropertyCond(mpCond2)
End Function
The following script function, shown in the context of a Web page, returns a collection of programs that have a metaproperty value greater than 0 in either the hockey or the football category, and displays the titles and descriptions of all items in the collection.
<SCRIPT LANGUAGE = "VBScript">
<!--
Function HockeyAndFootballPrograms
Dim allPrograms
Dim mpCond
Dim mpCond1
Dim mpCond2
Dim mpSets
Dim mpType
' Create two conditions.
Set mpSets = myGuideStore.MetaPropertySets
Set mpType = mpSets.Lookup("Categories.Hockey")
Set mpCond = mpType.Cond(">", 0, 0)
Set mpType = mpSets.Lookup("Categories.Football")
Set mpCond1 = mpType.Cond(">", 0, 0)
' Combine the conditions.
Set mpCond2 = mpCond.Or(mpCond1)
' Retrieve all programs.
Set allPrograms = myGuideStore.Programs
' Retrieve programs that match the combined condition.
Set HockeyAndFootballPrograms = _
allPrograms.ItemsWithMetaPropertyCond(mpCond2)
for x = 0 to HockeyAndFootballPrograms.count - 1
document.write HockeyAndFootballPrograms.Item(x).Title
document.write "<br>"
document.write HockeyAndFootballPrograms.Item(x).description
document.write "<p>"
next
End Function
-->
</SCRIPT>