ObjFW  Check-in [03be48c518]

Overview
Comment:Nicer API for OFNumber.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 03be48c518e0ee672a01e275ca628bb4558565bb8aa00b93d6082016d79a7884
User & Date: js on 2010-04-23 12:34:47
Other Links: manifest | tags
Context
2010-04-23
12:50
Improve link, symlink and rename operations in OFFile. check-in: 34991b40af user: js tags: trunk
12:34
Nicer API for OFNumber. check-in: 03be48c518 user: js tags: trunk
2010-04-22
09:05
Add OF_PATH_DELIM to macros.h. check-in: d931239e25 user: js tags: trunk
Changes

Modified src/OFNumber.h from [c86cd5538d] to [bdf451cad0].

100
101
102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119

120
121
122
123
124
125

126
127
128
129
130
131
132
100
101
102
103
104
105
106

107
108
109
110
111
112

113
114
115
116
117
118

119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+





-
+





-
+





-
+







 */
+ numberWithLong: (long)long_;

/**
 * \param uchar An unsigned char which the OFNumber should contain
 * \return A new autoreleased OFNumber
 */
+ numberWithUChar: (unsigned char)uchar;
+ numberWithUnsignedChar: (unsigned char)uchar;

/**
 * \param ushort An unsigned short which the OFNumber should contain
 * \return A new autoreleased OFNumber
 */
+ numberWithUShort: (unsigned short)ushort;
+ numberWithUnsignedShort: (unsigned short)ushort;

/**
 * \param uint An unsigned int which the OFNumber should contain
 * \return A new autoreleased OFNumber
 */
+ numberWithUInt: (unsigned int)uint;
+ numberWithUnsignedInt: (unsigned int)uint;

/**
 * \param ulong An unsigned long which the OFNumber should contain
 * \return A new autoreleased OFNumber
 */
+ numberWithULong: (unsigned long)ulong;
+ numberWithUnsignedLong: (unsigned long)ulong;

/**
 * \param int8 An int8_t which the OFNumber should contain
 * \return A new autoreleased OFNumber
 */
+ numberWithInt8: (int8_t)int8;

260
261
262
263
264
265
266
267

268
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283

284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
260
261
262
263
264
265
266

267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
298







-
+







-
+







-
+







-
+








/**
 * Initializes an already allocated OFNumber with the specified unsigned char.
 *
 * \param uchar An unsigned char which the OFNumber should contain
 * \return An initialized OFNumber
 */
- initWithUChar: (unsigned char)uchar;
- initWithUnsignedChar: (unsigned char)uchar;

/**
 * Initializes an already allocated OFNumber with the specified unsigned short.
 *
 * \param ushort An unsigned short which the OFNumber should contain
 * \return An initialized OFNumber
 */
- initWithUShort: (unsigned short)ushort;
- initWithUnsignedShort: (unsigned short)ushort;

/**
 * Initializes an already allocated OFNumber with the specified unsigned int .
 *
 * \param uint An unsigned int which the OFNumber should contain
 * \return An initialized OFNumber
 */
- initWithUInt: (unsigned int)uint;
- initWithUnsignedInt: (unsigned int)uint;

/**
 * Initializes an already allocated OFNumber with the specified unsigned long.
 *
 * \param ulong An unsigned long which the OFNumber should contain
 * \return An initialized OFNumber
 */
- initWithULong: (unsigned long)ulong;
- initWithUnsignedLong: (unsigned long)ulong;

/**
 * Initializes an already allocated OFNumber with the specified int8_t.
 *
 * \param int8 An int8_t which the OFNumber should contain
 * \return An initialized OFNumber
 */
431
432
433
434
435
436
437
438

439
440
441
442
443

444
445
446
447
448

449
450
451
452
453

454
455
456
457
458

459
460
461
462
463

464
465
466
467
468

469
470
471
472
473

474
475
476
477
478

479
480
481
482
483

484
485
486
487
488

489
490
491
492
493

494
495
496
497
498

499
500
501
502
503

504
505
506
507
508

509
510
511
512
513

514
515
516
517
518

519
520
521
522
523

524
525
526
527
528

529
530
531
532
533

534
535
536
537
538

539
540
541
542
543

