view dstep/foundation/NSValue.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 89f3c3ef1fd2
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Aug 3, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.foundation.NSValue;

import dstep.foundation.NSCoder;
import dstep.foundation.NSDecimal;
import dstep.foundation.NSDecimalNumber;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSGeometry;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSRange;
import dstep.foundation.NSString;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.applicationservices.coregraphics.CGGeometry;
import dstep.objc.objc;

private
{
	alias CGPoint NSPoint;
	alias NSPoint* NSPointPointer;
	alias NSPoint* NSPointArray;
	alias CGSize NSSize;
	alias NSSize* NSSizePointer;
	alias NSSize* NSSizeArray;
	alias CGRect NSRect;
	alias NSRect* NSRectPointer;
	alias NSRect* NSRectArray;
	alias NSUInteger NSRectEdge;
}

const TNSNumberCreation = `

	Object initWithChar (byte value)
	{
		return invokeObjcSelf!(Object, "initWithChar:", byte)(value);
	}

	this (byte value)
	{
		typeof(this).alloc.initWithChar(value);
	}

	Object initWithUnsignedChar (ubyte value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedChar:", ubyte)(value);
	}

	this (ubyte value)
	{
		typeof(this).alloc.initWithUnsignedChar(value);
	}

	Object initWithShort (short value)
	{
		return invokeObjcSelf!(Object, "initWithShort:", short)(value);
	}

	this (short value)
	{
		typeof(this).alloc.initWithShort(value);
	}

	Object initWithUnsignedShort (ushort value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedShort:", ushort)(value);
	}

	this (ushort value)
	{
		typeof(this).alloc.initWithUnsignedShort(value);
	}

	Object initWithInt (int value)
	{
		return invokeObjcSelf!(Object, "initWithInt:", int)(value);
	}

	this (int value)
	{
		typeof(this).alloc.initWithInt(value);
	}

	Object initWithUnsignedInt (uint value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedInt:", uint)(value);
	}

	this (uint value)
	{
		typeof(this).alloc.initWithUnsignedInt(value);
	}

	Object initWithLong (int value)
	{
		return invokeObjcSelf!(Object, "initWithLong:", int)(value);
	}

	this (int value)
	{
		typeof(this).alloc.initWithLong(value);
	}

	Object initWithUnsignedLong (uint value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedLong:", uint)(value);
	}

	this (uint value)
	{
		typeof(this).alloc.initWithUnsignedLong(value);
	}

	Object initWithLongLong (long value)
	{
		return invokeObjcSelf!(Object, "initWithLongLong:", long)(value);
	}

	this (long value)
	{
		typeof(this).alloc.initWithLongLong(value);
	}

	Object initWithUnsignedLongLong (ulong value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedLongLong:", ulong)(value);
	}

	this (ulong value)
	{
		typeof(this).alloc.initWithUnsignedLongLong(value);
	}

	Object initWithFloat (float value)
	{
		return invokeObjcSelf!(Object, "initWithFloat:", float)(value);
	}

	this (float value)
	{
		typeof(this).alloc.initWithFloat(value);
	}

	Object initWithDouble (double value)
	{
		return invokeObjcSelf!(Object, "initWithDouble:", double)(value);
	}

	this (double value)
	{
		typeof(this).alloc.initWithDouble(value);
	}

	Object initWithBool (bool value)
	{
		return invokeObjcSelf!(Object, "initWithBool:", bool)(value);
	}

	this (bool value)
	{
		typeof(this).alloc.initWithBool(value);
	}

	Object initWithInteger (NSInteger value)
	{
		return invokeObjcSelf!(Object, "initWithInteger:", NSInteger)(value);
	}

	this (NSInteger value)
	{
		typeof(this).alloc.initWithInteger(value);
	}

	Object initWithUnsignedInteger (NSUInteger value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedInteger:", NSUInteger)(value);
	}

	this (NSUInteger value)
	{
		typeof(this).alloc.initWithUnsignedInteger(value);
	}

	static NSNumber numberWithChar (byte value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithChar:", byte)(value);
	}

	static NSNumber numberWithUnsignedChar (ubyte value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedChar:", ubyte)(value);
	}

	static NSNumber numberWithShort (short value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithShort:", short)(value);
	}

	static NSNumber numberWithUnsignedShort (ushort value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedShort:", ushort)(value);
	}

	static NSNumber numberWithInt (int value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithInt:", int)(value);
	}

	static NSNumber numberWithUnsignedInt (uint value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedInt:", uint)(value);
	}

	static NSNumber numberWithLong (int value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithLong:", int)(value);
	}

	static NSNumber numberWithUnsignedLong (uint value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedLong:", uint)(value);
	}

	static NSNumber numberWithLongLong (long value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithLongLong:", long)(value);
	}

	static NSNumber numberWithUnsignedLongLong (ulong value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedLongLong:", ulong)(value);
	}

	static NSNumber numberWithFloat (float value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithFloat:", float)(value);
	}

	static NSNumber numberWithDouble (double value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithDouble:", double)(value);
	}

	static NSNumber numberWithBool (bool value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithBool:", bool)(value);
	}

	static NSNumber numberWithInteger (NSInteger value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithInteger:", NSInteger)(value);
	}

	static NSNumber numberWithUnsignedInteger (NSUInteger value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedInteger:", NSUInteger)(value);
	}
`;

