ObjFW  Check-in [dec9721b35]

Overview
Comment:of_rectangle_t -> OFRect
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | new-naming-convention
Files: files | file ages | folders
SHA3-256: dec9721b359528ea7e6689a2bafc3c59654767f3b3c8e74b3c26849400de46cc
User & Date: js on 2021-04-17 01:19:44
Other Links: branch diff | manifest | tags
Context
2021-04-17
01:24
OF_NOT_FOUND -> OFNotFound check-in: 83dc0fe6e5 user: js tags: new-naming-convention
01:19
of_rectangle_t -> OFRect check-in: dec9721b35 user: js tags: new-naming-convention
01:10
of_dimension_t -> OFSize check-in: 8a7353b219 user: js tags: new-naming-convention
Changes

Modified src/Makefile from [dbf0faa04b] to [45115139e9].

190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







-
+







	OFMutableMapTableSet.m		\
	OFMutableUTF8String.m		\
	OFNonretainedObjectValue.m	\
	OFPointValue.m			\
	OFPointerValue.m		\
	OFRangeCharacterSet.m		\
	OFRangeValue.m			\
	OFRectangleValue.m		\
	OFRectValue.m			\
	OFSandbox.m			\
	OFSizeValue.m			\
	OFSubarray.m			\
	OFUTF8String.m			\
	${LIBBASES_M}			\
	${RUNTIME_AUTORELEASE_M}	\
	${RUNTIME_INSTANCE_M}

Modified src/OFNumber.h from [c1e91a3a26] to [6fc4bc7a5d].

128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142







-
+







+ (instancetype)valueWithBytes: (const void *)bytes
		      objCType: (const char *)objCType OF_UNAVAILABLE;
