ObjFW  Diff

Differences From Artifact [2a910136b7]:

To Artifact [c650f7deea]:


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
57
58
59
60
61
62
63
64
65

66
67

68
69

70
71

72
73
74
75

76
77

78
79

80
81

82
83

84
85

86
87
88
89
90
91
92
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
57
58
59
60
61
62
63
64

65
66

67
68

69
70

71
72
73
74

75
76

77
78

79
80

81
82

83
84

85
86
87
88
89
90
91
92







-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+

-
+









-
+

-
+

-
+

-
+



-
+

-
+

-
+

-
+

-
+

-
+







#import "OFOutOfRangeException.h"

#define RETURN_AS(t)							\
	switch (_type) {						\
	case OF_NUMBER_TYPE_BOOL:					\
		return (t)_value.bool_;					\
	case OF_NUMBER_TYPE_CHAR:					\
		return (t)_value.schar;					\
		return (t)_value.sChar;					\
	case OF_NUMBER_TYPE_SHORT:					\
		return (t)_value.sshort;				\
		return (t)_value.sShort;				\
	case OF_NUMBER_TYPE_INT:					\
		return (t)_value.sint;					\
		return (t)_value.sInt;					\
	case OF_NUMBER_TYPE_LONG:					\
		return (t)_value.slong;					\
		return (t)_value.sLong;					\
	case OF_NUMBER_TYPE_LONGLONG:					\
		return (t)_value.slonglong;				\
		return (t)_value.sLongLong;				\
	case OF_NUMBER_TYPE_UCHAR:					\
		return (t)_value.uchar;					\
		return (t)_value.uChar;					\
	case OF_NUMBER_TYPE_USHORT:					\
		return (t)_value.ushort;				\
		return (t)_value.uShort;				\
	case OF_NUMBER_TYPE_UINT:					\
		return (t)_value.uint;					\
		return (t)_value.uInt;					\
	case OF_NUMBER_TYPE_ULONG:					\
		return (t)_value.ulong;					\
		return (t)_value.uLong;					\
	case OF_NUMBER_TYPE_ULONGLONG:					\
		return (t)_value.ulonglong;				\
		return (t)_value.uLongLong;				\
	case OF_NUMBER_TYPE_INT8:					\
		return (t)_value.int8;					\
	case OF_NUMBER_TYPE_INT16:					\
		return (t)_value.int16;					\
	case OF_NUMBER_TYPE_INT32:					\
		return (t)_value.int32;					\
	case OF_NUMBER_TYPE_INT64:					\
		return (t)_value.int64;					\
	case OF_NUMBER_TYPE_UINT8:					\
		return (t)_value.uint8;					\
		return (t)_value.uInt8;					\
	case OF_NUMBER_TYPE_UINT16:					\
		return (t)_value.uint16;				\
		return (t)_value.uInt16;				\
	case OF_NUMBER_TYPE_UINT32:					\
		return (t)_value.uint32;				\
		return (t)_value.uInt32;				\
	case OF_NUMBER_TYPE_UINT64:					\
		return (t)_value.uint64;				\
		return (t)_value.uInt64;				\
	case OF_NUMBER_TYPE_SIZE:					\
		return (t)_value.size;					\
	case OF_NUMBER_TYPE_SSIZE:					\
		return (t)_value.ssize;					\
		return (t)_value.sSize;					\
	case OF_NUMBER_TYPE_INTMAX:					\
		return (t)_value.intmax;				\
		return (t)_value.intMax;				\
	case OF_NUMBER_TYPE_UINTMAX:					\
		return (t)_value.uintmax;				\
		return (t)_value.uIntMax;				\
	case OF_NUMBER_TYPE_PTRDIFF:					\
		return (t)_value.ptrdiff;				\
		return (t)_value.ptrDiff;				\
	case OF_NUMBER_TYPE_INTPTR:					\
		return (t)_value.intptr;				\
		return (t)_value.intPtr;				\
	case OF_NUMBER_TYPE_UINTPTR:					\
		return (t)_value.uintptr;				\
		return (t)_value.uIntPtr;				\
	case OF_NUMBER_TYPE_FLOAT:					\
		return (t)_value.float_;				\
	case OF_NUMBER_TYPE_DOUBLE:					\
		return (t)_value.double_;				\
	default:							\
		@throw [OFInvalidFormatException exception];		\
	}
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
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