544
545
546
547
548

549
550
551
552
553

554
555
556
557
558

559
560
561
562
563
564
565
431
432
433
434
435
436
437

438
439
440
441
442

443
444
445
446
447

448
449
450
451
452

453
454
455
456
457

458
459
460
461
462

463
464
465
466
467

468
469
470
471
472

473
474
475
476
477

478
479
480
481
482

483
484
485
486
487

488
489
490
491
492

493
494
495
496
497

498
499
500
501
502

503
504
505
506
507

508
509
510
511
512

513
514
515
516
517

518
519
520
521
522

523
524
525
526
527

528
529
530
531
532

533
534
535
536
537

538
539
540
541
542

543
544
545
546
547

548
549
550
551
552

553
554
555
556
557

558
559
560
561
562
563
564
565







-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+







 *	   number of the OFNumber
 */
- (enum of_number_type)type;

/**
 * \return The OFNumber as a char
 */
- (char)asChar;
- (char)charValue;

/**
 * \return The OFNumber as a short
 */
- (short)asShort;
- (short)shortValue;

/**
 * \return The OFNumber as an int
 */
- (int)asInt;
- (int)intValue;

/**
 * \return The OFNumber as a long
 */
- (long)asLong;
- (long)longValue;

/**
 * \return The OFNumber as an unsigned char
 */
- (unsigned char)asUChar;
- (unsigned char)unsignedCharValue;

/**
 * \return The OFNumber as an unsigned short
 */
- (unsigned short)asUShort;
- (unsigned short)unsignedShortValue;

/**
 * \return The OFNumber as an unsigned int
 */
- (unsigned int)asUInt;
- (unsigned int)unsignedIntValue;

/**
 * \return The OFNumber as an unsigned long
 */
- (unsigned long)asULong;
- (unsigned long)unsignedLongValue;

/**
 * \return The OFNumber as an int8_t
 */
- (int8_t)asInt8;
- (int8_t)int8Value;

/**
 * \return The OFNumber as an int16_t
 */
- (int16_t)asInt16;
- (int16_t)int16Value;

/**
 * \return The OFNumber as an int32_t
 */
- (int32_t)asInt32;
- (int32_t)int32Value;

/**
 * \return The OFNumber as an int64_t
 */
- (int64_t)asInt64;
- (int64_t)int64Value;

/**
 * \return The OFNumber as an uint8_t
 */
- (uint8_t)asUInt8;
- (uint8_t)uInt8Value;

/**
 * \return The OFNumber as an uint16_t
 */
- (uint16_t)asUInt16;
- (uint16_t)uInt16Value;

/**
 * \return The OFNumber as an uint32_t
 */
- (uint32_t)asUInt32;
- (uint32_t)uInt32Value;

/**
 * \return The OFNumber as an uint64_t
 */
- (uint64_t)asUInt64;
- (uint64_t)uInt64Value;

/**
 * \return The OFNumber as a size_t
 */
- (size_t)asSize;
- (size_t)sizeValue;

/**
 * \return The OFNumber as an ssize_t
 */
- (ssize_t)asSSize;
- (ssize_t)sSizeValue;

/**
 * \return The OFNumber as an intmax_t
 */
- (intmax_t)asIntMax;
- (intmax_t)intMaxValue;

/**
 * \return The OFNumber as an uintmax_t
 */
- (uintmax_t)asUIntMax;
- (uintmax_t)uIntMaxValue;

/**
 * \return The OFNumber as a ptrdiff_t
 */
- (ptrdiff_t)asPtrDiff;
- (ptrdiff_t)ptrDiffValue;

/**
 * \return The OFNumber as an intptr_t
 */
- (intptr_t)asIntPtr;
- (intptr_t)intPtrValue;

/**
 * \return The OFNumber as an uintptr_t
 */
- (uintptr_t)asUIntPtr;
- (uintptr_t)uIntPtrValue;

/**
 * \return The OFNumber as a float
 */
- (float)asFloat;
- (float)floatValue;

/**
 * \return The OFNumber as a double
 */
- (double)asDouble;
- (double)doubleValue;

/**
 * \param num The OFNumber to add
 * \return A new autoreleased OFNumber added with the specified OFNumber
 */