const TNSValueCreation = `

	Object initWithBytes (void* value, char* type)
	{
		return invokeObjcSelf!(Object, "initWithBytes:objCType:", void*, char*)(value, type);
	}

	this (void* value, char* type)
	{
		typeof(this).alloc.initWithBytes(value, type);
	}

	static NSValue valueWithBytes (void* value, char* type)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithBytes:objCType:", void*, char*)(value, type);
	}

	static NSValue value (void* value, char* type)
	{
		return invokeObjcSuperClass!(NSValue, "value:withObjCType:", void*, char*)(value, type);
	}
`;

const TNSValueExtensionMethods = `

	static NSValue valueWithNonretainedObject (Object anObject)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithNonretainedObject:", Object)(anObject);
	}

	Object nonretainedObjectValue ()
	{
		return invokeObjcSelf!(Object, "nonretainedObjectValue");
	}

	static NSValue valueWithPointer (void* pointer)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithPointer:", void*)(pointer);
	}

	void* pointerValue ()
	{
		return invokeObjcSelf!(void*, "pointerValue");
	}

	bool isEqualToValue (NSValue value)
	{
		return invokeObjcSelf!(bool, "isEqualToValue:", NSValue)(value);
	}
`;

class NSValue : NSObject, INSCopying, INSCoding
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	void getValue (void* value)
	{
		return invokeObjcSelf!(void, "getValue:", void*)(value);
	}

	char* objCType ()
	{
		return invokeObjcSelf!(char*, "objCType");
	}

	Object copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
	}

	void encodeWithCoder (NSCoder aCoder)
	{
		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
	}

	Object initWithCoder (NSCoder aDecoder)
	{
		return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
	}

	this (NSCoder aDecoder)
	{
		typeof(this).alloc.initWithCoder(aDecoder);
	}
	
	// TNSValueGeometryExtensions
	static NSValue valueWithPoint (dstep.applicationservices.coregraphics.CGGeometry.CGPoint point)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithPoint:", NSPoint)(point);
	}
	
	static NSValue valueWithSize (NSSize size)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithSize:", NSSize)(size);
	}
	
	static NSValue valueWithRect (NSRect rect)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithRect:", NSRect)(rect);
	}
	
	NSPoint pointValue ()
	{
		return invokeObjcSelf!(NSPoint, "pointValue");
	}
	
	NSSize sizeValue ()
	{
		return invokeObjcSelf!(NSSize, "sizeValue");
	}
	
	NSRect rectValue ()
	{
		return invokeObjcSelf!(NSRect, "rectValue");
	}
	
	// TNSValueCreation
	Object initWithBytes (void* value, char* type)
	{
		return invokeObjcSelf!(Object, "initWithBytes:objCType:", void*, char*)(value, type);
	}
	
	this (void* value, char* type)
	{
		typeof(this).alloc.initWithBytes(value, type);
	}
	
	static NSValue valueWithBytes (void* value, char* type)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithBytes:objCType:", void*, char*)(value, type);
	}
	
	static NSValue value (void* value, char* type)
	{
		return invokeObjcSuperClass!(NSValue, "value:withObjCType:", void*, char*)(value, type);
	}
	
	// TNSValueRangeExtensions
	static NSValue valueWithRange (NSRange range)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithRange:", NSRange)(range);
	}
	
	NSRange rangeValue ()
	{
		return invokeObjcSelf!(NSRange, "rangeValue");
	}
	
	// TNSValueExtensionMethods
	static NSValue valueWithNonretainedObject (Object anObject)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithNonretainedObject:", Object)(anObject);
	}
	
	Object nonretainedObjectValue ()
	{
		return invokeObjcSelf!(Object, "nonretainedObjectValue");
	}
	
	static NSValue valueWithPointer (void* pointer)
	{
		return invokeObjcSuperClass!(NSValue, "valueWithPointer:", void*)(pointer);
	}
	
	void* pointerValue ()
	{
		return invokeObjcSelf!(void*, "pointerValue");
	}
	
	bool isEqualToValue (NSValue value)
	{
		return invokeObjcSelf!(bool, "isEqualToValue:", NSValue)(value);
	}
}

