Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -176,11 +176,10 @@ SRCS += OFASPrintF.m \ OFArchiveIRIHandler.m \ OFBase64.m \ OFBitSetCharacterSet.m \ - OFBytesValue.m \ OFCRC16.m \ OFCRC32.m \ OFConcreteArray.m \ OFConcreteColor.m \ OFConcreteCountedSet.m \ @@ -191,24 +190,19 @@ OFConcreteMutableData.m \ OFConcreteMutableDictionary.m \ OFConcreteMutableSet.m \ OFConcreteSet.m \ OFConcreteSubarray.m \ + OFConcreteValue.m \ OFEmbeddedIRIHandler.m \ OFHuffmanTree.m \ OFINIFileSettings.m \ OFInvertedCharacterSet.m \ OFLHADecompressingStream.m \ OFMutableUTF8String.m \ - OFNonretainedObjectValue.m \ - OFPointValue.m \ - OFPointerValue.m \ OFRangeCharacterSet.m \ - OFRangeValue.m \ - OFRectValue.m \ OFSandbox.m \ - OFSizeValue.m \ OFStrPTime.m \ OFSubarray.m \ OFSubdata.m \ OFTaggedPointerColor.m \ OFTaggedPointerDate.m \ DELETED src/OFBytesValue.h Index: src/OFBytesValue.h ================================================================== --- src/OFBytesValue.h +++ src/OFBytesValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 OFBytesValue: OFValue -{ - size_t _size; - void *_bytes; - const char *_objCType; -} -@end - -OF_ASSUME_NONNULL_END DELETED src/OFBytesValue.m Index: src/OFBytesValue.m ================================================================== --- src/OFBytesValue.m +++ src/OFBytesValue.m @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFBytesValue.h" -#import "OFMethodSignature.h" - -#import "OFOutOfRangeException.h" - -@implementation OFBytesValue -@synthesize objCType = _objCType; - -- (instancetype)initWithBytes: (const void *)bytes - objCType: (const char *)objCType -{ - self = [super init]; - - @try { - _size = OFSizeOfTypeEncoding(objCType); - _objCType = objCType; - _bytes = OFAllocMemory(1, _size); - - memcpy(_bytes, bytes, _size); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - OFFreeMemory(_bytes); - - [super dealloc]; -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != _size) - @throw [OFOutOfRangeException exception]; - - memcpy(value, _bytes, _size); -} -@end ADDED src/OFConcreteValue.h Index: src/OFConcreteValue.h ================================================================== --- src/OFConcreteValue.h +++ src/OFConcreteValue.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2008-2023 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 OFConcreteValue: OFValue +{ + size_t _size; + void *_bytes; + const char *_objCType; +} +@end + +OF_ASSUME_NONNULL_END ADDED src/OFConcreteValue.m Index: src/OFConcreteValue.m ================================================================== --- src/OFConcreteValue.m +++ src/OFConcreteValue.m @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2008-2023 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 "OFConcreteValue.h" +#import "OFMethodSignature.h" + +#import "OFOutOfRangeException.h" + +@implementation OFConcreteValue +@synthesize objCType = _objCType; + +- (instancetype)initWithBytes: (const void *)bytes + objCType: (const char *)objCType +{ + self = [super initWithBytes: bytes objCType: objCType]; + + @try { + _size = OFSizeOfTypeEncoding(objCType); + _objCType = objCType; + _bytes = OFAllocMemory(1, _size); + + memcpy(_bytes, bytes, _size); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + OFFreeMemory(_bytes); + + [super dealloc]; +} + +- (void)getValue: (void *)value size: (size_t)size +{ + if (size != _size) + @throw [OFOutOfRangeException exception]; + + memcpy(value, _bytes, _size); +} +@end DELETED src/OFNonretainedObjectValue.h Index: src/OFNonretainedObjectValue.h ================================================================== --- src/OFNonretainedObjectValue.h +++ src/OFNonretainedObjectValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 OFNonretainedObjectValue: OFValue -{ - id _object; -} - -- (instancetype)initWithNonretainedObject: (id)object; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFNonretainedObjectValue.m Index: src/OFNonretainedObjectValue.m ================================================================== --- src/OFNonretainedObjectValue.m +++ src/OFNonretainedObjectValue.m @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFNonretainedObjectValue.h" -#import "OFMethodSignature.h" - -#import "OFOutOfRangeException.h" - -@implementation OFNonretainedObjectValue -@synthesize nonretainedObjectValue = _object; - -- (instancetype)initWithNonretainedObject: (id)object -{ - self = [super init]; - - _object = object; - - return self; -} - -- (const char *)objCType -{ - return @encode(id); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_object)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_object, sizeof(_object)); -} - -- (void *)pointerValue -{ - return _object; -} -@end Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -602,161 +602,132 @@ OF_INVALID_INIT_METHOD } - (instancetype)initWithBool: (bool)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(bool)]; _value.unsigned_ = value; _typeEncoding = @encode(bool); return self; } - (instancetype)initWithChar: (signed char)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(signed char)]; _value.signed_ = value; _typeEncoding = @encode(signed char); return self; } - (instancetype)initWithShort: (short)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(short)]; _value.signed_ = value; _typeEncoding = @encode(short); return self; } - (instancetype)initWithInt: (int)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(int)]; _value.signed_ = value; _typeEncoding = @encode(int); return self; } - (instancetype)initWithLong: (long)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(long)]; _value.signed_ = value; _typeEncoding = @encode(long); return self; } - (instancetype)initWithLongLong: (long long)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(long long)]; _value.signed_ = value; _typeEncoding = @encode(long long); return self; } - (instancetype)initWithUnsignedChar: (unsigned char)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(unsigned char)]; _value.unsigned_ = value; - _typeEncoding = @encode(unsigned long); + _typeEncoding = @encode(unsigned char); return self; } - (instancetype)initWithUnsignedShort: (unsigned short)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(unsigned short)]; _value.unsigned_ = value; _typeEncoding = @encode(unsigned short); return self; } - (instancetype)initWithUnsignedInt: (unsigned int)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(unsigned int)]; _value.unsigned_ = value; _typeEncoding = @encode(unsigned int); return self; } - (instancetype)initWithUnsignedLong: (unsigned long)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(unsigned long)]; _value.unsigned_ = value; _typeEncoding = @encode(unsigned long); return self; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)value { - self = [super init]; + self = [super initWithBytes: &value + objCType: @encode(unsigned long long)]; _value.unsigned_ = value; _typeEncoding = @encode(unsigned long long); return self; } -- (instancetype)initWithPtrDiff: (ptrdiff_t)value -{ - self = [super init]; - - _value.signed_ = value; - _typeEncoding = @encode(ptrdiff_t); - - return self; -} - -- (instancetype)initWithIntPtr: (intptr_t)value -{ - self = [super init]; - - _value.signed_ = value; - _typeEncoding = @encode(intptr_t); - - return self; -} - -- (instancetype)initWithUIntPtr: (uintptr_t)value -{ - self = [super init]; - - _value.unsigned_ = value; - _typeEncoding = @encode(uintptr_t); - - return self; -} - - (instancetype)initWithFloat: (float)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(float)]; _value.float_ = value; _typeEncoding = @encode(float); return self; } - (instancetype)initWithDouble: (double)value { - self = [super init]; + self = [super initWithBytes: &value objCType: @encode(double)]; _value.float_ = value; _typeEncoding = @encode(double); return self; DELETED src/OFPointValue.h Index: src/OFPointValue.h ================================================================== --- src/OFPointValue.h +++ src/OFPointValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 OFPointValue: OFValue -{ - OFPoint _point; -} - -- (instancetype)initWithPoint: (OFPoint)point; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFPointValue.m Index: src/OFPointValue.m ================================================================== --- src/OFPointValue.m +++ src/OFPointValue.m @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFPointValue.h" -#import "OFMethodSignature.h" -#import "OFString.h" - -#import "OFOutOfRangeException.h" - -@implementation OFPointValue -@synthesize pointValue = _point; - -- (instancetype)initWithPoint: (OFPoint)point -{ - self = [super init]; - - _point = point; - - return self; -} - -- (const char *)objCType -{ - return @encode(OFPoint); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_point)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_point, sizeof(_point)); -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", _point.x, _point.y]; -} -@end DELETED src/OFPointerValue.h Index: src/OFPointerValue.h ================================================================== --- src/OFPointerValue.h +++ src/OFPointerValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 OFPointerValue: OFValue -{ - void *_pointer; -} - -- (instancetype)initWithPointer: (const void *)pointer; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFPointerValue.m Index: src/OFPointerValue.m ================================================================== --- src/OFPointerValue.m +++ src/OFPointerValue.m @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFPointerValue.h" -#import "OFMethodSignature.h" - -#import "OFOutOfRangeException.h" - -@implementation OFPointerValue -@synthesize pointerValue = _pointer; - -- (instancetype)initWithPointer: (const void *)pointer -{ - self = [super init]; - - _pointer = (void *)pointer; - - return self; -} - -- (const char *)objCType -{ - return @encode(void *); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_pointer)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_pointer, sizeof(_pointer)); -} - -- (id)nonretainedObjectValue -{ - return _pointer; -} -@end DELETED src/OFRangeValue.h Index: src/OFRangeValue.h ================================================================== --- src/OFRangeValue.h +++ src/OFRangeValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 OFRangeValue: OFValue -{ - OFRange _range; -} - -- (instancetype)initWithRange: (OFRange)range; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFRangeValue.m Index: src/OFRangeValue.m ================================================================== --- src/OFRangeValue.m +++ src/OFRangeValue.m @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 "OFRangeValue.h" -#import "OFMethodSignature.h" -#import "OFString.h" - -#import "OFOutOfRangeException.h" - -@implementation OFRangeValue -@synthesize rangeValue = _range; - -- (instancetype)initWithRange: (OFRange)range -{ - self = [super init]; - - _range = range; - - return self; -} - -- (const char *)objCType -{ - return @encode(OFRange); -} - -- (void)getValue: (void *)value size: (size_t)size -{ - if (size != sizeof(_range)) - @throw [OFOutOfRangeException exception]; - - memcpy(value, &_range, sizeof(_range)); -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", - _range.location, _range.length]; -} -@end DELETED src/OFRectValue.h Index: src/OFRectValue.h ================================================================== --- src/OFRectValue.h +++ src/OFRectValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 DELETED src/OFRectValue.m Index: src/OFRectValue.m ================================================================== --- src/OFRectValue.m +++ src/OFRectValue.m @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2008-2023 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/OFSizeValue.h Index: src/OFSizeValue.h ================================================================== --- src/OFSizeValue.h +++ src/OFSizeValue.h @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 DELETED src/OFSizeValue.m Index: src/OFSizeValue.m ================================================================== --- src/OFSizeValue.m +++ src/OFSizeValue.m @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2008-2023 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 @@ -21,14 +21,10 @@ * @class OFValue OFValue.h ObjFW/OFValue.h * * @brief A class for storing arbitrary values in an object. */ @interface OFValue: OFObject -{ - OF_RESERVE_IVARS(OFValue, 4) -} - /** * @brief The ObjC type encoding of the value. */ @property (readonly, nonatomic) const char *objCType; @@ -147,11 +143,13 @@ * @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; + objCType: (const char *)objCType OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; /** * @brief Gets the value. * * @param value The buffer to copy the value into Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -14,71 +14,120 @@ */ #include "config.h" #import "OFValue.h" -#import "OFBytesValue.h" +#import "OFConcreteValue.h" #import "OFMethodSignature.h" -#import "OFNonretainedObjectValue.h" -#import "OFPointValue.h" -#import "OFPointerValue.h" -#import "OFRangeValue.h" -#import "OFRectValue.h" -#import "OFSizeValue.h" #import "OFString.h" #import "OFOutOfMemoryException.h" + +static struct { + Class isa; +} placeholder; + +@interface OFPlaceholderValue: OFValue +@end + +@implementation OFPlaceholderValue +#ifdef __clang__ +/* We intentionally don't call into super, so silence the warning. */ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunknown-pragmas" +# pragma clang diagnostic ignored "-Wobjc-designated-initializers" +#endif +- (instancetype)initWithBytes: (const void *)bytes + objCType: (const char *)objCType +{ + return (id)[[OFConcreteValue alloc] initWithBytes: bytes + objCType: objCType]; +} +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + +OF_SINGLETON_METHODS +@end @implementation OFValue ++ (void)initialize +{ + if (self == [OFValue class]) + object_setClass((id)&placeholder, [OFPlaceholderValue class]); +} + + (instancetype)alloc { if (self == [OFValue class]) - return [OFBytesValue alloc]; + return (id)&placeholder; return [super alloc]; } + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType { - return [[[OFBytesValue alloc] initWithBytes: bytes - objCType: objCType] autorelease]; + return [[[OFValue alloc] initWithBytes: bytes + objCType: objCType] autorelease]; } + (instancetype)valueWithPointer: (const void *)pointer { - return [[[OFPointerValue alloc] initWithPointer: pointer] autorelease]; + return [[[OFValue alloc] + initWithBytes: &pointer + objCType: @encode(const void *)] autorelease]; } + (instancetype)valueWithNonretainedObject: (id)object { - return [[[OFNonretainedObjectValue alloc] - initWithNonretainedObject: object] autorelease]; + return [[[OFValue alloc] initWithBytes: &object + objCType: @encode(id)] autorelease]; } + (instancetype)valueWithRange: (OFRange)range { - return [[[OFRangeValue alloc] initWithRange: range] autorelease]; + return [[[OFValue alloc] initWithBytes: &range + objCType: @encode(OFRange)] autorelease]; } + (instancetype)valueWithPoint: (OFPoint)point { - return [[[OFPointValue alloc] initWithPoint: point] autorelease]; + return [[[OFValue alloc] initWithBytes: &point + objCType: @encode(OFPoint)] autorelease]; } + (instancetype)valueWithSize: (OFSize)size { - return [[[OFSizeValue alloc] initWithSize: size] autorelease]; + return [[[OFValue alloc] initWithBytes: &size + objCType: @encode(OFSize)] autorelease]; } + (instancetype)valueWithRect: (OFRect)rect { - return [[[OFRectValue alloc] initWithRect: rect] autorelease]; + return [[[OFValue alloc] initWithBytes: &rect + objCType: @encode(OFRect)] autorelease]; } - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType +{ + if ([self isMemberOfClass: [OFValue class]]) { + @try { + [self doesNotRecognizeSelector: _cmd]; + } @catch (id e) { + [self release]; + @throw e; + } + + abort(); + } + + return [super init]; +} + +- (instancetype)init { OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object