ObjFW  Check-in [e41940c022]

Overview
Comment:Simplify OFValue
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e41940c022a90ea557f5af6e493df81493a03e20d8bcbcff20b5313f9afb7d60
User & Date: js on 2021-04-13 21:43:42
Other Links: manifest | tags
Context
2021-04-17
00:57
OFNumber: Remove useless OF_UNAVAILABLE check-in: 27002f2efe user: js tags: trunk
00:14
of_comparison_result_t -> OFComparisonResult check-in: 61fc389aee user: js tags: new-naming-convention
2021-04-13
21:43
Simplify OFValue check-in: e41940c022 user: js tags: trunk
2021-04-09
01:28
Split XML processing instructions into target/data check-in: d4b3f8ea70 user: js tags: trunk
Changes

Modified src/OFDimensionValue.h from [f7a2f0822f] to [1e5243cb9c].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFDimensionValue: OFValue
{
	of_dimension_t _dimension;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFDimensionValue: OFValue
{
	of_dimension_t _dimension;
}

- (instancetype)initWithDimension: (of_dimension_t)dimension;
@end

OF_ASSUME_NONNULL_END

Modified src/OFNonretainedObjectValue.h from [324b0e8add] to [2e9ab2769c].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFNonretainedObjectValue: OFValue
{
	id _object;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFNonretainedObjectValue: OFValue
{
	id _object;
}

- (instancetype)initWithNonretainedObject: (id)object;
@end

OF_ASSUME_NONNULL_END

Modified src/OFPointValue.h from [a55ded17fa] to [8f405bc77c].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFPointValue: OFValue
{
	of_point_t _point;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFPointValue: OFValue
{
	of_point_t _point;
}

- (instancetype)initWithPoint: (of_point_t)point;
@end

OF_ASSUME_NONNULL_END

Modified src/OFPointerValue.h from [83e44d9bb8] to [76806b79ee].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFPointerValue: OFValue
{
	void *_pointer;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFPointerValue: OFValue
{
	void *_pointer;
}

- (instancetype)initWithPointer: (const void *)pointer;
@end

OF_ASSUME_NONNULL_END

Modified src/OFRangeValue.h from [a296ed91e7] to [d625b84e6d].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFRangeValue: OFValue
{
	of_range_t _range;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFRangeValue: OFValue
{
	of_range_t _range;
}

- (instancetype)initWithRange: (of_range_t)range;
@end

OF_ASSUME_NONNULL_END

Modified src/OFRectangleValue.h from [e2767981ab] to [6cb58bb467].

17
18
19
20
21
22
23


24
25
26

OF_ASSUME_NONNULL_BEGIN

@interface OFRectangleValue: OFValue
{
	of_rectangle_t _rectangle;
}


@end

OF_ASSUME_NONNULL_END







>
>



17
18
19
20
21
22
23
24
25
26
27
28

OF_ASSUME_NONNULL_BEGIN

@interface OFRectangleValue: OFValue
{
	of_rectangle_t _rectangle;
}

- (instancetype)initWithRectangle: (of_rectangle_t)rectangle;
@end

OF_ASSUME_NONNULL_END

Modified src/OFValue.h from [7e6204d34f] to [938b5927a6].

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
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return An initialized OFValue
 */
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  pointer.
 *
 * Only the raw value of the pointer is stored and no data will be copied.
 *
 * @param pointer The pointer the OFValue should contain
 * @return An initialized OFValue
 */
- (instancetype)initWithPointer: (const void *)pointer;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  non-retained object.
 *
 * The object is not retained, which makes this useful for storing objects in
 * collections without retaining them.
 *
 * @param object The object the OFValue should contain without retaining it
 * @return An initialized OFValue
 */
- (instancetype)initWithNonretainedObject: (id)object;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  range.
 *
 * @param range The range the OFValue should contain
 * @return An initialized OFValue
 */
- (instancetype)initWithRange: (of_range_t)range;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  point.
 *
 * @param point The point the OFValue should contain
 * @return An initialized OFValue
 */
- (instancetype)initWithPoint: (of_point_t)point;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  dimension.
 *
 * @param dimension The dimension the OFValue should contain
 * @return An initialized OFValue
 */
- (instancetype)initWithDimension: (of_dimension_t)dimension;

/**
 * @brief Initializes an already allocated OFValue containing the specified
 *	  rectangle.
 *
 * @param rectangle The rectangle the OFValue should contain
 * @return An initialized OFValue
 */
- (instancetype)initWithRectangle: (of_rectangle_t)rectangle;

/**
 * @brief Gets the value.
 *
 * If the specified size does not match, this raises an
 * @ref OFOutOfRangeException.
 *
 * @param value The buffer to copy the value into







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







148
149
150
151
152
153
154



























































155
156
157
158
159
160
161
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return An initialized OFValue
 */
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType;




























































/**
 * @brief Gets the value.
 *
 * If the specified size does not match, this raises an
 * @ref OFOutOfRangeException.
 *
 * @param value The buffer to copy the value into

Modified src/OFValue.m from [0c9f7f6c34] to [57c5a42ed5].

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
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
#import "OFPointerValue.h"
#import "OFRangeValue.h"
#import "OFRectangleValue.h"
#import "OFString.h"

#import "OFOutOfMemoryException.h"

static struct {
	Class isa;
} placeholder;

@interface OFValuePlaceholder: OFValue
@end

@implementation OFValuePlaceholder
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	return (id)[[OFBytesValue alloc] initWithBytes: bytes
					      objCType: objCType];
}

- (instancetype)initWithPointer: (const void *)pointer
{
	return (id)[[OFPointerValue alloc] initWithPointer: pointer];
}

- (instancetype)initWithNonretainedObject: (id)object
{
	return (id)[[OFNonretainedObjectValue alloc]
	    initWithNonretainedObject: object];
}

- (instancetype)initWithRange: (of_range_t)range
{
	return (id)[[OFRangeValue alloc] initWithRange: range];
}

- (instancetype)initWithPoint: (of_point_t)point
{
	return (id)[[OFPointValue alloc] initWithPoint: point];
}

- (instancetype)initWithDimension: (of_dimension_t)dimension
{
	return (id)[[OFDimensionValue alloc] initWithDimension: dimension];
}

- (instancetype)initWithRectangle: (of_rectangle_t)rectangle
{
	return (id)[[OFRectangleValue alloc] initWithRectangle: rectangle];
}
@end

@implementation OFValue
+ (void)initialize
{
	if (self == [OFValue class])
		placeholder.isa = [OFValuePlaceholder class];
}

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

	return [super alloc];
}

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

+ (instancetype)valueWithPointer: (const void *)pointer
{
	return [[[self alloc] initWithPointer: pointer] autorelease];
}

+ (instancetype)valueWithNonretainedObject: (id)object
{

	return [[[self alloc] initWithNonretainedObject: object] autorelease];
}

+ (instancetype)valueWithRange: (of_range_t)range
{
	return [[[self alloc] initWithRange: range] autorelease];
}

+ (instancetype)valueWithPoint: (of_point_t)point
{
	return [[[self alloc] initWithPoint: point] autorelease];
}

+ (instancetype)valueWithDimension: (of_dimension_t)dimension
{

	return [[[self alloc] initWithDimension: dimension] autorelease];
}

+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle
{

	return [[[self alloc] initWithRectangle: rectangle] autorelease];
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPointer: (const void *)pointer
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithNonretainedObject: (id)object
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithRange: (of_range_t)range
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPoint: (of_point_t)point
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithDimension: (of_dimension_t)dimension
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithRectangle: (of_rectangle_t)rectangle
{
	OF_INVALID_INIT_METHOD
}

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







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
<
<
<
<



|







|
|




|




>
|




|




|




>
|




>
|





<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
#import "OFPointerValue.h"
#import "OFRangeValue.h"
#import "OFRectangleValue.h"
#import "OFString.h"

#import "OFOutOfMemoryException.h"
















































@implementation OFValue






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

	return [super alloc];
}

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

+ (instancetype)valueWithPointer: (const void *)pointer
{
	return [[[OFPointerValue alloc] initWithPointer: pointer] autorelease];
}

+ (instancetype)valueWithNonretainedObject: (id)object
{
	return [[[OFNonretainedObjectValue alloc]
	    initWithNonretainedObject: object] autorelease];
}

+ (instancetype)valueWithRange: (of_range_t)range
{
	return [[[OFRangeValue alloc] initWithRange: range] autorelease];
}

+ (instancetype)valueWithPoint: (of_point_t)point
{
	return [[[OFPointValue alloc] initWithPoint: point] autorelease];
}

+ (instancetype)valueWithDimension: (of_dimension_t)dimension
{
	return [[[OFDimensionValue alloc]
	    initWithDimension: dimension] autorelease];
}

+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle
{
	return [[[OFRectangleValue alloc]
	    initWithRectangle: rectangle] autorelease];
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{






























	OF_INVALID_INIT_METHOD
}

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