CFComparatorFunction

Header: CFBase.h Carbon status: Supported

The prototype for a user-defined function that compares two values. You provide a pointer to this function in certain Core Foundation sorting functions.

typedef CFComparisonResult(* CFComparatorFunction) (
    const void *val1, 
    const void *val2, 
    void *context
);

You would declare your function like this if you were to name it MyCallback:

CFComparisonResult MyCallback (
    const void *val1, 
    const void *val2, 
    void *context
);
Parameter descriptions
val1

Pass a pointer to the first value to be compared.

val2

Pass a pointer to the second value to be compared.

context

An untyped pointer to the context of the evaluation. This is often used for user-defined data in the comparison.

function result

An integer value of type CFComparisonResult that indicates whether the first value is equal to, less than, or greater than the second value.

DISCUSSION

If you need to sort the elements in a collection using special criteria, you can implement a comparator function with the signature defined by the CFComparatorFunction prototype. You pass a pointer to this function in one of the "sort" functions, such as CFArray's CFArraySortValues.

You can also pass pointers to standard Core Foundation comparator functions such as CFStringCompare and CFDateCompare.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)