-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+







@synthesize type = _type;

+ (instancetype)numberWithBool: (bool)bool_
{
	return [[[self alloc] initWithBool: bool_] autorelease];
}

+ (instancetype)numberWithChar: (signed char)schar
+ (instancetype)numberWithChar: (signed char)sChar
{
	return [[[self alloc] initWithChar: schar] autorelease];
	return [[[self alloc] initWithChar: sChar] autorelease];
}

+ (instancetype)numberWithShort: (signed short)sshort
+ (instancetype)numberWithShort: (signed short)sShort
{
	return [[[self alloc] initWithShort: sshort] autorelease];
	return [[[self alloc] initWithShort: sShort] autorelease];
}

+ (instancetype)numberWithInt: (signed int)sint
+ (instancetype)numberWithInt: (signed int)sInt
{
	return [[[self alloc] initWithInt: sint] autorelease];
	return [[[self alloc] initWithInt: sInt] autorelease];
}

+ (instancetype)numberWithLong: (signed long)slong
+ (instancetype)numberWithLong: (signed long)sLong
{
	return [[[self alloc] initWithLong: slong] autorelease];
	return [[[self alloc] initWithLong: sLong] autorelease];
}

+ (instancetype)numberWithLongLong: (signed long long)slonglong
+ (instancetype)numberWithLongLong: (signed long long)sLongLong
{
	return [[[self alloc] initWithLongLong: slonglong] autorelease];
	return [[[self alloc] initWithLongLong: sLongLong] autorelease];
}

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

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

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

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

+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)ulonglong
+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)uLongLong
{
	return [[[self alloc] initWithUnsignedLongLong: ulonglong] autorelease];
	return [[[self alloc] initWithUnsignedLongLong: uLongLong] autorelease];
}

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

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
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







-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+







-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+


-
+

-
+







}

+ (instancetype)numberWithInt64: (int64_t)int64
{
	return [[[self alloc] initWithInt64: int64] autorelease];
}

+ (instancetype)numberWithUInt8: (uint8_t)uint8
+ (instancetype)numberWithUInt8: (uint8_t)uInt8
{
	return [[[self alloc] initWithUInt8: uint8] autorelease];
	return [[[self alloc] initWithUInt8: uInt8] autorelease];
}

+ (instancetype)numberWithUInt16: (uint16_t)uint16
+ (instancetype)numberWithUInt16: (uint16_t)uInt16
{
	return [[[self alloc] initWithUInt16: uint16] autorelease];
	return [[[self alloc] initWithUInt16: uInt16] autorelease];
}

+ (instancetype)numberWithUInt32: (uint32_t)uint32
+ (instancetype)numberWithUInt32: (uint32_t)uInt32
{
	return [[[self alloc] initWithUInt32: uint32] autorelease];
	return [[[self alloc] initWithUInt32: uInt32] autorelease];
}

+ (instancetype)numberWithUInt64: (uint64_t)uint64
+ (instancetype)numberWithUInt64: (uint64_t)uInt64
{
	return [[[self alloc] initWithUInt64: uint64] autorelease];
	return [[[self alloc] initWithUInt64: uInt64] autorelease];
}

+ (instancetype)numberWithSize: (size_t)size
{
	return [[[self alloc] initWithSize: size] autorelease];
}

+ (instancetype)numberWithSSize: (ssize_t)ssize
+ (instancetype)numberWithSSize: (ssize_t)sSize
{
	return [[[self alloc] initWithSSize: ssize] autorelease];
	return [[[self alloc] initWithSSize: sSize] autorelease];
}

+ (instancetype)numberWithIntMax: (intmax_t)intmax
+ (instancetype)numberWithIntMax: (intmax_t)intMax
{
	return [[[self alloc] initWithIntMax: intmax] autorelease];
	return [[[self alloc] initWithIntMax: intMax] autorelease];
}

+ (instancetype)numberWithUIntMax: (uintmax_t)uintmax
+ (instancetype)numberWithUIntMax: (uintmax_t)uIntMax
{
	return [[[self alloc] initWithUIntMax: uintmax] autorelease];
	return [[[self alloc] initWithUIntMax: uIntMax] autorelease];
}

