Defining property queries

When you iterate over a collection of property stores, you can use a property query to filter for the values in which you are interested.

For example, when iterating through files and directories, you can use a property query to specify that you only want to retrieve file entities with a modification date within a specific range. You first specify the query, then pass the query to the iterator when you instantiate it.

This example uses kModificationDate and kTaligentStartDate. kModification date is a TExtendedPropertyID<TTime> instance and kTaligentStartDate is a TTime instance.

      TPropertyQuery qRecent = 
          TFileSystemEntity::kModificationDate >= kTaligentStartDate;
      TDirectoryIterator iterator(aDirectory, qRecent);
As you can see from this example, you create query instances by comparing an identifier to a value. The interface evaluates the query at a later point in time.

While this may seem counter-intuitive, it simplifies the mechanics of constructing queries. Comparison operators for property identifiers return TPropertyQuery instances, rather than the Boolean values that most comparison operators return. Using comparison operators rather than function calls allows for natural syntax when constructing queries.

This example instructs the system to fetch the modification date property for each file or directory to which this query applies, and compare this property to the supplied date. If the modification date is greater than or equal to the supplied date, the query evaluates to True and the iterator returns the file or directory. Otherwise, it evaluates to false.

You can combine multiple query expressions using logical operators to form a new query.

    TPropertyQuery qRecentApplications = qRecent && kFileKind == "Applications";
You can create queries that are arbitrarily complex and use parentheses to control precedence:

      TPropertyQuery qRecentTaligentOrClarisApps =
      qRecentApplications && (kSource == "Taligent" || kSource == "Claris");
If you do not use parentheses, the precedence rules for logical operators apply. If you removed the parentheses from the previous example, the && operator takes precedence over the || operator.


[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