]> git.saurik.com Git - apple/cf.git/blob - CFNumber.h
CF-476.10.tar.gz
[apple/cf.git] / CFNumber.h
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* CFNumber.h
24 Copyright (c) 1999-2007, Apple Inc. All rights reserved.
25 */
26
27 #if !defined(__COREFOUNDATION_CFNUMBER__)
28 #define __COREFOUNDATION_CFNUMBER__ 1
29
30 #include <CoreFoundation/CFBase.h>
31
32 CF_EXTERN_C_BEGIN
33
34 typedef const struct __CFBoolean * CFBooleanRef;
35
36 CF_EXPORT
37 const CFBooleanRef kCFBooleanTrue;
38 CF_EXPORT
39 const CFBooleanRef kCFBooleanFalse;
40
41 CF_EXPORT
42 CFTypeID CFBooleanGetTypeID(void);
43
44 CF_EXPORT
45 Boolean CFBooleanGetValue(CFBooleanRef boolean);
46
47 enum {
48 /* Fixed-width types */
49 kCFNumberSInt8Type = 1,
50 kCFNumberSInt16Type = 2,
51 kCFNumberSInt32Type = 3,
52 kCFNumberSInt64Type = 4,
53 kCFNumberFloat32Type = 5,
54 kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */
55 /* Basic C types */
56 kCFNumberCharType = 7,
57 kCFNumberShortType = 8,
58 kCFNumberIntType = 9,
59 kCFNumberLongType = 10,
60 kCFNumberLongLongType = 11,
61 kCFNumberFloatType = 12,
62 kCFNumberDoubleType = 13,
63 /* Other */
64 kCFNumberCFIndexType = 14,
65 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
66 kCFNumberNSIntegerType = 15,
67 kCFNumberCGFloatType = 16,
68 kCFNumberMaxType = 16
69 #else
70 kCFNumberMaxType = 14
71 #endif
72 };
73 typedef CFIndex CFNumberType;
74
75 typedef const struct __CFNumber * CFNumberRef;
76
77 CF_EXPORT
78 const CFNumberRef kCFNumberPositiveInfinity;
79 CF_EXPORT
80 const CFNumberRef kCFNumberNegativeInfinity;
81 CF_EXPORT
82 const CFNumberRef kCFNumberNaN;
83
84 CF_EXPORT
85 CFTypeID CFNumberGetTypeID(void);
86
87 /*
88 Creates a CFNumber with the given value. The type of number pointed
89 to by the valuePtr is specified by type. If type is a floating point
90 type and the value represents one of the infinities or NaN, the
91 well-defined CFNumber for that value is returned. If either of
92 valuePtr or type is an invalid value, the result is undefined.
93 */
94 CF_EXPORT
95 CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
96
97 /*
98 Returns the storage format of the CFNumber's value. Note that
99 this is not necessarily the type provided in CFNumberCreate().
100 */
101 CF_EXPORT
102 CFNumberType CFNumberGetType(CFNumberRef number);
103
104 /*
105 Returns the size in bytes of the type of the number.
106 */
107 CF_EXPORT
108 CFIndex CFNumberGetByteSize(CFNumberRef number);
109
110 /*
111 Returns true if the type of the CFNumber's value is one of
112 the defined floating point types.
113 */
114 CF_EXPORT
115 Boolean CFNumberIsFloatType(CFNumberRef number);
116
117 /*
118 Copies the CFNumber's value into the space pointed to by
119 valuePtr, as the specified type. If conversion needs to take
120 place, the conversion rules follow human expectation and not
121 C's promotion and truncation rules. If the conversion is
122 lossy, or the value is out of range, false is returned. Best
123 attempt at conversion will still be in *valuePtr.
124 */
125 CF_EXPORT
126 Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
127
128 /*
129 Compares the two CFNumber instances. If conversion of the
130 types of the values is needed, the conversion and comparison
131 follow human expectations and not C's promotion and comparison
132 rules. Negative zero compares less than positive zero.
133 Positive infinity compares greater than everything except
134 itself, to which it compares equal. Negative infinity compares
135 less than everything except itself, to which it compares equal.
136 Unlike standard practice, if both numbers are NaN, then they
137 compare equal; if only one of the numbers is NaN, then the NaN
138 compares greater than the other number if it is negative, and
139 smaller than the other number if it is positive. (Note that in
140 CFEqual() with two CFNumbers, if either or both of the numbers
141 is NaN, true is returned.)
142 */
143 CF_EXPORT
144 CFComparisonResult CFNumberCompare(CFNumberRef number, CFNumberRef otherNumber, void *context);
145
146 CF_EXTERN_C_END
147
148 #endif /* ! __COREFOUNDATION_CFNUMBER__ */
149