Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -192,11 +192,11 @@ OFNonretainedObjectValue.m \ OFPointValue.m \ OFPointerValue.m \ OFRangeCharacterSet.m \ OFRangeValue.m \ - OFRectangleValue.m \ + OFRectValue.m \ OFSandbox.m \ OFSizeValue.m \ OFSubarray.m \ OFUTF8String.m \ ${LIBBASES_M} \ Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -130,11 +130,11 @@ + (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`. * Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -235,56 +235,56 @@ 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; } ADDED src/OFRectValue.h Index: src/OFRectValue.h ================================================================== --- src/OFRectValue.h +++ src/OFRectValue.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008-2021 Jonathan Schleifer + * + * 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.QPL included in + * the packaging of this file. + * + * 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 "OFValue.h" + +OF_ASSUME_NONNULL_BEGIN + +@interface OFRectValue: OFValue +{ + OFRect _rect; +} + +- (instancetype)initWithRect: (OFRect)rect; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFRectValue.m Index: src/OFRectValue.m ================================================================== --- src/OFRectValue.m +++ src/OFRectValue.m @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2008-2021 Jonathan Schleifer + * + * 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.QPL included in + * the packaging of this file. + * + * 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 "OFRectValue.h" +#import "OFMethodSignature.h" +#import "OFString.h" + +#import "OFOutOfRangeException.h" + +@implementation OFRectValue +@synthesize rectValue = _rect; + +- (instancetype)initWithRect: (OFRect)rect +{ + self = [super init]; + + _rect = rect; + + return self; +} + +- (const char *)objCType +{ + return @encode(OFRect); +} + +- (void)getValue: (void *)value size: (size_t)size +{ + if (size != sizeof(_rect)) + @throw [OFOutOfRangeException exception]; + + memcpy(value, &_rect, sizeof(_rect)); +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"", + _rect.origin.x, _rect.origin.y, + _rect.size.width, _rect.size.height]; +} +@end DELETED src/OFRectangleValue.h Index: src/OFRectangleValue.h ================================================================== --- src/OFRectangleValue.h +++ src/OFRectangleValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2021 Jonathan Schleifer - * - * 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.QPL included in - * the packaging of this file. - * - * 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 "OFValue.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OFRectangleValue: OFValue -{ - of_rectangle_t _rectangle; -} - -- (instancetype)initWithRectangle: (of_rectangle_t)rectangle; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFRectangleValue.m Index: src/OFRectangleValue.m ================================================================== --- src/OFRectangleValue.m +++ src/OFRectangleValue.m @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2008-2021 Jonathan Schleifer - * - * 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.QPL included in - * the packaging of this file. - * - * 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 "OFMethodSignature.h" -#import "OFString.h" - -#import "OFOutOfRangeException.h" - -@implementation OFRectangleValue -@synthesize rectangleValue = _rectangle; - -- (instancetype)initWithRectangle: (of_rectangle_t)rectangle -{ - self = [super init]; - - _rectangle = rectangle; - - return self; -} - -- (const char *)objCType -{ - return @encode(of_rectangle_t); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_rectangle)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_rectangle, sizeof(_rectangle)); -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", - _rectangle.origin.x, _rectangle.origin.y, - _rectangle.size.width, _rectangle.size.height]; -} -@end Index: src/OFValue.h ================================================================== --- src/OFValue.h +++ src/OFValue.h @@ -66,15 +66,15 @@ * 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. * @@ -133,14 +133,14 @@ /** * @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. * Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -18,11 +18,11 @@ #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" @@ -66,14 +66,13 @@ + (instancetype)valueWithSize: (OFSize)size { return [[[OFSizeValue alloc] initWithSize: size] autorelease]; } -+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle ++ (instancetype)valueWithRect: (OFRect)rect { - return [[[OFRectangleValue alloc] - initWithRectangle: rectangle] autorelease]; + return [[[OFRectValue alloc] initWithRect: rect] autorelease]; } - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { @@ -191,13 +190,13 @@ 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 Index: tests/OFValueTests.m ================================================================== --- tests/OFValueTests.m +++ tests/OFValueTests.m @@ -26,12 +26,11 @@ { 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); - of_rectangle_t rectangle2; + OFRect rect = OFMakeRect(1.5f, 3.0f, 4.5f, 6.0f), rect2; OFValue *value; void *pointer = &value; TEST(@"+[valueWithBytes:objCType:]", (value = [OFValue valueWithBytes: &range @@ -128,37 +127,36 @@ EXPECT_EXCEPTION(@"-[sizeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] sizeValue]) - TEST(@"+[valueWithRectangle:]", - (value = [OFValue valueWithRectangle: rectangle])) - - TEST(@"-[rectangleValue]", - of_rectangle_equal(value.rectangleValue, rectangle) && - (value = [OFValue valueWithBytes: &rectangle - objCType: @encode(of_rectangle_t)]) && - of_rectangle_equal(value.rectangleValue, rectangle)) - - TEST(@"-[getValue:size:] for OFRectangleValue", - (value = [OFValue valueWithRectangle: rectangle]) && - R([value getValue: &rectangle2 size: sizeof(rectangle2)]) && - of_rectangle_equal(rectangle2, rectangle)) - - EXPECT_EXCEPTION(@"-[rectangleValue] with wrong size throws", - OFOutOfRangeException, - [[OFValue valueWithBytes: "a" - objCType: @encode(char)] rectangleValue]) + TEST(@"+[valueWithRect:]", + (value = [OFValue valueWithRect: rect])) + + TEST(@"-[rectValue]", + OFEqualRects(value.rectValue, rect) && + (value = [OFValue valueWithBytes: &rect + objCType: @encode(OFRect)]) && + OFEqualRects(value.rectValue, rect)) + + TEST(@"-[getValue:size:] for OFRectValue", + (value = [OFValue valueWithRect: rect]) && + R([value getValue: &rect2 size: sizeof(rect2)]) && + OFEqualRects(rect2, rect)) + + EXPECT_EXCEPTION(@"-[rectValue] with wrong size throws", + OFOutOfRangeException, + [[OFValue valueWithBytes: "a" objCType: @encode(char)] rectValue]) 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