- (OFNumber*)numberByAdding: (OFNumber*)num;

Modified src/OFNumber.m from [1d85baa4c6] to [818b4fcf27].

70
71
72
73
74
75
76
77

78
79
80

81
82
83

84
85
86

87
88
89


90
91
92


93
94
95


96
97
98


99
100
101

102
103
104

105
106
107

108
109
110

111
112
113

114
115
116

117
118
119

120
121
122

123
124
125

126
127
128

129
130
131

132
133
134

135
136
137

138
139
140

141
142
143

144
145
146

147
148
149

150
151
152
153
154
155
156
157

158
159
160

161
162
163

164
165
166

167
168
169


170
171
172


173
174
175


176
177
178


179
180
181

182
183
184

185
186
187

188
189
190

191
192
193

194
195
196

197
198
199

200
201
202

203
204
205

206
207
208

209
210
211

212
213
214

215
216
217

218
219
220

221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242


243
244


245
246

247
248


249
250
251
252
253
254
255
70
71
72
73
74
75
76

77
78
79

80
81
82

83
84
85

86
87


88
89
90


91
92
93


94
95
96


97
98
99
100

101
102
103

104
105
106

107
108
109

110
111
112

113
114
115

116
117
118

119
120
121

122
123
124

125
126
127

128
129
130

131
132
133

134
135
136

137
138
139

140
141
142

143
144
145

146
147
148

149
150
151
152
153
154
155
156

157
158
159

160
161
162

163
164
165

166
167


168
169
170


171
172
173


174
175
176


177
178
179
180

181
182
183

184
185
186

187
188
189

190
191
192

193
194
195

196
197
198

199
200
201

202
203
204

205
206
207

208
209
210

211
212
213

214
215
216

217
218
219

220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

242
243
244

245
246
247

248
249

250
251
252
253
254
255
256
257
258







-
+


-
+


-
+


-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+







-
+


-
+


-
+


-
+

-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


-
+


















-
+
+

-
+
+

-
+

-
+
+







	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
	}