+ (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrdiff
+ (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrDiff
{
	return [[[self alloc] initWithPtrDiff: ptrdiff] autorelease];
	return [[[self alloc] initWithPtrDiff: ptrDiff] autorelease];
}

+ (instancetype)numberWithIntPtr: (intptr_t)intptr
+ (instancetype)numberWithIntPtr: (intptr_t)intPtr
{
	return [[[self alloc] initWithIntPtr: intptr] autorelease];
	return [[[self alloc] initWithIntPtr: intPtr] autorelease];
}

+ (instancetype)numberWithUIntPtr: (uintptr_t)uintptr
+ (instancetype)numberWithUIntPtr: (uintptr_t)uIntPtr
{
	return [[[self alloc] initWithUIntPtr: uintptr] autorelease];
	return [[[self alloc] initWithUIntPtr: uIntPtr] autorelease];
}

+ (instancetype)numberWithFloat: (float)float_
{
	return [[[self alloc] initWithFloat: float_] autorelease];
}

250
251
252
253
254
255
256
257

258
259
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
299
300
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
333
334
335
336
337

338
339
340
341

342
343
344
345
346
347

348
349
350
351

352
353
354
355
356
357
358
250
251
252
253
254
255
256

257
258
259
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
299
300

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
333
334
335
336

337
338
339
340

341
342
343
344
345
346

347
348
349
350

351
352
353
354
355
356
357
358







-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+








	_value.bool_ = bool_;
	_type = OF_NUMBER_TYPE_BOOL;

	return self;
}

- (instancetype)initWithChar: (signed char)schar
- (instancetype)initWithChar: (signed char)sChar
{
	self = [super init];

	_value.schar = schar;
	_value.sChar = sChar;
	_type = OF_NUMBER_TYPE_CHAR;

	return self;
}

- (instancetype)initWithShort: (signed short)sshort
- (instancetype)initWithShort: (signed short)sShort
{
	self = [super init];

	_value.sshort = sshort;
	_value.sShort = sShort;
	_type = OF_NUMBER_TYPE_SHORT;

	return self;
}

- (instancetype)initWithInt: (signed int)sint
- (instancetype)initWithInt: (signed int)sInt
{
	self = [super init];

	_value.sint = sint;
	_value.sInt = sInt;
	_type = OF_NUMBER_TYPE_INT;

	return self;
}

- (instancetype)initWithLong: (signed long)slong
- (instancetype)initWithLong: (signed long)sLong
{
	self = [super init];

	_value.slong = slong;
	_value.sLong = sLong;
	_type = OF_NUMBER_TYPE_LONG;

	return self;
}

- (instancetype)initWithLongLong: (signed long long)slonglong
- (instancetype)initWithLongLong: (signed long long)sLongLong
{
	self = [super init];

	_value.slonglong = slonglong;
	_value.sLongLong = sLongLong;
	_type = OF_NUMBER_TYPE_LONGLONG;

	return self;
}

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

	_value.uchar = uchar;
	_value.uChar = uChar;
	_type = OF_NUMBER_TYPE_UCHAR;

	return self;
}

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

	_value.ushort = ushort;
	_value.uShort = uShort;
	_type = OF_NUMBER_TYPE_USHORT;

	return self;
}

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

	_value.uint = uint;
	_value.uInt = uInt;
	_type = OF_NUMBER_TYPE_UINT;

	return self;
}

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

	_value.ulong = ulong;
	_value.uLong = uLong;
	_type = OF_NUMBER_TYPE_ULONG;

	return self;
}

- (instancetype)initWithUnsignedLongLong: (unsigned long long)ulonglong
- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
{
	self = [super init];

	_value.ulonglong = ulonglong;
	_value.uLongLong = uLongLong;
	_type = OF_NUMBER_TYPE_ULONGLONG;

	return self;
}

- (instancetype)initWithInt8: (int8_t)int8
{
390
391
392
393
394
395
396
397

398
399
400
401

402
403
404
405
406
407

408
409
410
411

412
413
414
415
416
417

418
419
420
421

422
423
424
425
426
427

428
429
430
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
390
391
392
393
394
395
396

397
398
399
400

401
402
403
404
405
406

407
408
409
410

411
412
413
414
415
416

417
418
419
420

421
422
423
424
425
426

427
428
429
430

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







-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+















-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+





-
+



-
+








	_value.int64 = int64;
	_type = OF_NUMBER_TYPE_INT64;

	return self;
}