+ (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE;
+ (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE;
+ (instancetype)valueWithRange: (OFRange)range OF_UNAVAILABLE;
+ (instancetype)valueWithPoint: (OFPoint)point OF_UNAVAILABLE;
+ (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE;
+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE;
+ (instancetype)valueWithRect: (OFRect)rect OF_UNAVAILABLE;
#endif

/**
 * @brief Creates a new OFNumber with the specified `bool`.
 *
 * @param value The `bool` value which the OFNumber should contain
 * @return A new autoreleased OFNumber

Modified src/OFObject.h from [43c18460ed] to [ad55e4debc].

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
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







-
+



-
+





-
+


-
+





-
+

-
-
+
+

-
+




-
+





-
-
+
+



-
+

-
+


-
+







	if (size1.height != size2.height)
		return false;

	return true;
}

/**
 * @struct of_rectangle_t OFObject.h ObjFW/OFObject.h
 * @struct OFRect OFObject.h ObjFW/OFObject.h
 *
 * @brief A rectangle.
 */
struct OF_BOXABLE of_rectangle_t {
struct OF_BOXABLE OFRect {
	/** The point from where the rectangle originates */
	OFPoint origin;
	/** The size of the rectangle */
	OFSize size;
};
typedef struct of_rectangle_t of_rectangle_t;
typedef struct OFRect OFRect;

/**
 * @brief Creates a new of_rectangle_t.
 * @brief Creates a new OFRect.
 *
 * @param x The x coordinate of the top left corner of the rectangle
 * @param y The y coordinate of the top left corner of the rectangle
 * @param width The width of the rectangle
 * @param height The height of the rectangle
 * @return An of_rectangle_t with the specified origin and size
 * @return An OFRect with the specified origin and size
 */
static OF_INLINE of_rectangle_t OF_CONST_FUNC
of_rectangle(float x, float y, float width, float height)
static OF_INLINE OFRect OF_CONST_FUNC
OFMakeRect(float x, float y, float width, float height)
{
	of_rectangle_t rectangle = {
	OFRect rect = {
		OFMakePoint(x, y),
		OFMakeSize(width, height)
	};

	return rectangle;
	return rect;
}

/**
 * @brief Returns whether the two rectangles are equal.
 *
 * @param rectangle1 The first rectangle for the comparison
 * @param rectangle2 The second rectangle for the comparison
 * @param rect1 The first rectangle for the comparison
 * @param rect2 The second rectangle for the comparison
 * @return Whether the two rectangles are equal
 */
static OF_INLINE bool
of_rectangle_equal(of_rectangle_t rectangle1, of_rectangle_t rectangle2)
OFEqualRects(OFRect rect1, OFRect rect2)
{
	if (!OFEqualPoints(rectangle1.origin, rectangle2.origin))
	if (!OFEqualPoints(rect1.origin, rect2.origin))
		return false;

	if (!OFEqualSizes(rectangle1.size, rectangle2.size))
	if (!OFEqualSizes(rect1.size, rect2.size))
		return false;

	return true;
}

#ifdef __OBJC__
@class OFMethodSignature;

Renamed and modified src/OFRectangleValue.h [6cb58bb467] to src/OFRectValue.h [57204033f6].

13
14
15
16
17
18
19
20

21
22

23
24
25

26
27
28
13
14
15
16
17
18
19

20
21

22
23
24

25
26
27
28







-
+

-
+


-
+



 * file.
 */

#import "OFValue.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFRectangleValue: OFValue
@interface OFRectValue: OFValue
{
	of_rectangle_t _rectangle;
	OFRect _rect;
}

- (instancetype)initWithRectangle: (of_rectangle_t)rectangle;
- (instancetype)initWithRect: (OFRect)rect;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/OFRectangleValue.m [7e7907dbd9] to src/OFRectValue.m [15e6c7cc85].

9
10
11
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
9
10
11
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







-
+





-
-
+
+

-
+



-
+






-
+




-
+


-
+





-
-
-
+
+
+


 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFRectangleValue.h"
#import "OFRectValue.h"
#import "OFMethodSignature.h"
#import "OFString.h"

#import "OFOutOfRangeException.h"

@implementation OFRectangleValue
@synthesize rectangleValue = _rectangle;
@implementation OFRectValue
@synthesize rectValue = _rect;

- (instancetype)initWithRectangle: (of_rectangle_t)rectangle
- (instancetype)initWithRect: (OFRect)rect
{
	self = [super init];

	_rectangle = rectangle;
	_rect = rect;

	return self;
}

- (const char *)objCType
{
	return @encode(of_rectangle_t);
	return @encode(OFRect);
}

- (void)getValue: (void *)value size: (size_t)size
{
	if (size != sizeof(_rectangle))
	if (size != sizeof(_rect))
		@throw [OFOutOfRangeException exception];

	memcpy(value, &_rectangle, sizeof(_rectangle));
	memcpy(value, &_rect, sizeof(_rect));
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"<OFValue: of_rectangle_t { %f, %f, %f, %f }>",
	    _rectangle.origin.x, _rectangle.origin.y,
	    _rectangle.size.width, _rectangle.size.height];
	    @"<OFValue: OFRect { %f, %f, %f, %f }>",
	    _rect.origin.x, _rect.origin.y,
	    _rect.size.width, _rect.size.height];
}
@end

Modified src/OFValue.h from [2987cd37b8] to [df3acd707a].

64
65
66
67
68
69
70
71

72
73

74
75

76
77
78
79
80
81
82
64
65
66
67
68
69
70

71
72

73
74

75
76
77
78
79
80
81
82







-
+

-
+

-
+







 * @brief The value as an OFSize.
 *
 * If the value is not OFSize-sized, @ref OFOutOfRangeException is thrown.
 */
@property (readonly, nonatomic) OFSize sizeValue;

/**
 * @brief The value as a rectangle.
 * @brief The value as a OFRect.
 *
 * If the value is not rectangle-sized, @ref OFOutOfRangeException is thrown.
 * If the value is not OFRect-sized, @ref OFOutOfRangeException is thrown.
 */
@property (readonly, nonatomic) of_rectangle_t rectangleValue;
@property (readonly, nonatomic) OFRect rectValue;

/**
 * @brief Creates a new, autorelease OFValue with the specified bytes of the
 *	  specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
131
132
133
134
135
136
137
138

139
140
141

142
143
144
145
146
147
148
131
132
133
134
135
136
137

138
139
140

141
142
143
144
145
146
147
148







-
+


-
+







 */
+ (instancetype)valueWithSize: (OFSize)size;

/**
 * @brief Creates a new, autoreleased OFValue containing the specified
 *	  rectangle.
 *
 * @param rectangle The rectangle the OFValue should contain
 * @param rect The rectangle the OFValue should contain
 * @return A new, autoreleased OFValue
 */
+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle;
+ (instancetype)valueWithRect: (OFRect)rect;

/**
 * @brief Initializes an already allocated OFValue with the specified bytes of
 *	  the specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value

Modified src/OFValue.m from [c62f9e27d2] to [712005bdcf].

16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30







-
+







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

#import "OFOutOfMemoryException.h"

@implementation OFValue
+ (instancetype)alloc
64
65
66
67
68
69
70
71

72
73

74
75
76
77
78
79
80
81
64
65
66
67
68
69
70

71
72

73

74
75
76
77
78
79
80







-
+

-
+
-







}

+ (instancetype)valueWithSize: (OFSize)size
{
	return [[[OFSizeValue alloc] initWithSize: size] autorelease];
}

+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle
+ (instancetype)valueWithRect: (OFRect)rect
{
	return [[[OFRectangleValue alloc]
	return [[[OFRectValue alloc] initWithRect: rect] autorelease];
	    initWithRectangle: rectangle] autorelease];
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	OF_INVALID_INIT_METHOD
}
189
190
191
192
193
194
195
196

197
198

199
200
201
202
203
204
205
188
189
190
191
192
193
194

195
196

197
198
199
200
201
202
203
204







-
+

-
+







- (OFSize)sizeValue
{
	OFSize ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}

- (of_rectangle_t)rectangleValue
- (OFRect)rectValue
{
	of_rectangle_t ret;
	OFRect ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}

- (OFString *)description
{
	OFMutableString *ret =

Modified tests/OFValueTests.m from [30f9ae95fb] to [8235c5a687].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
24
25
26
27
28
29
30

31

32
33
34
35
36
37
38







-
+
-







@implementation TestsAppDelegate (OFValueTests)
- (void)valueTests
{
	void *pool = objc_autoreleasePoolPush();
	OFRange range = OFMakeRange(1, 64), range2;
	OFPoint point = OFMakePoint(1.5f, 3.0f), point2;
	OFSize size = OFMakeSize(4.5f, 5.0f), size2;
	of_rectangle_t rectangle = of_rectangle(1.5f, 3.0f, 4.5f, 6.0f);
	OFRect rect = OFMakeRect(1.5f, 3.0f, 4.5f, 6.0f), rect2;
	of_rectangle_t rectangle2;
	OFValue *value;
	void *pointer = &value;

	TEST(@"+[valueWithBytes:objCType:]",
	    (value = [OFValue valueWithBytes: &range
				    objCType: @encode(OFRange)]))

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
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







-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
+
+
+
+

-
+

-
+
-


-
-
-
+
+
+









	    OFEqualSizes(size2, size))

	EXPECT_EXCEPTION(@"-[sizeValue] with wrong size throws",
	    OFOutOfRangeException,
	    [[OFValue valueWithBytes: "a"
			    objCType: @encode(char)] sizeValue])

	TEST(@"+[valueWithRectangle:]",
	    (value = [OFValue valueWithRectangle: rectangle]))
	TEST(@"+[valueWithRect:]",
	    (value = [OFValue valueWithRect: rect]))

	TEST(@"-[rectangleValue]",
	    of_rectangle_equal(value.rectangleValue, rectangle) &&
	    (value = [OFValue valueWithBytes: &rectangle
				    objCType: @encode(of_rectangle_t)]) &&
	    of_rectangle_equal(value.rectangleValue, rectangle))
	TEST(@"-[rectValue]",
	    OFEqualRects(value.rectValue, rect) &&
	    (value = [OFValue valueWithBytes: &rect
				    objCType: @encode(OFRect)]) &&
	    OFEqualRects(value.rectValue, rect))

	TEST(@"-[getValue:size:] for OFRectangleValue",
	    (value = [OFValue valueWithRectangle: rectangle]) &&
	    R([value getValue: &rectangle2 size: sizeof(rectangle2)]) &&
	    of_rectangle_equal(rectangle2, rectangle))
	TEST(@"-[getValue:size:] for OFRectValue",
	    (value = [OFValue valueWithRect: rect]) &&
	    R([value getValue: &rect2 size: sizeof(rect2)]) &&
	    OFEqualRects(rect2, rect))

	EXPECT_EXCEPTION(@"-[rectangleValue] with wrong size throws",
	EXPECT_EXCEPTION(@"-[rectValue] with wrong size throws",
	    OFOutOfRangeException,
	    [[OFValue valueWithBytes: "a"
	    [[OFValue valueWithBytes: "a" objCType: @encode(char)] rectValue])
			    objCType: @encode(char)] rectangleValue])

	TEST(@"-[isEqual:]",
	    [[OFValue valueWithRectangle: rectangle]
	    isEqual: [OFValue valueWithBytes: &rectangle
				    objCType: @encode(of_rectangle_t)]] &&
	    [[OFValue valueWithRect: rect]
	    isEqual: [OFValue valueWithBytes: &rect
				    objCType: @encode(OFRect)]] &&
	    ![[OFValue valueWithBytes: "a" objCType: @encode(signed char)]
	    isEqual: [OFValue valueWithBytes: "a"
				    objCType: @encode(unsigned char)]] &&
	    ![[OFValue valueWithBytes: "a" objCType: @encode(char)]
	    isEqual: [OFValue valueWithBytes: "b" objCType: @encode(char)]])

	objc_autoreleasePoolPop(pool);
}
@end