class NSNumber : NSValue
{
	mixin (ObjcWrap);

	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	byte charValue ()
	{
		return invokeObjcSelf!(byte, "charValue");
	}

	ubyte unsignedCharValue ()
	{
		return invokeObjcSelf!(ubyte, "unsignedCharValue");
	}

	short shortValue ()
	{
		return invokeObjcSelf!(short, "shortValue");
	}

	ushort unsignedShortValue ()
	{
		return invokeObjcSelf!(ushort, "unsignedShortValue");
	}

	int intValue ()
	{
		return invokeObjcSelf!(int, "intValue");
	}

	uint unsignedIntValue ()
	{
		return invokeObjcSelf!(uint, "unsignedIntValue");
	}

	int longValue ()
	{
		return invokeObjcSelf!(int, "longValue");
	}

	uint unsignedLongValue ()
	{
		return invokeObjcSelf!(uint, "unsignedLongValue");
	}

	long longLongValue ()
	{
		return invokeObjcSelf!(long, "longLongValue");
	}

	ulong unsignedLongLongValue ()
	{
		return invokeObjcSelf!(ulong, "unsignedLongLongValue");
	}

	float floatValue ()
	{
		return invokeObjcSelf!(float, "floatValue");
	}

	double doubleValue ()
	{
		return invokeObjcSelf!(double, "doubleValue");
	}

	bool boolValue ()
	{
		return invokeObjcSelf!(bool, "boolValue");
	}

	NSInteger integerValue ()
	{
		return invokeObjcSelf!(NSInteger, "integerValue");
	}

	NSUInteger unsignedIntegerValue ()
	{
		return invokeObjcSelf!(NSUInteger, "unsignedIntegerValue");
	}

	NSString stringValue ()
	{
		return invokeObjcSelf!(NSString, "stringValue");
	}

	int compare (NSNumber otherNumber)
	{
		return invokeObjcSelf!(int, "compare:", NSNumber)(otherNumber);
	}

	bool isEqualToNumber (NSNumber number)
	{
		return invokeObjcSelf!(bool, "isEqualToNumber:", NSNumber)(number);
	}

	NSString descriptionWithLocale (Object locale)
	{
		return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
	}
	
	// TNSDecimalNumberExtensions
	NSDecimal decimalValue ()
	{
		return invokeObjcSelf!(NSDecimal, "decimalValue");
	}
	
	// TNSNumberCreation
	Object initWithChar (byte value)
	{
		return invokeObjcSelf!(Object, "initWithChar:", byte)(value);
	}
	
	this (byte value)
	{
		typeof(this).alloc.initWithChar(value);
	}
	
	Object initWithUnsignedChar (ubyte value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedChar:", ubyte)(value);
	}
	
	this (ubyte value)
	{
		typeof(this).alloc.initWithUnsignedChar(value);
	}
	
