ObjFW  Check-in [5e8cca7678]

Overview
Comment:OFNumber: Always use the smallest type that fits
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5e8cca7678d6dec35890ef2f1e691694a5324168cc90c93cb3a695682f78e175
User & Date: js on 2020-07-19 11:03:55
Other Links: manifest | tags
Context
2020-07-19
11:49
OFNumber: Refactor to reduce code size check-in: 59e1c84d30 user: js tags: trunk
11:03
OFNumber: Always use the smallest type that fits check-in: 5e8cca7678 user: js tags: trunk
09:06
OFNumber: Use a placeholder until init is called check-in: 025756f4e3 user: js tags: trunk
Changes

Modified src/OFNumber.h from [f7f55d0f21] to [dfa33f4cd7].

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	OF_NUMBER_TYPE_UINTPTR		= 0x0C,
	/*! `uintmax_t` */
	OF_NUMBER_TYPE_UINTMAX		= 0x0D,
	OF_NUMBER_TYPE_SIGNED		= 0x10,
	/*! `signed char` */
	OF_NUMBER_TYPE_CHAR		= OF_NUMBER_TYPE_UCHAR |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `signed short` */
	OF_NUMBER_TYPE_SHORT		= OF_NUMBER_TYPE_USHORT |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `signed int` */
	OF_NUMBER_TYPE_INT		= OF_NUMBER_TYPE_UINT |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `signed long` */
	OF_NUMBER_TYPE_LONG		= OF_NUMBER_TYPE_ULONG |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `signed long long` */
	OF_NUMBER_TYPE_LONGLONG		= OF_NUMBER_TYPE_ULONGLONG |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `int8_t` */
	OF_NUMBER_TYPE_INT8		= OF_NUMBER_TYPE_UINT8 |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `int16_t` */
	OF_NUMBER_TYPE_INT16		= OF_NUMBER_TYPE_UINT16 |







|


|


|


|







