Core Foundation's Base Services include several polymorphic functions. These functions can take any Core Foundation object as a parameter and (in one instance,
CFRetain
) can return any Core Foundation object. These parameters and return values are given the type of
CFTypeRef
, a generic object-reference type. (See Type IDs and Generic Object References for more on this type.)
You use polymorphic functions for operations that are common to all Core Foundation types:
The
CFEqual
function compares any two Core Foundation objects (see Comparing Objects). The basis of equality depends on the type of objects compared. For example, if both are CFString objects the test involves a character-by-character comparison.
The
CFHash
function returns a unique hash code identifying a Core Foundation object (see Comparing Objects). You can use the hash code as a table address in a hash table structure. If two objects are equal (as determined by the
CFEqual
function), they must have the same hash value.
Base Services gives you the means to inspect objects and thereby learn about their contents and the type to which they "belong." The
CFCopyDescription
function returns a string (more precisely, a reference to a CFString object) that describes an object. The
CFCopyTypeIDDescription
function, which takes a
CFTypeID
rather than a
CFTypeRef
parameter, returns a string reference that describes the opaque type identified by the type ID. These functions are primarily intended to assist debugging; see Inspecting Objects for more on these functions.
You can also determine the opaque type to which an generically typed object belongs by getting its type ID with the
CFGetTypeID
function and then comparing that value with known type IDs. See Inspecting Objects for more on this task.
Base Services provides several polymorphic functions for manipulating and obtaining the retention count of objects. See Reference Counting for more about these functions.