|
| 1 | +/** |
| 2 | + CoreFoundation Numbers |
| 3 | +
|
| 4 | + Copyright: Copyright © 2024-2025, Kitsunebi Games EMV |
| 5 | + License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 6 | + Authors: Luna Nielsen |
| 7 | +*/ |
| 8 | +module corefoundation.cfnumber; |
| 9 | +import corefoundation.cfallocator; |
| 10 | +import corefoundation.core; |
| 11 | +import foundation.nsvalue; |
| 12 | + |
| 13 | +extern(C) @nogc nothrow: |
| 14 | + |
| 15 | +/** |
| 16 | + CoreFoundation boxed boolean |
| 17 | +*/ |
| 18 | +alias CFBooleanRef = CFSubType!("CFBoolean", NSNumber); |
| 19 | + |
| 20 | +/** |
| 21 | + CoreFoundation wrapped "true" value. |
| 22 | +*/ |
| 23 | +extern __gshared CFBooleanRef kCFBooleanTrue; |
| 24 | + |
| 25 | +/** |
| 26 | + CoreFoundation wrapped "false" value. |
| 27 | +*/ |
| 28 | +extern __gshared CFBooleanRef kCFBooleanFalse; |
| 29 | + |
| 30 | +/** |
| 31 | + Gets the type identifier for CFBoolean |
| 32 | +
|
| 33 | + Returns: |
| 34 | + The Type ID of CFBoolean |
| 35 | +*/ |
| 36 | +extern CFTypeID CFBooleanGetTypeID(); |
| 37 | + |
| 38 | +/** |
| 39 | + Gets the boolean value stored in a CFBoolean |
| 40 | +
|
| 41 | + Returns: |
| 42 | + The contents of the CFBoolean |
| 43 | +*/ |
| 44 | +extern bool CFBooleanGetValue(CFBooleanRef boolean); |
| 45 | + |
| 46 | +/** |
| 47 | + Subtypes for CFNumber |
| 48 | +*/ |
| 49 | +alias CFNumberType = CFIndex; |
| 50 | +enum : CFNumberType { |
| 51 | + |
| 52 | + /* Fixed-width types */ |
| 53 | + kCFNumberSInt8Type = 1, |
| 54 | + kCFNumberSInt16Type = 2, |
| 55 | + kCFNumberSInt32Type = 3, |
| 56 | + kCFNumberSInt64Type = 4, |
| 57 | + kCFNumberFloat32Type = 5, |
| 58 | + kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */ |
| 59 | + |
| 60 | + /* Basic C types */ |
| 61 | + kCFNumberCharType = 7, |
| 62 | + kCFNumberShortType = 8, |
| 63 | + kCFNumberIntType = 9, |
| 64 | + kCFNumberLongType = 10, |
| 65 | + kCFNumberLongLongType = 11, |
| 66 | + kCFNumberFloatType = 12, |
| 67 | + kCFNumberDoubleType = 13, |
| 68 | + |
| 69 | + /* Other */ |
| 70 | + kCFNumberCFIndexType = 14, |
| 71 | + kCFNumberNSIntegerType = 15, |
| 72 | + kCFNumberCGFloatType = 16, |
| 73 | + kCFNumberMaxType = 16 |
| 74 | +} |
| 75 | + |
| 76 | +/** |
| 77 | + CoreFoundation boxed numbers |
| 78 | +*/ |
| 79 | +alias CFNumberRef = CFSubType!("CFNumber", NSNumber); |
| 80 | + |
| 81 | +/** |
| 82 | + CoreFoundation wrapped +infinity value. |
| 83 | +*/ |
| 84 | +extern __gshared CFNumberRef kCFNumberPositiveInfinity; |
| 85 | + |
| 86 | +/** |
| 87 | + CoreFoundation wrapped -infinity value. |
| 88 | +*/ |
| 89 | +extern __gshared CFNumberRef kCFNumberNegativeInfinity; |
| 90 | + |
| 91 | +/** |
| 92 | + CoreFoundation wrapped NaN value. |
| 93 | +*/ |
| 94 | +extern __gshared CFNumberRef kCFNumberNaN; |
| 95 | + |
| 96 | +/** |
| 97 | + Gets the type identifier for CFNumber |
| 98 | +
|
| 99 | + Returns: |
| 100 | + The Type ID of CFNumber |
| 101 | +*/ |
| 102 | +extern CFTypeID CFNumberGetTypeID(); |
| 103 | + |
| 104 | +/** |
| 105 | + Creates a CFNumber with the given value. The type of number pointed |
| 106 | + to by the valuePtr is specified by type. |
| 107 | +
|
| 108 | + Params: |
| 109 | + allocator = The allocator to use or $(D null) to use the default. |
| 110 | + theType = The number subtype of the given value. |
| 111 | + valuePtr = Pointer to the value to copy into the CFNumber |
| 112 | + |
| 113 | + Returns: |
| 114 | + If type is a floating point type and the value represents one |
| 115 | + of the infinities or NaN, the well-defined CFNumber for that |
| 116 | + value is returned. If either of valuePtr or type is an invalid |
| 117 | + value, the result is undefined. |
| 118 | +*/ |
| 119 | +extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const(void)* valuePtr); |
| 120 | + |
| 121 | +/** |
| 122 | + Gets the underlying type of the CFNumber. |
| 123 | + |
| 124 | + Params: |
| 125 | + number = The CFNumber |
| 126 | + |
| 127 | + Returns: |
| 128 | + The subtype of the CFNumber. |
| 129 | +*/ |
| 130 | +extern CFNumberType CFNumberGetType(CFNumberRef number); |
| 131 | + |
| 132 | +/** |
| 133 | + Gets the size of the number value stored, in bytes. |
| 134 | + |
| 135 | + Params: |
| 136 | + number = The CFNumber |
| 137 | + |
| 138 | + Returns: |
| 139 | + The size of the number value stored, in bytes. |
| 140 | +*/ |
| 141 | +extern CFIndex CFNumberGetByteSize(CFNumberRef number); |
| 142 | + |
| 143 | +/** |
| 144 | + Gets whether the CFNumber contains a floating point number. |
| 145 | +
|
| 146 | + Params: |
| 147 | + number = The CFNumber |
| 148 | + |
| 149 | + Returns: |
| 150 | + $(D true) if the CFNumber contains float data, |
| 151 | + $(D false) otherwise. |
| 152 | +*/ |
| 153 | +extern bool CFNumberIsFloatType(CFNumberRef number); |
| 154 | + |
| 155 | +/** |
| 156 | + Gets the value of the CFNumber, converting if needed. |
| 157 | +
|
| 158 | + Params: |
| 159 | + number = The CFNumber |
| 160 | + theType = The type of value to get, converting if neccesary. |
| 161 | + valuePtr = Where to store the data. |
| 162 | + |
| 163 | + Returns: |
| 164 | + $(D true) if the operation succeeded |
| 165 | + without any loss of accuracy, $(D false) otherwise. |
| 166 | +*/ |
| 167 | +extern bool CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr); |
| 168 | + |
| 169 | +/** |
| 170 | + Compares the two CFNumber instances. |
| 171 | + |
| 172 | + If conversion of the types of the values is needed, |
| 173 | + the conversion and comparison follow human expectations |
| 174 | + and not C's promotion and comparison rules. |
| 175 | + Negative zero compares less than positive zero. |
| 176 | + Positive infinity compares greater than everything except |
| 177 | + itself, to which it compares equal. Negative infinity compares |
| 178 | + less than everything except itself, to which it compares equal. |
| 179 | + Unlike standard practice, if both numbers are NaN, then they |
| 180 | + compare equal; if only one of the numbers is NaN, then the NaN |
| 181 | + compares greater than the other number if it is negative, and |
| 182 | + smaller than the other number if it is positive. (Note that in |
| 183 | + CFEqual() with two CFNumbers, if either or both of the numbers |
| 184 | + is NaN, true is returned.) |
| 185 | +
|
| 186 | + Params: |
| 187 | + number = The first number |
| 188 | + otherNumber = The second number |
| 189 | + context = The comparison context. |
| 190 | +
|
| 191 | + Returns: |
| 192 | + The result of the comparison. |
| 193 | +*/ |
| 194 | +extern CFComparisonResult CFNumberCompare(CFNumberRef number, CFNumberRef otherNumber, void *context); |
0 commit comments