	Object initWithShort (short value)
	{
		return invokeObjcSelf!(Object, "initWithShort:", short)(value);
	}
	
	this (short value)
	{
		typeof(this).alloc.initWithShort(value);
	}
	
	Object initWithUnsignedShort (ushort value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedShort:", ushort)(value);
	}
	
	this (ushort value)
	{
		typeof(this).alloc.initWithUnsignedShort(value);
	}
	
	Object initWithInt (int value)
	{
		return invokeObjcSelf!(Object, "initWithInt:", int)(value);
	}
	
	this (int value)
	{
		typeof(this).alloc.initWithInt(value);
	}
	
	Object initWithUnsignedInt (uint value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedInt:", uint)(value);
	}
	
	this (uint value)
	{
		typeof(this).alloc.initWithUnsignedInt(value);
	}
	
	Object initWithLong (int value)
	{
		return invokeObjcSelf!(Object, "initWithLong:", int)(value);
	}
	
	Object initWithUnsignedLong (uint value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedLong:", uint)(value);
	}
	
	Object initWithLongLong (long value)
	{
		return invokeObjcSelf!(Object, "initWithLongLong:", long)(value);
	}
	
	this (long value)
	{
		typeof(this).alloc.initWithLongLong(value);
	}
	
	Object initWithUnsignedLongLong (ulong value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedLongLong:", ulong)(value);
	}
	
	this (ulong value)
	{
		typeof(this).alloc.initWithUnsignedLongLong(value);
	}
	
	Object initWithFloat (float value)
	{
		return invokeObjcSelf!(Object, "initWithFloat:", float)(value);
	}
	
	this (float value)
	{
		typeof(this).alloc.initWithFloat(value);
	}
	
	Object initWithDouble (double value)
	{
		return invokeObjcSelf!(Object, "initWithDouble:", double)(value);
	}
	
	this (double value)
	{
		typeof(this).alloc.initWithDouble(value);
	}
	
	Object initWithBool (bool value)
	{
		return invokeObjcSelf!(Object, "initWithBool:", bool)(value);
	}
	
	this (bool value)
	{
		typeof(this).alloc.initWithBool(value);
	}
	
	Object initWithInteger (NSInteger value)
	{
		return invokeObjcSelf!(Object, "initWithInteger:", NSInteger)(value);
	}
	
	Object initWithUnsignedInteger (NSUInteger value)
	{
		return invokeObjcSelf!(Object, "initWithUnsignedInteger:", NSUInteger)(value);
	}
	
	static NSNumber numberWithChar (byte value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithChar:", byte)(value);
	}
	
	static NSNumber numberWithUnsignedChar (ubyte value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedChar:", ubyte)(value);
	}
	
	static NSNumber numberWithShort (short value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithShort:", short)(value);
	}
	
	static NSNumber numberWithUnsignedShort (ushort value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedShort:", ushort)(value);
	}
	
	static NSNumber numberWithInt (int value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithInt:", int)(value);
	}
	
	static NSNumber numberWithUnsignedInt (uint value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedInt:", uint)(value);
	}
	
	static NSNumber numberWithLong (int value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithLong:", int)(value);
	}
	
	static NSNumber numberWithUnsignedLong (uint value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedLong:", uint)(value);
	}
	
	static NSNumber numberWithLongLong (long value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithLongLong:", long)(value);
	}
	
	static NSNumber numberWithUnsignedLongLong (ulong value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedLongLong:", ulong)(value);
	}
	
	static NSNumber numberWithFloat (float value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithFloat:", float)(value);
	}
	
	static NSNumber numberWithDouble (double value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithDouble:", double)(value);
	}
	
	static NSNumber numberWithBool (bool value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithBool:", bool)(value);
	}
	
	static NSNumber numberWithInteger (NSInteger value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithInteger:", NSInteger)(value);
	}
	
	static NSNumber numberWithUnsignedInteger (NSUInteger value)
	{
		return invokeObjcSuperClass!(NSNumber, "numberWithUnsignedInteger:", NSUInteger)(value);
	}
}