- (instancetype)initWithUInt8: (uint8_t)uint8
- (instancetype)initWithUInt8: (uint8_t)uInt8
{
	self = [super init];

	_value.uint8 = uint8;
	_value.uInt8 = uInt8;
	_type = OF_NUMBER_TYPE_UINT8;

	return self;
}

- (instancetype)initWithUInt16: (uint16_t)uint16
- (instancetype)initWithUInt16: (uint16_t)uInt16
{
	self = [super init];

	_value.uint16 = uint16;
	_value.uInt16 = uInt16;
	_type = OF_NUMBER_TYPE_UINT16;

	return self;
}

- (instancetype)initWithUInt32: (uint32_t)uint32
- (instancetype)initWithUInt32: (uint32_t)uInt32
{
	self = [super init];

	_value.uint32 = uint32;
	_value.uInt32 = uInt32;
	_type = OF_NUMBER_TYPE_UINT32;

	return self;
}

- (instancetype)initWithUInt64: (uint64_t)uint64
- (instancetype)initWithUInt64: (uint64_t)uInt64
{
	self = [super init];

	_value.uint64 = uint64;
	_value.uInt64 = uInt64;
	_type = OF_NUMBER_TYPE_UINT64;

	return self;
}

- (instancetype)initWithSize: (size_t)size
{
	self = [super init];

	_value.size = size;
	_type = OF_NUMBER_TYPE_SIZE;

	return self;
}

- (instancetype)initWithSSize: (ssize_t)ssize
- (instancetype)initWithSSize: (ssize_t)sSize
{
	self = [super init];

	_value.ssize = ssize;
	_value.sSize = sSize;
	_type = OF_NUMBER_TYPE_SSIZE;

	return self;
}

- (instancetype)initWithIntMax: (intmax_t)intmax
- (instancetype)initWithIntMax: (intmax_t)intMax
{
	self = [super init];

	_value.intmax = intmax;
	_value.intMax = intMax;
	_type = OF_NUMBER_TYPE_INTMAX;

	return self;
}

- (instancetype)initWithUIntMax: (uintmax_t)uintmax
- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
{
	self = [super init];

	_value.uintmax = uintmax;
	_value.uIntMax = uIntMax;
	_type = OF_NUMBER_TYPE_UINTMAX;

	return self;
}

- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrdiff
- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
{
	self = [super init];

	_value.ptrdiff = ptrdiff;
	_value.ptrDiff = ptrDiff;
	_type = OF_NUMBER_TYPE_PTRDIFF;

	return self;
}

- (instancetype)initWithIntPtr: (intptr_t)intptr
- (instancetype)initWithIntPtr: (intptr_t)intPtr
{
	self = [super init];

	_value.intptr = intptr;
	_value.intPtr = intPtr;
	_type = OF_NUMBER_TYPE_INTPTR;

	return self;
}

- (instancetype)initWithUIntPtr: (uintptr_t)uintptr
- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
{
	self = [super init];

	_value.uintptr = uintptr;
	_value.uIntPtr = uIntPtr;
	_type = OF_NUMBER_TYPE_UINTPTR;

	return self;
}

- (instancetype)initWithFloat: (float)float_
{
549
550
551
552
553
554
555
556

557
558
559

560
561
562
563
564
565
566
549
550
551
552
553
554
555

556
557
558

559
560
561
562
563
564
565
566







-
+


-
+







				@throw [OFInvalidArgumentException exception];
		} else if ([typeString isEqual: @"unsigned"]) {
			/*
			 * FIXME: This will fail if the value is bigger than
			 *	  INTMAX_MAX!
			 */
			_type = OF_NUMBER_TYPE_UINTMAX;
			_value.uintmax = [element decimalValue];
			_value.uIntMax = [element decimalValue];
		} else if ([typeString isEqual: @"signed"]) {
			_type = OF_NUMBER_TYPE_INTMAX;
			_value.intmax = [element decimalValue];
			_value.intMax = [element decimalValue];
		} else if ([typeString isEqual: @"float"]) {
			union {
				float f;
				uint32_t u;
			} f;

			f.u = OF_BSWAP32_IF_LE(