ObjFW  Diff

Differences From Artifact [c13a2ddb4a]:

To Artifact [c9cabca4f9]:


339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
		return [OFNumber numberWithDouble: _value.double_ o];	\
	default:							\
		@throw [OFInvalidFormatException			\
		    exceptionWithClass: [self class]];			\
	}

@implementation OFNumber
+ (instancetype)numberWithBool: (BOOL)bool_
{
	return [[[self alloc] initWithBool: bool_] autorelease];
}

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







|







339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
		return [OFNumber numberWithDouble: _value.double_ o];	\
	default:							\
		@throw [OFInvalidFormatException			\
		    exceptionWithClass: [self class]];			\
	}

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

+ (instancetype)numberWithChar: (signed char)schar
{
	return [[[self alloc] initWithChar: schar] autorelease];
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
		[self release];
		@throw e;
	}

	abort();
}

- initWithBool: (BOOL)bool_
{
	self = [super init];

	_value.bool_ = (bool_ ? YES : NO);
	_type = OF_NUMBER_BOOL;

	return self;
}

- initWithChar: (signed char)schar
{







|



|







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
		[self release];
		@throw e;
	}

	abort();
}

- initWithBool: (bool)bool_
{
	self = [super init];

	_value.bool_ = bool_;
	_type = OF_NUMBER_BOOL;

	return self;
}

- initWithChar: (signed char)schar
{
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
				      selector: _cmd];

		typeString = [[element attributeForName: @"type"] stringValue];

		if ([typeString isEqual: @"boolean"]) {
			_type = OF_NUMBER_BOOL;

			if ([[element stringValue] isEqual: @"YES"])
				_value.bool_ = YES;
			else if ([[element stringValue] isEqual: @"NO"])
				_value.bool_ = NO;
			else
				@throw [OFInvalidArgumentException
				    exceptionWithClass: [self class]
					      selector: _cmd];
		} else if ([typeString isEqual: @"unsigned"]) {
			/*
			 * FIXME: This will fail if the value is bigger than







|
|
|
|







790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
				      selector: _cmd];

		typeString = [[element attributeForName: @"type"] stringValue];

		if ([typeString isEqual: @"boolean"]) {
			_type = OF_NUMBER_BOOL;

			if ([[element stringValue] isEqual: @"true"])
				_value.bool_ = true;
			else if ([[element stringValue] isEqual: @"false"])
				_value.bool_ = false;
			else
				@throw [OFInvalidArgumentException
				    exceptionWithClass: [self class]
					      selector: _cmd];
		} else if ([typeString isEqual: @"unsigned"]) {
			/*
			 * FIXME: This will fail if the value is bigger than
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
}

- (of_number_type_t)type
{
	return _type;
}

- (BOOL)boolValue
{
	switch (_type) {
	case OF_NUMBER_BOOL:
		return !!_value.bool_;
	case OF_NUMBER_CHAR:
		return !!_value.schar;
	case OF_NUMBER_SHORT:
		return !!_value.sshort;
	case OF_NUMBER_INT:
		return !!_value.sint;
	case OF_NUMBER_LONG:
		return !!_value.slong;
	case OF_NUMBER_LONGLONG:
		return !!_value.slonglong;
	case OF_NUMBER_UCHAR:
		return !!_value.uchar;
	case OF_NUMBER_USHORT:
		return !!_value.ushort;
	case OF_NUMBER_UINT:
		return !!_value.uint;
	case OF_NUMBER_ULONG:
		return !!_value.ulong;
	case OF_NUMBER_ULONGLONG:
		return !!_value.ulonglong;
	case OF_NUMBER_INT8:
		return !!_value.int8;
	case OF_NUMBER_INT16:
		return !!_value.int16;
	case OF_NUMBER_INT32:
		return !!_value.int32;
	case OF_NUMBER_INT64:
		return !!_value.int64;
	case OF_NUMBER_UINT8:
		return !!_value.uint8;
	case OF_NUMBER_UINT16:
		return !!_value.uint16;
	case OF_NUMBER_UINT32:
		return !!_value.uint32;
	case OF_NUMBER_UINT64:
		return !!_value.uint64;
	case OF_NUMBER_SIZE:
		return !!_value.size;
	case OF_NUMBER_SSIZE:
		return !!_value.ssize;
	case OF_NUMBER_INTMAX:
		return !!_value.intmax;
	case OF_NUMBER_UINTMAX:
		return !!_value.uintmax;
	case OF_NUMBER_PTRDIFF:
		return !!_value.ptrdiff;
	case OF_NUMBER_INTPTR:
		return !!_value.intptr;
	case OF_NUMBER_UINTPTR:
		return !!_value.uintptr;
	case OF_NUMBER_FLOAT:
		return !!_value.float_;
	case OF_NUMBER_DOUBLE:
		return !!_value.double_;
	default:
		@throw [OFInvalidFormatException
		    exceptionWithClass: [self class]];
	}
}

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








|

<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







847
848
849
850
851
852
853
854
855


856


























































857
858
859
860
861
862
863
}

- (of_number_type_t)type
{
	return _type;
}

- (bool)boolValue
{


	RETURN_AS(bool)


























































}

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

1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
}

- (double)doubleValue
{
	RETURN_AS(double)
}

- (BOOL)isEqual: (id)object
{
	OFNumber *number;

	if (![object isKindOfClass: [OFNumber class]])
		return NO;

	number = object;

	if (_type & OF_NUMBER_FLOAT || number->_type & OF_NUMBER_FLOAT)
		return ([number doubleValue] == [self doubleValue]);

	if (_type & OF_NUMBER_SIGNED || number->_type & OF_NUMBER_SIGNED)







|




|







987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
}

- (double)doubleValue
{
	RETURN_AS(double)
}

- (bool)isEqual: (id)object
{
	OFNumber *number;

	if (![object isKindOfClass: [OFNumber class]])
		return false;

	number = object;

	if (_type & OF_NUMBER_FLOAT || number->_type & OF_NUMBER_FLOAT)
		return ([number doubleValue] == [self doubleValue]);

	if (_type & OF_NUMBER_SIGNED || number->_type & OF_NUMBER_SIGNED)
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343

- (OFString*)description
{
	OFMutableString *ret;

	switch (_type) {
	case OF_NUMBER_BOOL:
		return (_value.bool_ ? @"YES" : @"NO");
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:
	case OF_NUMBER_ULONGLONG:
	case OF_NUMBER_UINT8:
	case OF_NUMBER_UINT16:







|







1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283

- (OFString*)description
{
	OFMutableString *ret;

	switch (_type) {
	case OF_NUMBER_BOOL:
		return (_value.bool_ ? @"true" : @"false");
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:
	case OF_NUMBER_ULONGLONG:
	case OF_NUMBER_UINT8:
	case OF_NUMBER_UINT16: