Index: src/OFDimensionValue.h ================================================================== --- src/OFDimensionValue.h +++ src/OFDimensionValue.h @@ -19,8 +19,10 @@ @interface OFDimensionValue: OFValue { of_dimension_t _dimension; } + +- (instancetype)initWithDimension: (of_dimension_t)dimension; @end OF_ASSUME_NONNULL_END Index: src/OFNonretainedObjectValue.h ================================================================== --- src/OFNonretainedObjectValue.h +++ src/OFNonretainedObjectValue.h @@ -19,8 +19,10 @@ @interface OFNonretainedObjectValue: OFValue { id _object; } + +- (instancetype)initWithNonretainedObject: (id)object; @end OF_ASSUME_NONNULL_END Index: src/OFPointValue.h ================================================================== --- src/OFPointValue.h +++ src/OFPointValue.h @@ -19,8 +19,10 @@ @interface OFPointValue: OFValue { of_point_t _point; } + +- (instancetype)initWithPoint: (of_point_t)point; @end OF_ASSUME_NONNULL_END Index: src/OFPointerValue.h ================================================================== --- src/OFPointerValue.h +++ src/OFPointerValue.h @@ -19,8 +19,10 @@ @interface OFPointerValue: OFValue { void *_pointer; } + +- (instancetype)initWithPointer: (const void *)pointer; @end OF_ASSUME_NONNULL_END Index: src/OFRangeValue.h ================================================================== --- src/OFRangeValue.h +++ src/OFRangeValue.h @@ -19,8 +19,10 @@ @interface OFRangeValue: OFValue { of_range_t _range; } + +- (instancetype)initWithRange: (of_range_t)range; @end OF_ASSUME_NONNULL_END Index: src/OFRectangleValue.h ================================================================== --- src/OFRectangleValue.h +++ src/OFRectangleValue.h @@ -19,8 +19,10 @@ @interface OFRectangleValue: OFValue { of_rectangle_t _rectangle; } + +- (instancetype)initWithRectangle: (of_rectangle_t)rectangle; @end OF_ASSUME_NONNULL_END Index: src/OFValue.h ================================================================== --- src/OFValue.h +++ src/OFValue.h @@ -150,69 +150,10 @@ * @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. Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -24,142 +24,62 @@ #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 [OFBytesValue alloc]; return [super alloc]; } + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType { - return [[[self alloc] initWithBytes: bytes - objCType: objCType] autorelease]; + return [[[OFBytesValue alloc] initWithBytes: bytes + objCType: objCType] autorelease]; } + (instancetype)valueWithPointer: (const void *)pointer { - return [[[self alloc] initWithPointer: pointer] autorelease]; + return [[[OFPointerValue alloc] initWithPointer: pointer] autorelease]; } + (instancetype)valueWithNonretainedObject: (id)object { - return [[[self alloc] initWithNonretainedObject: object] autorelease]; + return [[[OFNonretainedObjectValue alloc] + initWithNonretainedObject: object] autorelease]; } + (instancetype)valueWithRange: (of_range_t)range { - return [[[self alloc] initWithRange: range] autorelease]; + return [[[OFRangeValue alloc] initWithRange: range] autorelease]; } + (instancetype)valueWithPoint: (of_point_t)point { - return [[[self alloc] initWithPoint: point] autorelease]; + return [[[OFPointValue alloc] initWithPoint: point] autorelease]; } + (instancetype)valueWithDimension: (of_dimension_t)dimension { - return [[[self alloc] initWithDimension: dimension] autorelease]; + return [[[OFDimensionValue alloc] + initWithDimension: dimension] autorelease]; } + (instancetype)valueWithRectangle: (of_rectangle_t)rectangle { - return [[[self alloc] initWithRectangle: rectangle] autorelease]; + return [[[OFRectangleValue 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 {