Derived from | |
Framework | CoreFoundation/CoreFoundation.h |
Companion guide | |
Declared in | CFNumber.h |
CFNumber encapsulates C scalar (numeric) types. It provides functions for setting and accessing the value as any basic C type. It also provides a compare function to determine the ordering of two CFNumber objects. CFNumber objects are used to wrap numerical values for use in Core Foundation property lists and collections.
CFNumber objects are not intended as a replacement for C scalar values and should not be used in APIs or implementations where scalar values are more appropriate and efficient.
Note: In order to improve performance, some commonly-used numbers (such as 0
and 1
) are uniqued. You should not expect that allocating multiple CFNumber instances will necessarily result in distinct objects.
CFNumber is “toll-free bridged” with its Cocoa Foundation counterpart, NSNumber. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSNumber *
parameter, you can pass in a CFNumberRef
, and in a function where you see a CFNumberRef
parameter, you can pass in an NSNumber instance. This fact also applies to concrete subclasses of NSNumber. See Integrating Carbon and Cocoa in Your Application for more information on toll-free bridging.
Compares two CFNumber objects and returns a comparison result.
CFComparisonResult CFNumberCompare ( CFNumberRef number, CFNumberRef otherNumber, void *context );
The first CFNumber object to compare.
The second CFNumber object to compare.
Pass NULL
.
A CFComparisonResult
constant that indicates whether number is equal to, less than, or greater than otherNumber.
When comparing two CFNumber objects using this function, one or both objects can represent a special-case number such as signed 0, signed infinity, or NaN.
The following rules apply:
Negative 0 compares less than positive 0.
Positive infinity compares greater than everything except itself, to which it compares equal.
Negative infinity compares less than everything except itself, to which it compares equal.
If both numbers are NaN, then they compare equal.
If only one of the numbers is NaN, then the NaN compares greater than the other number if it is negative, and smaller than the other number if it is positive.
CFNumber.h
Creates a CFNumber object using a specified value.
CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr );
The allocator to use to allocate memory for the new object. Pass NULL
or kCFAllocatorDefault
to use the default allocator.
A constant that specifies the data type of the value to convert. See Number Types for a list of possible values.
A pointer to the value for the returned number object.
A new number with the value specified by valuePtr. Ownership follows the Create Rule.
The theType parameter is not necessarily preserved when creating a new CFNumber object. The CFNumber object will be created using whatever internal storage type the creation function deems appropriate. Use the function CFNumberGetType
to find out what type the CFNumber object used to store your value.
CFNumber.h
Returns the number of bytes used by a CFNumber object to store its value.
CFIndex CFNumberGetByteSize ( CFNumberRef number );
The CFNumber object to examine.
The size in bytes of the value contained in number.
Because a CFNumber object might store a value using a type different from that of the original value with which it was created, this function may return a size different from the size of the original value's type.
CFNumber.h
Returns the type used by a CFNumber object to store its value.
CFNumberType CFNumberGetType ( CFNumberRef number );
The CFNumber object to examine.
A constant that indicates the data type of the value contained in number. See Number Types for a list of possible values.
The type specified in the call to CFNumberCreate
is not necessarily preserved when a new CFNumber object is created—it uses whatever internal storage type the creation function deems appropriate.
CFNumber.h
Returns the type identifier for the CFNumber opaque type.
CFTypeID CFNumberGetTypeID ( void );
The type identifier for the CFNumber opaque type.
CFNumber.h
Obtains the value of a CFNumber object cast to a specified type.
Boolean CFNumberGetValue ( CFNumberRef number, CFNumberType theType, void *valuePtr );
The CFNumber object to examine.
A constant that specifies the data type to return. See Number Types for a list of possible values.
On return, contains the value of number.
true
if the operation was successful, otherwise false
.
If the argument type differs from the return type, and the conversion is lossy or the return value is out of range, then this function passes back an approximate value in valuePtr and returns false
.
CFNumber.h
Determines whether a CFNumber object contains a value stored as one of the defined floating point types.
Boolean CFNumberIsFloatType ( CFNumberRef number );
The CFNumber object to examine.
true
if number's value is one of the defined floating point types, otherwise false
. The valid floating point types are listed in Number Types.
CFNumber.h
A reference to a CFNumber object.
typedef const struct __CFNumber *CFNumberRef;
CFNumber.h
Flags used by CFNumber to indicate the data type of a value.
enum CFNumberType { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 }; typedef enum CFNumberType CFNumberType;
kCFNumberSInt8Type
Eight-bit, signed integer. The SInt8
data type is defined in MacTypes.h
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberSInt16Type
Sixteen-bit, signed integer. The SInt16
data type is defined in MacTypes.h
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberSInt32Type
Thirty-two-bit, signed integer. The SInt32
data type is defined in MacTypes.h
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberSInt64Type
Sixty-four-bit, signed integer. The SInt64
data type is defined in MacTypes.h
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberFloat32Type
Thirty-two-bit real. The Float32
data type is defined in MacTypes.h
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberFloat64Type
Sixty-four-bit real. The Float64
data type is defined in MacTypes.h
and conforms to the 64-bit IEEE 754 standard.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberCharType
Basic C char
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberShortType
Basic C short
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberIntType
Basic C int
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberLongType
Basic C long
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberLongLongType
Basic C long long
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberFloatType
Basic C float
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberDoubleType
Basic C double
type.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberCFIndexType
CFIndex value.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberNSIntegerType
NSInteger
value.
Available in Mac OS X v10.5 and later.
Declared in CFNumber.h
.
kCFNumberCGFloatType
CGFloat
value.
Available in Mac OS X v10.5 and later.
Declared in CFNumber.h
.
kCFNumberMaxType
Same as kCFNumberCGFloatType
.
Note that on Mac OS X v10.4, kCFNumberMaxType
was the same as kCFNumberCFIndexType
.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
The type specified in the call to CFNumberCreate
is not necessarily preserved when creating a new CFNumber object. A CFNumber object uses whatever internal storage type the creation function deems appropriate. Use the CFNumberGetType
function to find out what type the CFNumber object used to store your value.
CFNumber provides some predefined number values.
const CFNumberRef kCFNumberNaN; const CFNumberRef kCFNumberNegativeInfinity; const CFNumberRef kCFNumberPositiveInfinity;
kCFNumberNaN
“Not a Number.” This value is often the result of an invalid operation, such as the square-root of a negative number.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberNegativeInfinity
Designates a negative infinity value.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
kCFNumberPositiveInfinity
Designates a positive infinity value.
Available in Mac OS X v10.0 and later.
Declared in CFNumber.h
.
© 2003, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-12-01)