#define CALCULATE(o, n)							\
	switch (type) { 						\
	case OF_NUMBER_CHAR:						\
		return [OFNumber numberWithChar:			\
		    value.char_ o [n asChar]];				\
		    value.char_ o [n charValue]];			\
	case OF_NUMBER_SHORT:						\
		return [OFNumber numberWithShort:			\
		    value.short_ o [n asShort]];			\
		    value.short_ o [n shortValue]];			\
	case OF_NUMBER_INT:						\
		return [OFNumber numberWithInt:				\
		    value.int_ o [n asInt]];				\
		    value.int_ o [n intValue]];				\
	case OF_NUMBER_LONG:						\
		return [OFNumber numberWithLong:			\
		    value.long_ o [n asLong]];				\
		    value.long_ o [n longValue]];			\
	case OF_NUMBER_UCHAR:						\
		return [OFNumber numberWithUChar:			\
		    value.uchar o [n asUChar]];				\
		return [OFNumber numberWithUnsignedChar:		\
		    value.uchar o [n unsignedCharValue]];		\
	case OF_NUMBER_USHORT:						\
		return [OFNumber numberWithUShort:			\
		    value.ushort o [n asUShort]];			\
		return [OFNumber numberWithUnsignedShort:		\
		    value.ushort o [n unsignedShortValue]];		\
	case OF_NUMBER_UINT:						\
		return [OFNumber numberWithUInt:			\
		    value.uint o [n asUInt]];				\
		return [OFNumber numberWithUnsignedInt:			\
		    value.uint o [n unsignedIntValue]];			\
	case OF_NUMBER_ULONG:						\
		return [OFNumber numberWithULong:			\
		    value.ulong o [n asULong]];				\
		return [OFNumber numberWithUnsignedLong:		\
		    value.ulong o [n unsignedLongValue]];		\
	case OF_NUMBER_INT8:						\
		return [OFNumber numberWithInt8:			\
		    value.int8 o [n asInt8]];				\
		    value.int8 o [n int8Value]];			\
	case OF_NUMBER_INT16:						\
		return [OFNumber numberWithInt16:			\
		    value.int16 o [n asInt16]];				\
		    value.int16 o [n int16Value]];			\
	case OF_NUMBER_INT32:						\
		return [OFNumber numberWithInt32:			\
		    value.int32 o [n asInt32]];				\
		    value.int32 o [n int32Value]];			\
	case OF_NUMBER_INT64:						\
		return [OFNumber numberWithInt64:			\
		    value.int64 o [n asInt64]];				\
		    value.int64 o [n int64Value]];			\
	case OF_NUMBER_UINT8:						\
		return [OFNumber numberWithUInt8:			\
		    value.uint8 o [n asUInt8]];				\
		    value.uint8 o [n uInt8Value]];			\
	case OF_NUMBER_UINT16:						\
		return [OFNumber numberWithUInt16:			\
		    value.uint16 o [n asUInt16]];			\
		    value.uint16 o [n uInt16Value]];			\
	case OF_NUMBER_UINT32:						\
		return [OFNumber numberWithUInt32:			\
		    value.uint32 o [n asUInt32]];			\
		    value.uint32 o [n uInt32Value]];			\
	case OF_NUMBER_UINT64:						\
		return [OFNumber numberWithUInt64:			\
		    value.uint64 o [n asUInt64]];			\
		    value.uint64 o [n uInt64Value]];			\
	case OF_NUMBER_SIZE:						\
		return [OFNumber numberWithSize:			\
		    value.size o [n asSize]];				\
		    value.size o [n sizeValue]];			\
	case OF_NUMBER_SSIZE:						\
		return [OFNumber numberWithSSize:			\
		    value.ssize o [n asSSize]];				\
		    value.ssize o [n sSizeValue]];			\
	case OF_NUMBER_INTMAX:						\
		return [OFNumber numberWithIntMax:			\
		    value.intmax o [n asIntMax]];			\
		    value.intmax o [n intMaxValue]];			\
	case OF_NUMBER_UINTMAX:						\
		return [OFNumber numberWithUIntMax:			\
		    value.uintmax o [n asUIntMax]];			\
		    value.uintmax o [n uIntMaxValue]];			\
	case OF_NUMBER_PTRDIFF:						\
		return [OFNumber numberWithPtrDiff:			\
		    value.ptrdiff o [n asPtrDiff]];			\
		    value.ptrdiff o [n ptrDiffValue]];			\
	case OF_NUMBER_INTPTR:						\
		return [OFNumber numberWithIntPtr:			\
		    value.intptr o [n asIntPtr]];			\
		    value.intptr o [n intPtrValue]];			\
	case OF_NUMBER_UINTPTR:						\
		return [OFNumber numberWithUIntPtr:			\
		    value.uintptr o [n asUIntPtr]];			\
		    value.uintptr o [n uIntPtrValue]];			\
	case OF_NUMBER_FLOAT:						\
		return [OFNumber numberWithFloat:			\
		    value.float_ o [n asFloat]];			\
		    value.float_ o [n floatValue]];			\
	case OF_NUMBER_DOUBLE:						\
		return [OFNumber numberWithDouble:			\
		    value.double_ o [n asDouble]];			\
		    value.double_ o [n doubleValue]];			\
	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
	}
