@@ -15,12 +15,15 @@ * file. */ #import "OFValue.h" #import "OFValue_bytes.h" +#import "OFValue_nonretainedObject.h" +#import "OFValue_pointer.h" #import "OFMethodSignature.h" +#import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" static struct { Class isa; } placeholder; @@ -33,10 +36,21 @@ objCType: (const char *)objCType { return (id)[[OFValue_bytes alloc] initWithBytes: bytes objCType: objCType]; } + +- (instancetype)initWithPointer: (const void *)pointer +{ + return (id)[[OFValue_pointer alloc] initWithPointer: pointer]; +} + +- (instancetype)initWithNonretainedObject: (id)object +{ + return (id)[[OFValue_nonretainedObject alloc] + initWithNonretainedObject: object]; +} @end @implementation OFValue + (void)initialize { @@ -56,14 +70,34 @@ objCType: (const char *)objCType { return [[[self alloc] initWithBytes: bytes objCType: objCType] autorelease]; } + ++ (instancetype)valueWithPointer: (const void *)pointer +{ + return [[[self alloc] initWithPointer: pointer] autorelease]; +} + ++ (instancetype)valueWithNonretainedObject: (id)object +{ + return [[[self alloc] initWithNonretainedObject: object] 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 } - (bool)isEqual: (id)object { @@ -139,6 +173,26 @@ - (void)getValue: (void *)value size: (size_t)size { OF_UNRECOGNIZED_SELECTOR } + +- (void *)pointerValue +{ + void *ret; + + [self getValue: &ret + size: sizeof(ret)]; + + return ret; +} + +- (id)nonretainedObjectValue +{ + id ret; + + [self getValue: &ret + size: sizeof(ret)]; + + return ret; +} @end