]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2011 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 | ||
24 | /* CFNumber.h | |
25 | Copyright (c) 1999-2011, Apple Inc. All rights reserved. | |
26 | */ | |
27 | ||
28 | #if !defined(__COREFOUNDATION_CFNUMBER__) | |
29 | #define __COREFOUNDATION_CFNUMBER__ 1 | |
30 | ||
31 | #include <CoreFoundation/CFBase.h> | |
32 | ||
33 | CF_EXTERN_C_BEGIN | |
34 | ||
35 | typedef const struct __CFBoolean * CFBooleanRef; | |
36 | ||
37 | CF_EXPORT | |
38 | const CFBooleanRef kCFBooleanTrue; | |
39 | CF_EXPORT | |
40 | const CFBooleanRef kCFBooleanFalse; | |
41 | ||
42 | CF_EXPORT | |
43 | CFTypeID CFBooleanGetTypeID(void); | |
44 | ||
45 | CF_EXPORT | |
46 | Boolean CFBooleanGetValue(CFBooleanRef boolean); | |
47 | ||
48 | enum { | |
49 | /* Fixed-width types */ | |
50 | kCFNumberSInt8Type = 1, | |
51 | kCFNumberSInt16Type = 2, | |
52 | kCFNumberSInt32Type = 3, | |
53 | kCFNumberSInt64Type = 4, | |
54 | kCFNumberFloat32Type = 5, | |
55 | kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */ | |
56 | /* Basic C types */ | |
57 | kCFNumberCharType = 7, | |
58 | kCFNumberShortType = 8, | |
59 | kCFNumberIntType = 9, | |
60 | kCFNumberLongType = 10, | |
61 | kCFNumberLongLongType = 11, | |
62 | kCFNumberFloatType = 12, | |
63 | kCFNumberDoubleType = 13, | |
64 | /* Other */ | |
65 | kCFNumberCFIndexType = 14, | |
66 | #if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED | |
67 | kCFNumberNSIntegerType = 15, | |
68 | kCFNumberCGFloatType = 16, | |
69 | kCFNumberMaxType = 16 | |
70 | #else | |
71 | kCFNumberMaxType = 14 | |
72 | #endif | |
73 | }; | |
74 | typedef CFIndex CFNumberType; | |
75 | ||
76 | typedef const struct __CFNumber * CFNumberRef; | |
77 | ||
78 | CF_EXPORT | |
79 | const CFNumberRef kCFNumberPositiveInfinity; | |
80 | CF_EXPORT | |
81 | const CFNumberRef kCFNumberNegativeInfinity; | |
82 | CF_EXPORT | |
83 | const CFNumberRef kCFNumberNaN; | |
84 | ||
85 | CF_EXPORT | |
86 | CFTypeID CFNumberGetTypeID(void); | |
87 | ||
88 | /* | |
89 | Creates a CFNumber with the given value. The type of number pointed | |
90 | to by the valuePtr is specified by type. If type is a floating point | |
91 | type and the value represents one of the infinities or NaN, the | |
92 | well-defined CFNumber for that value is returned. If either of | |
93 | valuePtr or type is an invalid value, the result is undefined. | |
94 | */ | |
95 | CF_EXPORT | |
96 | CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); | |
97 | ||
98 | /* | |
99 | Returns the storage format of the CFNumber's value. Note that | |
100 | this is not necessarily the type provided in CFNumberCreate(). | |
101 | */ | |
102 | CF_EXPORT | |
103 | CFNumberType CFNumberGetType(CFNumberRef number); | |
104 | ||
105 | /* | |
106 | Returns the size in bytes of the type of the number. | |
107 | */ | |
108 | CF_EXPORT | |
109 | CFIndex CFNumberGetByteSize(CFNumberRef number); | |
110 | ||
111 | /* | |
112 | Returns true if the type of the CFNumber's value is one of | |
113 | the defined floating point types. | |
114 | */ | |
115 | CF_EXPORT | |
116 | Boolean CFNumberIsFloatType(CFNumberRef number); | |
117 | ||
118 | /* | |
119 | Copies the CFNumber's value into the space pointed to by | |
120 | valuePtr, as the specified type. If conversion needs to take | |
121 | place, the conversion rules follow human expectation and not | |
122 | C's promotion and truncation rules. If the conversion is | |
123 | lossy, or the value is out of range, false is returned. Best | |
124 | attempt at conversion will still be in *valuePtr. | |
125 | */ | |
126 | CF_EXPORT | |
127 | Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr); | |
128 | ||
129 | /* | |
130 | Compares the two CFNumber instances. If conversion of the | |
131 | types of the values is needed, the conversion and comparison | |
132 | follow human expectations and not C's promotion and comparison | |
133 | rules. Negative zero compares less than positive zero. | |
134 | Positive infinity compares greater than everything except | |
135 | itself, to which it compares equal. Negative infinity compares | |
136 | less than everything except itself, to which it compares equal. | |
137 | Unlike standard practice, if both numbers are NaN, then they | |
138 | compare equal; if only one of the numbers is NaN, then the NaN | |
139 | compares greater than the other number if it is negative, and | |
140 | smaller than the other number if it is positive. (Note that in | |
141 | CFEqual() with two CFNumbers, if either or both of the numbers | |
142 | is NaN, true is returned.) | |
143 | */ | |
144 | CF_EXPORT | |
145 | CFComparisonResult CFNumberCompare(CFNumberRef number, CFNumberRef otherNumber, void *context); | |
146 | ||
147 | CF_EXTERN_C_END | |
148 | ||
149 | #endif /* ! __COREFOUNDATION_CFNUMBER__ */ | |
150 |