Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -179,11 +179,10 @@ SRCS += OFAdjacentArray.m \ OFAdjacentSubarray.m \ OFBitSetCharacterSet.m \ OFBytesValue.m \ OFCountedMapTableSet.m \ - OFDimensionValue.m \ OFInvertedCharacterSet.m \ OFLHADecompressingStream.m \ OFMapTableDictionary.m \ OFMapTableSet.m \ OFMutableAdjacentArray.m \ @@ -195,10 +194,11 @@ OFPointerValue.m \ OFRangeCharacterSet.m \ OFRangeValue.m \ OFRectangleValue.m \ OFSandbox.m \ + OFSizeValue.m \ OFSubarray.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} DELETED src/OFDimensionValue.h Index: src/OFDimensionValue.h ================================================================== --- src/OFDimensionValue.h +++ src/OFDimensionValue.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 OFDimensionValue: OFValue -{ - of_dimension_t _dimension; -} - -- (instancetype)initWithDimension: (of_dimension_t)dimension; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFDimensionValue.m Index: src/OFDimensionValue.m ================================================================== --- src/OFDimensionValue.m +++ src/OFDimensionValue.m @@ -1,53 +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 "OFDimensionValue.h" -#import "OFMethodSignature.h" -#import "OFString.h" - -#import "OFOutOfRangeException.h" - -@implementation OFDimensionValue -@synthesize dimensionValue = _dimension; - -- (instancetype)initWithDimension: (of_dimension_t)dimension -{ - self = [super init]; - - _dimension = dimension; - - return self; -} - -- (const char *)objCType -{ - return @encode(of_dimension_t); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_dimension)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_dimension, sizeof(_dimension)); -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", - _dimension.width, _dimension.height]; -} -@end Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -129,11 +129,11 @@ 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)valueWithDimension: (of_dimension_t)dimension OF_UNAVAILABLE; ++ (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE; + (instancetype)valueWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE; #endif /** * @brief Creates a new OFNumber with the specified `bool`. Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -188,51 +188,51 @@ return true; } /** - * @struct of_dimension_t OFObject.h ObjFW/OFObject.h - * - * @brief A dimension. - */ -struct OF_BOXABLE of_dimension_t { - /** The width of the dimension */ - float width; - /** The height of the dimension */ - float height; -}; -typedef struct of_dimension_t of_dimension_t; - -/** - * @brief Creates a new of_dimension_t. - * - * @param width The width of the dimension - * @param height The height of the dimension - * @return An of_dimension_t with the specified width and height - */ -static OF_INLINE of_dimension_t OF_CONST_FUNC -of_dimension(float width, float height) -{ - of_dimension_t dimension = { width, height }; - - return dimension; -} - -/** - * @brief Returns whether the two dimensions are equal. - * - * @param dimension1 The first dimension for the comparison - * @param dimension2 The second dimension for the comparison - * @return Whether the two dimensions are equal - */ -static OF_INLINE bool -of_dimension_equal(of_dimension_t dimension1, of_dimension_t dimension2) -{ - if (dimension1.width != dimension2.width) - return false; - - if (dimension1.height != dimension2.height) + * @struct OFSize OFObject.h ObjFW/OFObject.h + * + * @brief A size. + */ +struct OF_BOXABLE OFSize { + /** The width of the size */ + float width; + /** The height of the size */ + float height; +}; +typedef struct OFSize OFSize; + +/** + * @brief Creates a new OFSize. + * + * @param width The width of the size + * @param height The height of the size + * @return An OFSize with the specified width and height + */ +static OF_INLINE OFSize OF_CONST_FUNC +OFMakeSize(float width, float height) +{ + OFSize size = { width, height }; + + return size; +} + +/** + * @brief Returns whether the two sizes are equal. + * + * @param size1 The first size for the comparison + * @param size2 The second size for the comparison + * @return Whether the two sizes are equal + */ +static OF_INLINE bool +OFEqualSizes(OFSize size1, OFSize size2) +{ + if (size1.width != size2.width) + return false; + + if (size1.height != size2.height) return false; return true; } @@ -243,11 +243,11 @@ */ struct OF_BOXABLE of_rectangle_t { /** The point from where the rectangle originates */ OFPoint origin; /** The size of the rectangle */ - of_dimension_t size; + OFSize size; }; typedef struct of_rectangle_t of_rectangle_t; /** * @brief Creates a new of_rectangle_t. @@ -261,11 +261,11 @@ static OF_INLINE of_rectangle_t OF_CONST_FUNC of_rectangle(float x, float y, float width, float height) { of_rectangle_t rectangle = { OFMakePoint(x, y), - of_dimension(width, height) + OFMakeSize(width, height) }; return rectangle; } @@ -280,11 +280,11 @@ of_rectangle_equal(of_rectangle_t rectangle1, of_rectangle_t rectangle2) { if (!OFEqualPoints(rectangle1.origin, rectangle2.origin)) return false; - if (!of_dimension_equal(rectangle1.size, rectangle2.size)) + if (!OFEqualSizes(rectangle1.size, rectangle2.size)) return false; return true; } ADDED src/OFSizeValue.h Index: src/OFSizeValue.h ================================================================== --- src/OFSizeValue.h +++ src/OFSizeValue.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 OFSizeValue: OFValue +{ + OFSize _size; +} + +- (instancetype)initWithSize: (OFSize)size; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFSizeValue.m Index: src/OFSizeValue.m ================================================================== --- src/OFSizeValue.m +++ src/OFSizeValue.m @@ -0,0 +1,52 @@ +/* + * 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 "OFSizeValue.h" +#import "OFMethodSignature.h" +#import "OFString.h" + +#import "OFOutOfRangeException.h" + +@implementation OFSizeValue +@synthesize sizeValue = _size; + +- (instancetype)initWithSize: (OFSize)size +{ + self = [super init]; + + _size = size; + + return self; +} + +- (const char *)objCType +{ + return @encode(OFSize); +} + +- (void)getValue: (void *)value size: (size_t)size +{ + if (size != sizeof(_size)) + @throw [OFOutOfRangeException exception]; + + memcpy(value, &_size, sizeof(_size)); +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"", _size.width, _size.height]; +} +@end Index: src/OFValue.h ================================================================== --- src/OFValue.h +++ src/OFValue.h @@ -45,29 +45,29 @@ * If the value is not pointer-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) id nonretainedObjectValue; /** - * @brief The value as a range. + * @brief The value as an OFRange. * - * If the value is not range-sized, @ref OFOutOfRangeException is thrown. + * If the value is not OFRange-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFRange rangeValue; /** - * @brief The value as a point. + * @brief The value as an OFPoint. * - * If the value is not point-sized, @ref OFOutOfRangeException is thrown. + * If the value is not OFPoint-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFPoint pointValue; /** - * @brief The value as a dimension. + * @brief The value as an OFSize. * - * If the value is not dimension-sized, @ref OFOutOfRangeException is thrown. + * If the value is not OFSize-sized, @ref OFOutOfRangeException is thrown. */ -@property (readonly, nonatomic) of_dimension_t dimensionValue; +@property (readonly, nonatomic) OFSize sizeValue; /** * @brief The value as a rectangle. * * If the value is not rectangle-sized, @ref OFOutOfRangeException is thrown. @@ -122,17 +122,16 @@ * @return A new, autoreleased OFValue */ + (instancetype)valueWithPoint: (OFPoint)point; /** - * @brief Creates a new, autoreleased OFValue containing the specified - * dimension. + * @brief Creates a new, autoreleased OFValue containing the specified size. * - * @param dimension The dimension the OFValue should contain + * @param size The size the OFValue should contain * @return A new, autoreleased OFValue */ -+ (instancetype)valueWithDimension: (of_dimension_t)dimension; ++ (instancetype)valueWithSize: (OFSize)size; /** * @brief Creates a new, autoreleased OFValue containing the specified * rectangle. * Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -13,17 +13,17 @@ * file. */ #import "OFValue.h" #import "OFBytesValue.h" -#import "OFDimensionValue.h" #import "OFMethodSignature.h" #import "OFNonretainedObjectValue.h" #import "OFPointValue.h" #import "OFPointerValue.h" #import "OFRangeValue.h" #import "OFRectangleValue.h" +#import "OFSizeValue.h" #import "OFString.h" #import "OFOutOfMemoryException.h" @implementation OFValue @@ -61,14 +61,13 @@ + (instancetype)valueWithPoint: (OFPoint)point { return [[[OFPointValue alloc] initWithPoint: point] autorelease]; } -+ (instancetype)valueWithDimension: (of_dimension_t)dimension ++ (instancetype)valueWithSize: (OFSize)size { - return [[[OFDimensionValue alloc] - initWithDimension: dimension] autorelease]; + return [[[OFSizeValue alloc] initWithSize: size] autorelease]; } + (instancetype)valueWithRectangle: (of_rectangle_t)rectangle { return [[[OFRectangleValue alloc] @@ -185,13 +184,13 @@ OFPoint ret; [self getValue: &ret size: sizeof(ret)]; return ret; } -- (of_dimension_t)dimensionValue +- (OFSize)sizeValue { - of_dimension_t ret; + OFSize ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (of_rectangle_t)rectangleValue Index: tests/OFValueTests.m ================================================================== --- tests/OFValueTests.m +++ tests/OFValueTests.m @@ -25,11 +25,11 @@ - (void)valueTests { void *pool = objc_autoreleasePoolPush(); OFRange range = OFMakeRange(1, 64), range2; OFPoint point = OFMakePoint(1.5f, 3.0f), point2; - of_dimension_t dimension = of_dimension(4.5f, 5.0f), dimension2; + 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; OFValue *value; void *pointer = &value; @@ -109,28 +109,28 @@ EXPECT_EXCEPTION(@"-[pointValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] pointValue]) - TEST(@"+[valueWithDimension:]", - (value = [OFValue valueWithDimension: dimension])) - - TEST(@"-[dimensionValue]", - of_dimension_equal(value.dimensionValue, dimension) && - (value = [OFValue valueWithBytes: &dimension - objCType: @encode(of_dimension_t)]) && - of_dimension_equal(value.dimensionValue, dimension)) - - TEST(@"-[getValue:size:] for OFDimensionValue", - (value = [OFValue valueWithDimension: dimension]) && - R([value getValue: &dimension2 size: sizeof(dimension2)]) && - of_dimension_equal(dimension2, dimension)) - - EXPECT_EXCEPTION(@"-[dimensionValue] with wrong size throws", + TEST(@"+[valueWithSize:]", + (value = [OFValue valueWithSize: size])) + + TEST(@"-[sizeValue]", + OFEqualSizes(value.sizeValue, size) && + (value = [OFValue valueWithBytes: &size + objCType: @encode(OFSize)]) && + OFEqualSizes(value.sizeValue, size)) + + TEST(@"-[getValue:size:] for OFSizeValue", + (value = [OFValue valueWithSize: size]) && + R([value getValue: &size2 size: sizeof(size2)]) && + OFEqualSizes(size2, size)) + + EXPECT_EXCEPTION(@"-[sizeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" - objCType: @encode(char)] dimensionValue]) + objCType: @encode(char)] sizeValue]) TEST(@"+[valueWithRectangle:]", (value = [OFValue valueWithRectangle: rectangle])) TEST(@"-[rectangleValue]",