#define CALCULATE2(o, n)						\
	switch (type) { 						\
	case OF_NUMBER_CHAR:						\
		return [OFNumber numberWithChar:			\
		    value.char_ o [n asChar]];				\
		    value.char_ o [n charValue]];			\
	case OF_NUMBER_SHORT:						\
		return [OFNumber numberWithShort:			\
		    value.short_ o [n asShort]];			\
		    value.short_ o [n shortValue]];			\
	case OF_NUMBER_INT:						\
		return [OFNumber numberWithInt:				\
		    value.int_ o [n asInt]];				\
		    value.int_ o [n intValue]];				\
	case OF_NUMBER_LONG:						\
		return [OFNumber numberWithLong:			\
		    value.long_ o [n asLong]];				\
		    value.long_ o [n longValue]];			\
	case OF_NUMBER_UCHAR:						\
		return [OFNumber numberWithUChar:			\
		    value.uchar o [n asUChar]];				\
		return [OFNumber numberWithUnsignedChar:		\
		    value.uchar o [n unsignedCharValue]];		\
	case OF_NUMBER_USHORT:						\
		return [OFNumber numberWithUShort:			\
		    value.ushort o [n asUShort]];			\
		return [OFNumber numberWithUnsignedShort:		\
		    value.ushort o [n unsignedShortValue]];		\
	case OF_NUMBER_UINT:						\
		return [OFNumber numberWithUInt:			\
		    value.uint o [n asUInt]];				\
		return [OFNumber numberWithUnsignedInt:			\
		    value.uint o [n unsignedIntValue]];			\
	case OF_NUMBER_ULONG:						\
		return [OFNumber numberWithULong:			\
		    value.ulong o [n asULong]];				\
		return [OFNumber numberWithUnsignedLong:		\
		    value.ulong o [n unsignedLongValue]];		\
	case OF_NUMBER_INT8:						\
		return [OFNumber numberWithInt8:			\
		    value.int8 o [n asInt8]];				\
		    value.int8 o [n int8Value]];			\
	case OF_NUMBER_INT16:						\
		return [OFNumber numberWithInt16:			\
		    value.int16 o [n asInt16]];				\
		    value.int16 o [n int16Value]];			\
	case OF_NUMBER_INT32:						\
		return [OFNumber numberWithInt32:			\
		    value.int32 o [n asInt32]];				\
		    value.int32 o [n int32Value]];			\
	case OF_NUMBER_INT64:						\
		return [OFNumber numberWithInt64:			\
		    value.int64 o [n asInt64]];				\
		    value.int64 o [n int64Value]];			\
	case OF_NUMBER_UINT8:						\
		return [OFNumber numberWithUInt8:			\
		    value.uint8 o [n asUInt8]];				\
		    value.uint8 o [n uInt8Value]];			\
	case OF_NUMBER_UINT16:						\
		return [OFNumber numberWithUInt16:			\
		    value.uint16 o [n asUInt16]];			\
		    value.uint16 o [n uInt16Value]];			\
	case OF_NUMBER_UINT32:						\
		return [OFNumber numberWithUInt32:			\
		    value.uint32 o [n asUInt32]];			\
		    value.uint32 o [n uInt32Value]];			\
	case OF_NUMBER_UINT64:						\
		return [OFNumber numberWithUInt64:			\
		    value.uint64 o [n asUInt64]];			\
		    value.uint64 o [n uInt64Value]];			\
	case OF_NUMBER_SIZE:						\
		return [OFNumber numberWithSize:			\
		    value.size o [n asSize]];				\
		    value.size o [n sizeValue]];			\
	case OF_NUMBER_SSIZE:						\
		return [OFNumber numberWithSSize:			\
		    value.ssize o [n asSSize]];				\
		    value.ssize o [n sSizeValue]];			\
	case OF_NUMBER_INTMAX:						\
		return [OFNumber numberWithIntMax:			\
		    value.intmax o [n asIntMax]];			\
		    value.intmax o [n intMaxValue]];			\
	case OF_NUMBER_UINTMAX:						\
		return [OFNumber numberWithUIntMax:			\
		    value.uintmax o [n asUIntMax]];			\
		    value.uintmax o [n uIntMaxValue]];			\
	case OF_NUMBER_PTRDIFF:						\
		return [OFNumber numberWithPtrDiff:			\
		    value.ptrdiff o [n asPtrDiff]];			\
		    value.ptrdiff o [n ptrDiffValue]];			\
	case OF_NUMBER_INTPTR:						\
		return [OFNumber numberWithIntPtr:			\
		    value.intptr o [n asIntPtr]];			\
		    value.intptr o [n intPtrValue]];			\
	case OF_NUMBER_UINTPTR:						\
		return [OFNumber numberWithUIntPtr:			\
		    value.uintptr o [n asUIntPtr]];			\
		    value.uintptr o [n uIntPtrValue]];			\
	case OF_NUMBER_FLOAT:						\
	case OF_NUMBER_DOUBLE:						\
		@throw [OFNotImplementedException newWithClass: isa	\
						      selector: _cmd];	\
	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
	}
