ObjFW  Diff

Differences From Artifact [7dc3a8f62d]:

To Artifact [109bd47316]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21
22
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#import "OFNumber.h"
#import "OFExceptions.h"


#define RETURN_AS(t)							\
	switch (type) {							\
	case OF_NUMBER_CHAR:						\
		return (t)value.char_;					\
	case OF_NUMBER_SHORT:						\
		return (t)value.short_;					\

|













>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#import "OFNumber.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#define RETURN_AS(t)							\
	switch (type) {							\
	case OF_NUMBER_CHAR:						\
		return (t)value.char_;					\
	case OF_NUMBER_SHORT:						\
		return (t)value.short_;					\
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
	case OF_NUMBER_DOUBLE:						\
		value.double_ o;					\
		break;							\
	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
	}
#define CALCULATE2(o, n)						\
	switch ([n type]) { 						\
	case OF_NUMBER_CHAR:						\
		value.char_ o [n asChar];				\
		break;							\
	case OF_NUMBER_SHORT:						\
		value.short_ o [n asShort];				\
		break;							\
	case OF_NUMBER_INT:						\







|







142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	case OF_NUMBER_DOUBLE:						\
		value.double_ o;					\
		break;							\
	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
	}
#define CALCULATE2(o, n)						\
	switch (type) { 						\
	case OF_NUMBER_CHAR:						\
		value.char_ o [n asChar];				\
		break;							\
	case OF_NUMBER_SHORT:						\
		value.short_ o [n asShort];				\
		break;							\
	case OF_NUMBER_INT:						\
754
755
756
757
758
759
760



















761

762
763
764
765
766
767
768
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
	}
}

- (uint32_t)hash
{



















	return [self asUInt32];

}

- add: (OFNumber*)num
{
	CALCULATE2(+=, num)
	return self;
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







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
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
	}
}

- (uint32_t)hash
{
	uint32_t hash;
	size_t i;

	switch (type) {
	case OF_NUMBER_FLOAT:
		OF_HASH_INIT(hash);
		for (i = 0; i < sizeof(float); i++)
			OF_HASH_ADD(hash, ((char*)&value.float_)[i]);
		OF_HASH_FINALIZE(hash);

		return hash;
	case OF_NUMBER_DOUBLE:
		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];
	}
}

- add: (OFNumber*)num
{
	CALCULATE2(+=, num)
	return self;
}