ObjFW  Diff

Differences From Artifact [ed60df5d2c]:

To Artifact [f907dbb433]:


12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29






























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
12
13
14
15
16
17
18

19
20









21
22
23
24
25
26
27
28
29
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
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







-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+
+
+
+
+
+



-
+







-
-
+
+




-
+
+
+




-
-
+
+




-
+
+




-
+
+




-
+
+




-
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFValue.h"
#import "OFBytesValue.h"
#import "OFConcreteValue.h"
#import "OFMethodSignature.h"
#import "OFNonretainedObjectValue.h"
#import "OFPointValue.h"
#import "OFPointerValue.h"
#import "OFRangeValue.h"
#import "OFRectValue.h"
#import "OFSizeValue.h"
#import "OFString.h"

#import "OFOutOfMemoryException.h"
#import "OFString.h"

#import "OFOutOfMemoryException.h"

static struct {
	Class isa;
} placeholder;

@interface OFPlaceholderValue: OFValue
@end

@implementation OFPlaceholderValue
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	return (id)[[OFConcreteValue alloc] initWithBytes: bytes
						 objCType: objCType];
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif

OF_SINGLETON_METHODS
@end

@implementation OFValue
+ (void)initialize
{
	if (self == [OFValue class])
		object_setClass((id)&placeholder, [OFPlaceholderValue class]);
}

+ (instancetype)alloc
{
	if (self == [OFValue class])
		return [OFBytesValue alloc];
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)valueWithBytes: (const void *)bytes
		      objCType: (const char *)objCType
{
	return [[[OFBytesValue alloc] initWithBytes: bytes
					   objCType: objCType] autorelease];
	return [[[OFValue alloc] initWithBytes: bytes
				      objCType: objCType] autorelease];
}

+ (instancetype)valueWithPointer: (const void *)pointer
{
	return [[[OFPointerValue alloc] initWithPointer: pointer] autorelease];
	return [[[OFValue alloc]
	    initWithBytes: &pointer
		 objCType: @encode(const void *)] autorelease];
}

+ (instancetype)valueWithNonretainedObject: (id)object
{
	return [[[OFNonretainedObjectValue alloc]
	    initWithNonretainedObject: object] autorelease];
	return [[[OFValue alloc] initWithBytes: &object
				      objCType: @encode(id)] autorelease];
}

+ (instancetype)valueWithRange: (OFRange)range
{
	return [[[OFRangeValue alloc] initWithRange: range] autorelease];
	return [[[OFValue alloc] initWithBytes: &range
				      objCType: @encode(OFRange)] autorelease];
}

+ (instancetype)valueWithPoint: (OFPoint)point
{
	return [[[OFPointValue alloc] initWithPoint: point] autorelease];
	return [[[OFValue alloc] initWithBytes: &point
				      objCType: @encode(OFPoint)] autorelease];
}

+ (instancetype)valueWithSize: (OFSize)size
{
	return [[[OFSizeValue alloc] initWithSize: size] autorelease];
	return [[[OFValue alloc] initWithBytes: &size
				      objCType: @encode(OFSize)] autorelease];
}

+ (instancetype)valueWithRect: (OFRect)rect
{
	return [[[OFRectValue alloc] initWithRect: rect] autorelease];
	return [[[OFValue alloc] initWithBytes: &rect
				      objCType: @encode(OFRect)] autorelease];
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	if ([self isMemberOfClass: [OFValue class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}

		abort();
	}

	return [super init];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (bool)isEqual: (id)object
{
	const char *objCType;