#define CALCULATE3(o)							\
	switch (type) {							\
	case OF_NUMBER_CHAR:						\
		return [OFNumber numberWithChar: value.char_ o];	\
	case OF_NUMBER_SHORT:						\
		return [OFNumber numberWithShort: value.short_ o];	\
	case OF_NUMBER_INT:						\
		return [OFNumber numberWithInt: value.int_ o];		\
	case OF_NUMBER_LONG:						\
		return [OFNumber numberWithLong: value.long_ o];	\
	case OF_NUMBER_UCHAR:						\
		return [OFNumber numberWithUChar: value.uchar o];	\
		return [OFNumber numberWithUnsignedChar:		\
		    value.uchar o];					\
	case OF_NUMBER_USHORT:						\
		return [OFNumber numberWithUShort: value.ushort o];	\
		return [OFNumber numberWithUnsignedShort:		\
		    value.ushort o];					\
	case OF_NUMBER_UINT:						\
		return [OFNumber numberWithUInt: value.uint o];		\
		return [OFNumber numberWithUnsignedInt: value.uint o];	\
	case OF_NUMBER_ULONG:						\
		return [OFNumber numberWithULong: value.ulong o];	\
		return [OFNumber numberWithUnsignedLong:		\
		    value.ulong o];	\
	case OF_NUMBER_INT8:						\
		return [OFNumber numberWithInt8: value.int8 o];		\
	case OF_NUMBER_INT16:						\
		return [OFNumber numberWithInt16: value.int16 o];	\
	case OF_NUMBER_INT32:						\
		return [OFNumber numberWithInt32: value.int32 o];	\
	case OF_NUMBER_INT64:						\
301
302
303
304
305
306
307
308

309
310

311
312
313

314
315

316
317
318

319
320

321
322
323

324
325

326
327
328
329
330
331
332
304
305
306
307
308
309
310

311
312

313
314
315

316
317

318
319
320

321
322

323
324
325

326
327

328
329
330
331
332
333
334
335







-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+







}

+ numberWithLong: (long)long_
{
	return [[[self alloc] initWithLong: long_] autorelease];
}

+ numberWithUChar: (unsigned char)uchar
+ numberWithUnsignedChar: (unsigned char)uchar
{
	return [[[self alloc] initWithUChar: uchar] autorelease];
	return [[[self alloc] initWithUnsignedChar: uchar] autorelease];
}

+ numberWithUShort: (unsigned short)ushort
+ numberWithUnsignedShort: (unsigned short)ushort
{
	return [[[self alloc] initWithUShort: ushort] autorelease];
	return [[[self alloc] initWithUnsignedShort: ushort] autorelease];
}

+ numberWithUInt: (unsigned int)uint
+ numberWithUnsignedInt: (unsigned int)uint
{
	return [[[self alloc] initWithUInt: uint] autorelease];
	return [[[self alloc] initWithUnsignedInt: uint] autorelease];
}

+ numberWithULong: (unsigned long)ulong
+ numberWithUnsignedLong: (unsigned long)ulong
{
	return [[[self alloc] initWithULong: ulong] autorelease];
	return [[[self alloc] initWithUnsignedLong: ulong] autorelease];
}

+ numberWithInt8: (int8_t)int8
{
	return [[[self alloc] initWithInt8: int8] autorelease];
}

452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468
469

470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499







-
+









-
+









-
+









-
+








	value.long_ = long_;
	type = OF_NUMBER_LONG;

	return self;
}

- initWithUChar: (unsigned char)uchar
- initWithUnsignedChar: (unsigned char)uchar
{
	self = [super init];

	value.uchar = uchar;
	type = OF_NUMBER_UCHAR;

	return self;
}

- initWithUShort: (unsigned short)ushort
- initWithUnsignedShort: (unsigned short)ushort
{
	self = [super init];

	value.ushort = ushort;
	type = OF_NUMBER_USHORT;

	return self;
}

- initWithUInt: (unsigned int)uint
- initWithUnsignedInt: (unsigned int)uint
{
	self = [super init];

	value.uint = uint;
	type = OF_NUMBER_UINT;

	return self;
}

