ObjFW  Diff

Differences From Artifact [1d85baa4c6]:

To Artifact [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)
}