67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	OF_NUMBER_TYPE_UINTPTR		= 0x0C,
	/*! `uintmax_t` */
	OF_NUMBER_TYPE_UINTMAX		= 0x0D,
	OF_NUMBER_TYPE_SIGNED		= 0x10,
	/*! `signed char` */
	OF_NUMBER_TYPE_CHAR		= OF_NUMBER_TYPE_UCHAR |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `short` */
	OF_NUMBER_TYPE_SHORT		= OF_NUMBER_TYPE_USHORT |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `int` */
	OF_NUMBER_TYPE_INT		= OF_NUMBER_TYPE_UINT |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `long` */
	OF_NUMBER_TYPE_LONG		= OF_NUMBER_TYPE_ULONG |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `long long` */
	OF_NUMBER_TYPE_LONGLONG		= OF_NUMBER_TYPE_ULONGLONG |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `int8_t` */
	OF_NUMBER_TYPE_INT8		= OF_NUMBER_TYPE_UINT8 |
					      OF_NUMBER_TYPE_SIGNED,
	/*! `int16_t` */
	OF_NUMBER_TYPE_INT16		= OF_NUMBER_TYPE_UINT16 |
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#endif
@interface OFNumber: OFValue <OFComparing, OFSerialization,
    OFJSONRepresentation, OFMessagePackRepresentation>
{
	union of_number_value {
		bool		   bool_;
		signed char	   sChar;
		signed short	   sShort;
		signed int	   sInt;
		signed long	   sLong;
		signed long long   sLongLong;
		unsigned char	   uChar;
		unsigned short	   uShort;
		unsigned int	   uInt;
		unsigned long	   uLong;
		unsigned long long uLongLong;
		int8_t		   int8;
		int16_t		   int16;







|
|
|
|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#endif
@interface OFNumber: OFValue <OFComparing, OFSerialization,
    OFJSONRepresentation, OFMessagePackRepresentation>
{
	union of_number_value {
		bool		   bool_;
		signed char	   sChar;
		short              sShort;
		int                sInt;
		long               sLong;
		long long          sLongLong;
		unsigned char	   uChar;
		unsigned short	   uShort;
		unsigned int	   uInt;
		unsigned long	   uLong;
		unsigned long long uLongLong;
		int8_t		   int8;
		int16_t		   int16;
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

/*!
 * @brief The OFNumber as a `signed char`.
 */
@property (readonly, nonatomic) signed char charValue;

/*!
 * @brief The OFNumber as a `signed short`.
 */
@property (readonly, nonatomic) signed short shortValue;

/*!
 * @brief The OFNumber as a `signed int`.
 */
@property (readonly, nonatomic) signed int intValue;

/*!
 * @brief The OFNumber as a `signed long`.
 */
@property (readonly, nonatomic) signed long longValue;

/*!
 * @brief The OFNumber as a `signed long long`.
 */
@property (readonly, nonatomic) signed long long longLongValue;

/*!
 * @brief The OFNumber as an `unsigned char`.
 */
@property (readonly, nonatomic) unsigned char unsignedCharValue;

/*!







|

|


|

|


|

|


|

|







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

/*!
 * @brief The OFNumber as a `signed char`.
 */
@property (readonly, nonatomic) signed char charValue;

/*!
 * @brief The OFNumber as a `short`.
 */
@property (readonly, nonatomic) short shortValue;

/*!
 * @brief The OFNumber as an `int`.
 */
@property (readonly, nonatomic) int intValue;

/*!
 * @brief The OFNumber as a `long`.
 */
@property (readonly, nonatomic) long longValue;

/*!
 * @brief The OFNumber as a `long long`.
 */
@property (readonly, nonatomic) long long longLongValue;

/*!
 * @brief The OFNumber as an `unsigned char`.
 */
@property (readonly, nonatomic) unsigned char unsignedCharValue;

/*!
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
 *
 * @param sChar A `signed char` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithChar: (signed char)sChar;

/*!
 * @brief Creates a new OFNumber with the specified `signed short`.
 *
 * @param sShort A `signed short` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithShort: (signed short)sShort;

/*!
 * @brief Creates a new OFNumber with the specified `signed int`.
 *
 * @param sInt A `signed int` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithInt: (signed int)sInt;

/*!
 * @brief Creates a new OFNumber with the specified `signed long`.
 *
 * @param sLong A `signed long` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithLong: (signed long)sLong;

/*!
 * @brief Creates a new OFNumber with the specified `signed long long`.
 *
 * @param sLongLong A `signed long long` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithLongLong: (signed long long)sLongLong;

/*!
 * @brief Creates a new OFNumber with the specified `unsigned char`.
 *
 * @param uChar An `unsigned char` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */







|

|


|


|

|


|


|

|


|


|

|


|







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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
 *
 * @param sChar A `signed char` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithChar: (signed char)sChar;

/*!
 * @brief Creates a new OFNumber with the specified `short`.
 *
 * @param sShort A `short` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithShort: (short)sShort;

/*!
 * @brief Creates a new OFNumber with the specified `int`.
 *
 * @param sInt An `int` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithInt: (int)sInt;

/*!
 * @brief Creates a new OFNumber with the specified `long`.
 *
 * @param sLong A `long` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithLong: (long)sLong;

/*!
 * @brief Creates a new OFNumber with the specified `long long`.
 *
 * @param sLongLong A `long long` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithLongLong: (long long)sLongLong;

/*!
 * @brief Creates a new OFNumber with the specified `unsigned char`.
 *
 * @param uChar An `unsigned char` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
 *
 * @param sChar A `signed char` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithChar: (signed char)sChar;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `signed short`.
 *
 * @param sShort A `signed short` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithShort: (signed short)sShort;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `signed int`.
 *
 * @param sInt A `signed int` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithInt: (signed int)sInt;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `signed long`.
 *
 * @param sLong A `signed long` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithLong: (signed long)sLong;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `signed long long`.
 *
 * @param sLongLong A `signed long long` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithLongLong: (signed long long)sLongLong;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `unsigned char`.
 *
 * @param uChar An `unsigned char` which the OFNumber should contain
 * @return An initialized OFNumber







|
<

|


|


|
<

|


|


|
<

|


|



|

|


|







566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
 *
 * @param sChar A `signed char` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithChar: (signed char)sChar;

/*!
 * @brief Initializes an already allocated OFNumber with the specified `short`.

 *
 * @param sShort A `short` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithShort: (short)sShort;

/*!
 * @brief Initializes an already allocated OFNumber with the specified `int`.

 *
 * @param sInt An `int` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithInt: (int)sInt;

/*!
 * @brief Initializes an already allocated OFNumber with the specified `long`.

 *
 * @param sLong A `long` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithLong: (long)sLong;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `long long`.
 *
 * @param sLongLong A `long long` which the OFNumber should contain
 * @return An initialized OFNumber
 */
- (instancetype)initWithLongLong: (long long)sLongLong;

/*!
 * @brief Initializes an already allocated OFNumber with the specified
 *	  `unsigned char`.
 *
 * @param uChar An `unsigned char` which the OFNumber should contain
 * @return An initialized OFNumber

Modified src/OFNumber.m from [fe840b486f] to [68a0381598].

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
- (instancetype)initWithBool: (bool)bool_
{
	return (id)[[OFNumber of_alloc] initWithBool: bool_];
}

- (instancetype)initWithChar: (signed char)sChar
{



	return (id)[[OFNumber of_alloc] initWithChar: sChar];
}

- (instancetype)initWithShort: (signed short)sShort
{






	return (id)[[OFNumber of_alloc] initWithShort: sShort];
}

- (instancetype)initWithInt: (signed int)sInt
{





	return (id)[[OFNumber of_alloc] initWithInt: sInt];
}

- (instancetype)initWithLong: (signed long)sLong
{





	return (id)[[OFNumber of_alloc] initWithLong: sLong];
}

- (instancetype)initWithLongLong: (signed long long)sLongLong
{






	return (id)[[OFNumber of_alloc] initWithLongLong: sLongLong];
}

- (instancetype)initWithUnsignedChar: (unsigned char)uChar
{
	return (id)[[OFNumber of_alloc] initWithUnsignedChar: uChar];
}

- (instancetype)initWithUnsignedShort: (unsigned short)uShort
{




	return (id)[[OFNumber of_alloc] initWithUnsignedShort: uShort];
}

- (instancetype)initWithUnsignedInt: (unsigned int)uInt
{




	return (id)[[OFNumber of_alloc] initWithUnsignedInt: uInt];
}

- (instancetype)initWithUnsignedLong: (unsigned long)uLong
{




	return (id)[[OFNumber of_alloc] initWithUnsignedLong: uLong];
}

- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
{




	return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: uLongLong];
}

- (instancetype)initWithInt8: (int8_t)int8
{



	return (id)[[OFNumber of_alloc] initWithInt8: int8];
}

- (instancetype)initWithInt16: (int16_t)int16
{





	return (id)[[OFNumber of_alloc] initWithInt16: int16];
}

- (instancetype)initWithInt32: (int32_t)int32
{





	return (id)[[OFNumber of_alloc] initWithInt32: int32];
}

- (instancetype)initWithInt64: (int64_t)int64
{





	return (id)[[OFNumber of_alloc] initWithInt64: int64];
}

- (instancetype)initWithUInt8: (uint8_t)uInt8
{
	return (id)[[OFNumber of_alloc] initWithUInt8: uInt8];
}

- (instancetype)initWithUInt16: (uint16_t)uInt16
{



	return (id)[[OFNumber of_alloc] initWithUInt16: uInt16];
}

- (instancetype)initWithUInt32: (uint32_t)uInt32
{




	return (id)[[OFNumber of_alloc] initWithUInt32: uInt32];
}

- (instancetype)initWithUInt64: (uint64_t)uInt64
{




	return (id)[[OFNumber of_alloc] initWithUInt64: uInt64];
}

- (instancetype)initWithSize: (size_t)size
{




	return (id)[[OFNumber of_alloc] initWithSize: size];
}

- (instancetype)initWithSSize: (ssize_t)sSize
{





	return (id)[[OFNumber of_alloc] initWithSSize: sSize];
}

- (instancetype)initWithIntMax: (intmax_t)intMax
{






	return (id)[[OFNumber of_alloc] initWithIntMax: intMax];
}

- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
{




	return (id)[[OFNumber of_alloc] initWithUIntMax: uIntMax];
}

- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
{




	return (id)[[OFNumber of_alloc] initWithPtrDiff: ptrDiff];
}

- (instancetype)initWithIntPtr: (intptr_t)intPtr
{






	return (id)[[OFNumber of_alloc] initWithIntPtr: intPtr];
}

- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
{




	return (id)[[OFNumber of_alloc] initWithUIntPtr: uIntPtr];
}

- (instancetype)initWithFloat: (float)float_
{







	return (id)[[OFNumber of_alloc] initWithFloat: float_];
}

- (instancetype)initWithDouble: (double)double_
{









	return (id)[[OFNumber of_alloc] initWithDouble: double_];
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	return (id)[[OFNumber of_alloc] initWithSerialization: element];
}







>
>
>



|

>
>
>
>
>
>



|

>
>
>
>
>



|

>
>
>
>
>



|

>
>
>
>
>
>










>
>
>
>





>
>
>
>





>
>
>
>





>
>
>
>





>
>
>





>
>
>
>
>





>
>
>
>
>





>
>
>
>
>










>
>
>





>
>
>
>





>
>
>
>





>
>
>
>





>
>
>
>
>





>
>
>
>
>
>





>
>
>
>





>
>
>
>





>
>
>
>
>
>





>
>
>
>





>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>







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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
- (instancetype)initWithBool: (bool)bool_
{
	return (id)[[OFNumber of_alloc] initWithBool: bool_];
}

- (instancetype)initWithChar: (signed char)sChar
{
	if (sChar >= 0)
		return (id)[[OFNumber of_alloc] initWithUnsignedChar: sChar];

	return (id)[[OFNumber of_alloc] initWithChar: sChar];
}

- (instancetype)initWithShort: (short)sShort
{
	if (sShort >= 0)
		return (id)[[OFNumber of_alloc] initWithUnsignedShort: sShort];
	if (sShort >= SCHAR_MIN)
		return (id)[[OFNumber of_alloc]
		    initWithChar: (signed char)sShort];

	return (id)[[OFNumber of_alloc] initWithShort: sShort];
}

- (instancetype)initWithInt: (int)sInt
{
	if (sInt >= 0)
		return (id)[[OFNumber of_alloc] initWithUnsignedInt: sInt];
	if (sInt >= SHRT_MIN)
		return (id)[[OFNumber of_alloc] initWithShort: (short)sInt];

	return (id)[[OFNumber of_alloc] initWithInt: sInt];
}

- (instancetype)initWithLong: (long)sLong
{
	if (sLong >= 0)
		return (id)[[OFNumber of_alloc] initWithUnsignedLong: sLong];
	if (sLong >= INT_MIN)
		return (id)[[OFNumber of_alloc] initWithShort: (int)sLong];

	return (id)[[OFNumber of_alloc] initWithLong: sLong];
}

- (instancetype)initWithLongLong: (long long)sLongLong
{
	if (sLongLong >= 0)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedLongLong: sLongLong];
	if (sLongLong >= LONG_MIN)
		return (id)[[OFNumber of_alloc] initWithLong: (long)sLongLong];

	return (id)[[OFNumber of_alloc] initWithLongLong: sLongLong];
}

- (instancetype)initWithUnsignedChar: (unsigned char)uChar
{
	return (id)[[OFNumber of_alloc] initWithUnsignedChar: uChar];
}

- (instancetype)initWithUnsignedShort: (unsigned short)uShort
{
	if (uShort <= UCHAR_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedChar: (unsigned char)uShort];

	return (id)[[OFNumber of_alloc] initWithUnsignedShort: uShort];
}

- (instancetype)initWithUnsignedInt: (unsigned int)uInt
{
	if (uInt <= USHRT_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedShort: (unsigned short)uInt];

	return (id)[[OFNumber of_alloc] initWithUnsignedInt: uInt];
}

- (instancetype)initWithUnsignedLong: (unsigned long)uLong
{
	if (uLong <= UINT_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedInt: (unsigned int)uLong];

	return (id)[[OFNumber of_alloc] initWithUnsignedLong: uLong];
}

- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
{
	if (uLongLong <= ULONG_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedLong: (unsigned long)uLongLong];

	return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: uLongLong];
}

- (instancetype)initWithInt8: (int8_t)int8
{
	if (int8 >= 0)
		return (id)[[OFNumber of_alloc] initWithUInt8: int8];

	return (id)[[OFNumber of_alloc] initWithInt8: int8];
}

- (instancetype)initWithInt16: (int16_t)int16
{
	if (int16 >= 0)
		return (id)[[OFNumber of_alloc] initWithUInt16: int16];
	if (int16 >= INT8_MIN)
		return (id)[[OFNumber of_alloc] initWithInt8: (int8_t)int16];

	return (id)[[OFNumber of_alloc] initWithInt16: int16];
}

- (instancetype)initWithInt32: (int32_t)int32
{
	if (int32 >= 0)
		return (id)[[OFNumber of_alloc] initWithUInt32: int32];
	if (int32 >= INT16_MIN)
		return (id)[[OFNumber of_alloc] initWithInt16: (int16_t)int32];

	return (id)[[OFNumber of_alloc] initWithInt32: int32];
}

- (instancetype)initWithInt64: (int64_t)int64
{
	if (int64 >= 0)
		return (id)[[OFNumber of_alloc] initWithUInt64: int64];
	if (int64 >= INT32_MIN)
		return (id)[[OFNumber of_alloc] initWithInt32: (int32_t)int64];

	return (id)[[OFNumber of_alloc] initWithInt64: int64];
}

- (instancetype)initWithUInt8: (uint8_t)uInt8
{
	return (id)[[OFNumber of_alloc] initWithUInt8: uInt8];
}

- (instancetype)initWithUInt16: (uint16_t)uInt16
{
	if (uInt16 <= UINT8_MAX)
		return (id)[[OFNumber of_alloc] initWithUInt8: (uint8_t)uInt16];

	return (id)[[OFNumber of_alloc] initWithUInt16: uInt16];
}

- (instancetype)initWithUInt32: (uint32_t)uInt32
{
	if (uInt32 <= UINT16_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUInt16: (uint16_t)uInt32];

	return (id)[[OFNumber of_alloc] initWithUInt32: uInt32];
}

- (instancetype)initWithUInt64: (uint64_t)uInt64
{
	if (uInt64 <= UINT32_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUInt32: (uint32_t)uInt64];

	return (id)[[OFNumber of_alloc] initWithUInt64: uInt64];
}

- (instancetype)initWithSize: (size_t)size
{
	if (size <= ULONG_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedLong: (unsigned long)size];

	return (id)[[OFNumber of_alloc] initWithSize: size];
}

- (instancetype)initWithSSize: (ssize_t)sSize
{
	if (sSize >= 0)
		return (id)[[OFNumber of_alloc] initWithSize: sSize];
	if (sSize <= LONG_MIN)
		return (id)[[OFNumber of_alloc] initWithLong: (long)sSize];

	return (id)[[OFNumber of_alloc] initWithSSize: sSize];
}

- (instancetype)initWithIntMax: (intmax_t)intMax
{
	if (intMax >= 0)
		return (id)[[OFNumber of_alloc] initWithUIntMax: intMax];
	if (intMax <= LLONG_MIN)
		return (id)[[OFNumber of_alloc]
		    initWithLongLong: (long long)intMax];

	return (id)[[OFNumber of_alloc] initWithIntMax: intMax];
}

- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
{
	if (uIntMax <= ULLONG_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedLongLong: (unsigned long long)uIntMax];

	return (id)[[OFNumber of_alloc] initWithUIntMax: uIntMax];
}

- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
{
	if (ptrDiff >= LLONG_MIN && ptrDiff <= LLONG_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithLongLong: (long long)ptrDiff];

	return (id)[[OFNumber of_alloc] initWithPtrDiff: ptrDiff];
}

- (instancetype)initWithIntPtr: (intptr_t)intPtr
{
	if (intPtr >= 0)
		return (id)[[OFNumber of_alloc] initWithUIntPtr: intPtr];
	if (intPtr >= LLONG_MIN)
		return (id)[[OFNumber of_alloc]
		    initWithLongLong: (long long)intPtr];

	return (id)[[OFNumber of_alloc] initWithIntPtr: intPtr];
}

- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
{
	if (uIntPtr <= ULLONG_MAX)
		return (id)[[OFNumber of_alloc]
		    initWithUnsignedLongLong: (unsigned long long)uIntPtr];

	return (id)[[OFNumber of_alloc] initWithUIntPtr: uIntPtr];
}

- (instancetype)initWithFloat: (float)float_
{
	if (float_ == (uintmax_t)float_)
		return (id)[[OFNumber of_alloc]
		    initWithUIntMax: (uintmax_t)float_];
	if (float_ == (intmax_t)float_)
		return (id)[[OFNumber of_alloc]
		    initWithIntMax: (intmax_t)float_];

	return (id)[[OFNumber of_alloc] initWithFloat: float_];
}

- (instancetype)initWithDouble: (double)double_
{
	if (double_ == (uintmax_t)double_)
		return (id)[[OFNumber of_alloc]
		    initWithUIntMax: (uintmax_t)double_];
	if (double_ == (intmax_t)double_)
		return (id)[[OFNumber of_alloc]
		    initWithIntMax: (intmax_t)double_];
	if (double_ == (float)double_)
		return (id)[[OFNumber of_alloc] initWithFloat: (float)double_];

	return (id)[[OFNumber of_alloc] initWithDouble: double_];
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	return (id)[[OFNumber of_alloc] initWithSerialization: element];
}
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
}

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

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

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

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

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

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







|




|




|




|







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
}

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

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

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

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

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

+ (instancetype)numberWithUnsignedChar: (unsigned char)uChar
{
	return [[[self alloc] initWithUnsignedChar: uChar] autorelease];
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

	_value.sChar = sChar;
	_type = OF_NUMBER_TYPE_CHAR;

	return self;
}

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

	_value.sShort = sShort;
	_type = OF_NUMBER_TYPE_SHORT;

	return self;
}

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

	_value.sInt = sInt;
	_type = OF_NUMBER_TYPE_INT;

	return self;
}

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

	_value.sLong = sLong;
	_type = OF_NUMBER_TYPE_LONG;

	return self;
}

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

	_value.sLongLong = sLongLong;
	_type = OF_NUMBER_TYPE_LONGLONG;

	return self;







|









|









|









|







555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599

	_value.sChar = sChar;
	_type = OF_NUMBER_TYPE_CHAR;

	return self;
}

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

	_value.sShort = sShort;
	_type = OF_NUMBER_TYPE_SHORT;

	return self;
}

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

	_value.sInt = sInt;
	_type = OF_NUMBER_TYPE_INT;

	return self;
}

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

	_value.sLong = sLong;
	_type = OF_NUMBER_TYPE_LONG;

	return self;
}

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

	_value.sLongLong = sLongLong;
	_type = OF_NUMBER_TYPE_LONGLONG;

	return self;
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
{
	switch (_type) {
	case OF_NUMBER_TYPE_BOOL:
		return @encode(bool);
	case OF_NUMBER_TYPE_CHAR:
		return @encode(signed char);
	case OF_NUMBER_TYPE_SHORT:
		return @encode(signed short);
	case OF_NUMBER_TYPE_INT:
		return @encode(signed int);
	case OF_NUMBER_TYPE_LONG:
		return @encode(signed long);
	case OF_NUMBER_TYPE_LONGLONG:
		return @encode(signed long long);
	case OF_NUMBER_TYPE_UCHAR:
		return @encode(unsigned char);
	case OF_NUMBER_TYPE_USHORT:
		return @encode(unsigned short);
	case OF_NUMBER_TYPE_UINT:
		return @encode(unsigned int);
	case OF_NUMBER_TYPE_ULONG:







|

|

|

|







878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
{
	switch (_type) {
	case OF_NUMBER_TYPE_BOOL:
		return @encode(bool);
	case OF_NUMBER_TYPE_CHAR:
		return @encode(signed char);
	case OF_NUMBER_TYPE_SHORT:
		return @encode(short);
	case OF_NUMBER_TYPE_INT:
		return @encode(int);
	case OF_NUMBER_TYPE_LONG:
		return @encode(long);
	case OF_NUMBER_TYPE_LONGLONG:
		return @encode(long long);
	case OF_NUMBER_TYPE_UCHAR:
		return @encode(unsigned char);
	case OF_NUMBER_TYPE_USHORT:
		return @encode(unsigned short);
	case OF_NUMBER_TYPE_UINT:
		return @encode(unsigned int);
	case OF_NUMBER_TYPE_ULONG:
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
	case OF_NUMBER_TYPE_CHAR:
		if (size != sizeof(signed char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sChar, sizeof(signed char));
		break;
	case OF_NUMBER_TYPE_SHORT:
		if (size != sizeof(signed short))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sShort, sizeof(signed short));
		break;
	case OF_NUMBER_TYPE_INT:
		if (size != sizeof(signed int))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sInt, sizeof(signed int));
		break;
	case OF_NUMBER_TYPE_LONG:
		if (size != sizeof(signed long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLong, sizeof(signed long));
		break;
	case OF_NUMBER_TYPE_LONGLONG:
		if (size != sizeof(signed long long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLongLong, sizeof(signed long long));
		break;
	case OF_NUMBER_TYPE_UCHAR:
		if (size != sizeof(unsigned char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uChar, sizeof(unsigned char));
		break;







|


|


|


|


|


|


|


|







951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
	case OF_NUMBER_TYPE_CHAR:
		if (size != sizeof(signed char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sChar, sizeof(signed char));
		break;
	case OF_NUMBER_TYPE_SHORT:
		if (size != sizeof(short))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sShort, sizeof(short));
		break;
	case OF_NUMBER_TYPE_INT:
		if (size != sizeof(int))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sInt, sizeof(int));
		break;
	case OF_NUMBER_TYPE_LONG:
		if (size != sizeof(long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLong, sizeof(long));
		break;
	case OF_NUMBER_TYPE_LONGLONG:
		if (size != sizeof(long long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLongLong, sizeof(long long));
		break;
	case OF_NUMBER_TYPE_UCHAR:
		if (size != sizeof(unsigned char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uChar, sizeof(unsigned char));
		break;
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
}

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

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

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

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

- (signed long long)longLongValue
{
	RETURN_AS(signed long long)
}

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








|

|


|

|


|

|


|

|







1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
}

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

- (short)shortValue
{
	RETURN_AS(short)
}

- (int)intValue
{
	RETURN_AS(int)
}

- (long)longValue
{
	RETURN_AS(long)
}

- (long long)longLongValue
{
	RETURN_AS(long long)
}

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

Modified tests/serialization.xml from [173d674534] to [4e889883e6].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    <object>
      <OFString>data</OFString>
    </object>
    <key>
      <OFArray>
        <OFString>Qu&quot;xbar
test</OFString>
        <OFNumber type='signed'>1234</OFNumber>
        <OFNumber type='double'>40934a456d5cfaad</OFNumber>
        <OFMutableString>asd</OFMutableString>
        <OFDate>40934a456d5cfaad</OFDate>
      </OFArray>
    </key>
    <object>
      <OFString>Hello</OFString>







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    <object>
      <OFString>data</OFString>
    </object>
    <key>
      <OFArray>
        <OFString>Qu&quot;xbar
test</OFString>
        <OFNumber type='unsigned'>1234</OFNumber>
        <OFNumber type='double'>40934a456d5cfaad</OFNumber>
        <OFMutableString>asd</OFMutableString>
        <OFDate>40934a456d5cfaad</OFDate>
      </OFArray>
    </key>
    <object>
      <OFString>Hello</OFString>