- initWithULong: (unsigned long)ulong
- initWithUnsignedLong: (unsigned long)ulong
{
	self = [super init];

	value.ulong = ulong;
	type = OF_NUMBER_ULONG;

	return self;
667
668
669
670
671
672
673
674

675
676
677
678
679

680
681
682
683
684

685
686
687
688
689

690
691
692
693
694

695
696
697
698
699

700
701
702
703
704

705
706
707
708
709

710
711
712
713
714

715
716
717
718
719

720
721
722
723
724

725
726
727
728
729

730
731
732
733
734

735
736
737
738
739

740
741
742
743
744

745
746
747
748
749

750
751
752
753
754

755
756
757
758
759

760
761
762
763
764

765
766
767
768
769

770
771
772
773
774

775
776
777
778
779

780
781
782
783
784

785
786
787
788
789

790
791
792
793
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827
828
829
830

831
832
833
834

835
836
837
838
839
840
841
670
671
672
673
674
675
676

677
678
679
680
681

682
683
684
685
686

687
688
689
690
691

692
693
694
695
696

697
698
699
700
701

702
703
704
705
706

707
708
709
710
711

712
713
714
715
716

717
718
719
720
721

722
723
724
725
726

727
728
729
730
731

732
733
734
735
736

737
738
739
740
741

742
743
744
745
746

747
748
749
750
751

752
753
754
755
756

757
758
759
760
761

762
763
764
765
766

767
768
769
770
771

772
773
774
775
776

777
778
779
780
781

782
783
784
785
786

787
788
789
790
791

792
793
794
795
796

797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825
826
827
828
829
830
831
832

833
834
835
836

837
838
839
840
841
842
843
844







-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




















-
+














-
+



-
+







}

- (enum of_number_type)type
{
	return type;
}

- (char)asChar
- (char)charValue
{
	RETURN_AS(char)
}

- (short)asShort
- (short)shortValue
{
	RETURN_AS(short)
}

- (int)asInt
- (int)intValue
{
	RETURN_AS(int)
}

- (long)asLong
- (long)longValue
{
	RETURN_AS(long)
}

- (unsigned char)asUChar
- (unsigned char)unsignedCharValue
{
	RETURN_AS(unsigned char)
}

- (unsigned short)asUShort
- (unsigned short)unsignedShortValue
{
	RETURN_AS(unsigned short)
}

- (unsigned int)asUInt
- (unsigned int)unsignedIntValue
{
	RETURN_AS(unsigned int)
}

- (unsigned long)asULong
- (unsigned long)unsignedLongValue
{
	RETURN_AS(unsigned long)
}

- (int8_t)asInt8
- (int8_t)int8Value
{
	RETURN_AS(int8_t)
}

- (int16_t)asInt16
- (int16_t)int16Value
{
	RETURN_AS(int16_t)
}

- (int32_t)asInt32
- (int32_t)int32Value
{
	RETURN_AS(int32_t)
}

- (int64_t)asInt64
- (int64_t)int64Value
{
	RETURN_AS(int64_t)
}

- (uint8_t)asUInt8
- (uint8_t)uInt8Value
{
	RETURN_AS(uint8_t)
}

- (uint16_t)asUInt16
- (uint16_t)uInt16Value
{
	RETURN_AS(uint16_t)
}

- (uint32_t)asUInt32
- (uint32_t)uInt32Value
{
	RETURN_AS(uint32_t)
}

- (uint64_t)asUInt64
- (uint64_t)uInt64Value
{
	RETURN_AS(uint64_t)
}

- (size_t)asSize
- (size_t)sizeValue
{
	RETURN_AS(size_t)
}

- (ssize_t)asSSize
- (ssize_t)sSizeValue
{
	RETURN_AS(ssize_t)
}

- (intmax_t)asIntMax
- (intmax_t)intMaxValue
{
	RETURN_AS(intmax_t)
}

- (uintmax_t)asUIntMax
- (uintmax_t)uIntMaxValue
{
	RETURN_AS(uintmax_t)
}

- (ptrdiff_t)asPtrDiff
- (ptrdiff_t)ptrDiffValue
{
	RETURN_AS(ptrdiff_t)
}

- (intptr_t)asIntPtr
- (intptr_t)intPtrValue
{
	RETURN_AS(intptr_t)
}

- (uintptr_t)asUIntPtr
- (uintptr_t)uIntPtrValue
{
	RETURN_AS(uintptr_t)
}

- (float)asFloat
- (float)floatValue
{
	RETURN_AS(float)
}

- (double)asDouble
- (double)doubleValue
{
	RETURN_AS(double)
}

- (BOOL)isEqual: (OFObject*)obj
{
	if (![obj isKindOfClass: [OFNumber class]])
		return NO;

	switch (type) {
	case OF_NUMBER_CHAR:
	case OF_NUMBER_SHORT:
	case OF_NUMBER_INT:
	case OF_NUMBER_LONG:
	case OF_NUMBER_INT8:
	case OF_NUMBER_INT16:
	case OF_NUMBER_INT32:
	case OF_NUMBER_INT64:
	case OF_NUMBER_INTMAX:
	case OF_NUMBER_PTRDIFF:
		return ([(OFNumber*)obj asIntMax] == [self asIntMax]
		return ([(OFNumber*)obj intMaxValue] == [self intMaxValue]
		    ? YES : NO);
	case OF_NUMBER_SSIZE:
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:
	case OF_NUMBER_UINT8:
	case OF_NUMBER_UINT16:
	case OF_NUMBER_UINT32:
	case OF_NUMBER_UINT64:
	case OF_NUMBER_SIZE:
	case OF_NUMBER_UINTMAX:
	case OF_NUMBER_INTPTR:
	case OF_NUMBER_UINTPTR:
		return ([(OFNumber*)obj asUIntMax] == [self asUIntMax]
		return ([(OFNumber*)obj uIntMaxValue] == [self uIntMaxValue]
		    ? YES : NO);
	case OF_NUMBER_FLOAT:
	case OF_NUMBER_DOUBLE:
		return ([(OFNumber*)obj asDouble] == [self asDouble]
		return ([(OFNumber*)obj doubleValue] == [self doubleValue]
		    ? YES : NO);
	default:
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
	}
}

856
857
858
859
860
861
862
863

864
865
866
867
868
869
870
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873







-
+







		OF_HASH_INIT(hash);
		for (i = 0; i < sizeof(double); i++)
			OF_HASH_ADD(hash, ((char*)&value.double_)[i]);
		OF_HASH_FINALIZE(hash);

		return hash;
	default:
		return [self asUInt32];
		return [self uInt32Value];
	}
}

- (OFNumber*)numberByAdding: (OFNumber*)num
{
	CALCULATE(+, num)
}

Modified tests/OFNumberTests.m from [6bab1566e0] to [6cf377110f].

29
30
31
32
33
34
35
36

37
38
39
40
41
42
43

44
45
46
47
48


49
50
51
52

53
54
55
56
29
30
31
32
33
34
35

36
37
38
39
40
41
42

43
44
45
46


47
48
49
50
51

52
53
54
55
56







-
+






-
+



-
-
+
+



-
+




	    (num = [OFNumber numberWithIntMax: 123456789]))

	TEST(@"-[isEqual:]",
	    [num isEqual: [OFNumber numberWithUInt32: 123456789]])

	TEST(@"-[hash]", [num hash] == 123456789)

	TEST(@"-[asDouble]", [num asDouble] == 123456789.L)
	TEST(@"-[asDouble]", [num doubleValue] == 123456789.L)

	TEST(@"-[numberByDecreasing]",
	    [[num numberByDecreasing]
	    isEqual: [OFNumber numberWithInt32: 123456788]])

	TEST(@"-[numberByDividingBy:]",
	    [[num numberByDividingBy: [OFNumber numberWithInt: 2]] asInt] ==
	    [[num numberByDividingBy: [OFNumber numberWithInt: 2]] intValue] ==
	    61728394)

	TEST(@"-[numberByXORing:]",
	    [[num numberByXORing: [OFNumber numberWithInt: 123456831]] asInt] ==
	    42)
	    [[num numberByXORing: [OFNumber numberWithInt: 123456831]]
	    intValue] == 42)

	TEST(@"-[numberByShiftingRightBy:]",
	    [[num numberByShiftingRightBy: [OFNumber numberWithInt: 8]]
	    asInt] == 482253)
	    intValue] == 482253)

	[pool drain];
}
@end