diff dstep/foundation/NSDecimalNumber.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 7ff919f595d5
children b9de51448c6b
line wrap: on
line diff
--- a/dstep/foundation/NSDecimalNumber.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSDecimalNumber.d	Sun Jan 03 22:06:11 2010 +0100
@@ -6,94 +6,127 @@
  */
 module dstep.foundation.NSDecimalNumber;
 
+import dstep.foundation.NSCoder;
 import dstep.foundation.NSDecimal;
 import dstep.foundation.NSDictionary;
+import dstep.foundation.NSObjCRuntime;
+import dstep.foundation.NSObject;
 import dstep.foundation.NSScanner;
+import dstep.foundation.NSString;
 import dstep.foundation.NSValue;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
 
 import bindings = dstep.foundation.NSDecimalNumber_bindings;
 
-const NSString NSDecimalNumberExactnessException;
-const NSString NSDecimalNumberOverflowException;
-const NSString NSDecimalNumberUnderflowException;
-const NSString NSDecimalNumberDivideByZeroException;
+private
+{
+	NSString NSDecimalNumberExactnessException_;
+	NSString NSDecimalNumberOverflowException_;
+	NSString NSDecimalNumberUnderflowException_;
+	NSString NSDecimalNumberDivideByZeroException_;
+}
+
+NSString NSDecimalNumberExactnessException ()
+{
+	if (NSDecimalNumberExactnessException_)
+		return NSDecimalNumberExactnessException_;
+		
+	return NSDecimalNumberExactnessException_ = new NSString(bindings.NSDecimalNumberExactnessException);
+}
+
+NSString NSDecimalNumberOverflowException ()
+{
+	if (NSDecimalNumberOverflowException_)
+		return NSDecimalNumberOverflowException_;
+		
+	return NSDecimalNumberOverflowException_ = new NSString(bindings.NSDecimalNumberOverflowException);
+}
 
-static this ()
+NSString NSDecimalNumberUnderflowException ()
+{
+	if (NSDecimalNumberUnderflowException_)
+		return NSDecimalNumberUnderflowException_;
+		
+	return NSDecimalNumberUnderflowException_ = new NSString(bindings.NSDecimalNumberUnderflowException);
+}
+
+NSString NSDecimalNumberDivideByZeroException ()
 {
-	NSDecimalNumberExactnessException = new NSString(bindings.NSDecimalNumberExactnessException);
-	NSDecimalNumberOverflowException = new NSString(bindings.NSDecimalNumberOverflowException);
-	NSDecimalNumberUnderflowException = new NSString(bindings.NSDecimalNumberUnderflowException);
-	NSDecimalNumberDivideByZeroException = new NSString(bindings.NSDecimalNumberDivideByZeroException);
+	if (NSDecimalNumberDivideByZeroException_)
+		return NSDecimalNumberDivideByZeroException_;
+		
+	return NSDecimalNumberDivideByZeroException_ = new NSString(bindings.NSDecimalNumberDivideByZeroException);
 }
 
+const TNSDecimalNumberExtensions = `
+
+	NSDecimal decimalValue ()
+	{
+		return invokeObjcSelf!(NSDecimal, "decimalValue");
+	}
+`;
+
+const TNSDecimalNumberScanning = `
+
+	bool scanDecimal (NSDecimal* dcm)
+	{
+		return invokeObjcSelf!(bool, "scanDecimal:", NSDecimal*)(dcm);
+	}
+`;
+
 class NSDecimalNumber : NSNumber
 {
-	mixin ObjcWrap;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
-	Object initWithMantissa (ulong mantissa, short exponent, bool flag)
+	NSDecimalNumber initWithMantissa (ulong mantissa, short exponent, bool flag)
 	{
-		return invokeObjcSelf!(Object, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
+		return invokeObjcSelf!(NSDecimalNumber, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
 	}
 
 	this (ulong mantissa, short exponent, bool flag)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithMantissa:exponent:isNegative:", ulong, short, bool)(objcObject, mantissa, exponent, flag);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		super(typeof(this).alloc.initWithMantissa(mantissa, exponent, flag).objcObject);
 	}
 
-	Object initWithDecimal (NSDecimal dcm)
+	NSDecimalNumber initWithDecimal (NSDecimal dcm)
 	{
-		return invokeObjcSelf!(Object, "initWithDecimal:", NSDecimal)(dcm);
+		return invokeObjcSelf!(NSDecimalNumber, "initWithDecimal:", NSDecimal)(dcm);
 	}
 
 	this (NSDecimal dcm)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithDecimal:", NSDecimal)(objcObject, dcm);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		super(typeof(this).alloc.initWithDecimal(dcm).objcObject);
 	}
 
-	Object initWithString (NSString numberValue)
+	NSDecimalNumber initWithString (NSString numberValue)
 	{
-		return invokeObjcSelf!(Object, "initWithString:", NSString)(numberValue);
+		return invokeObjcSelf!(NSDecimalNumber, "initWithString:", NSString)(numberValue);
 	}
 
 	this (NSString numberValue)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithString:", NSString)(objcObject, numberValue);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		super(typeof(this).alloc.initWithString(numberValue).objcObject);
 	}
 
-	Object initWithString (NSString numberValue, Object locale)
+	NSDecimalNumber initWithString (NSString numberValue, Object locale)
 	{
-		return invokeObjcSelf!(Object, "initWithString:locale:", NSString, Object)(numberValue, locale);
+		return invokeObjcSelf!(NSDecimalNumber, "initWithString:locale:", NSString, Object)(numberValue, locale);
 	}
 
 	this (NSString numberValue, Object locale)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithString:locale:", NSString, Object)(objcObject, numberValue, locale);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		super(typeof(this).alloc.initWithString(numberValue, locale).objcObject);
 	}
 
 	NSString descriptionWithLocale (Object locale)
@@ -108,47 +141,47 @@
 
 	static NSDecimalNumber decimalNumberWithMantissa (ulong mantissa, short exponent, bool flag)
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
+		return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithMantissa:exponent:isNegative:", ulong, short, bool)(mantissa, exponent, flag);
 	}
 
 	static NSDecimalNumber decimalNumberWithDecimal (NSDecimal dcm)
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithDecimal:", NSDecimal)(dcm);
+		return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithDecimal:", NSDecimal)(dcm);
 	}
 
 	static NSDecimalNumber decimalNumberWithString (NSString numberValue)
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:", NSString)(numberValue);
+		return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithString:", NSString)(numberValue);
 	}
 
 	static NSDecimalNumber decimalNumberWithString (NSString numberValue, Object locale)
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "decimalNumberWithString:locale:", NSString, Object)(numberValue, locale);
+		return invokeObjcSuperClass!(NSDecimalNumber, "decimalNumberWithString:locale:", NSString, Object)(numberValue, locale);
 	}
 
 	static NSDecimalNumber zero ()
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "zero");
+		return invokeObjcSuperClass!(NSDecimalNumber, "zero");
 	}
 
 	static NSDecimalNumber one ()
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "one");
+		return invokeObjcSuperClass!(NSDecimalNumber, "one");
 	}
 
 	static NSDecimalNumber minimumDecimalNumber ()
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "minimumDecimalNumber");
+		return invokeObjcSuperClass!(NSDecimalNumber, "minimumDecimalNumber");
 	}
 
 	static NSDecimalNumber maximumDecimalNumber ()
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "maximumDecimalNumber");
+		return invokeObjcSuperClass!(NSDecimalNumber, "maximumDecimalNumber");
 	}
 
 	static NSDecimalNumber notANumber ()
 	{
-		return invokeObjcSelfClass!(NSDecimalNumber, "notANumber");
+		return invokeObjcSuperClass!(NSDecimalNumber, "notANumber");
 	}
 
 	NSDecimalNumber decimalNumberByAdding (NSDecimalNumber decimalNumber)
@@ -236,12 +269,12 @@
 
 	static void setDefaultBehavior (INSDecimalNumberBehaviors behavior)
 	{
-		return invokeObjcSelfClass!(void, "setDefaultBehavior:", INSDecimalNumberBehaviors)(behavior);
+		return invokeObjcSuperClass!(void, "setDefaultBehavior:", INSDecimalNumberBehaviors)(behavior);
 	}
 
 	static INSDecimalNumberBehaviors defaultBehavior ()
 	{
-		return invokeObjcSelfClass!(INSDecimalNumberBehaviors, "defaultBehavior");
+		return invokeObjcSuperClass!(INSDecimalNumberBehaviors, "defaultBehavior");
 	}
 
 	char* objCType ()
@@ -257,11 +290,21 @@
 
 class NSDecimalNumberHandler : NSObject, INSDecimalNumberBehaviors, INSCoding
 {
-	mixin ObjcWrap;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	static Object defaultDecimalNumberHandler ()
 	{
-		return invokeObjcSelfClass!(Object, "defaultDecimalNumberHandler");
+		return invokeObjcSuperClass!(Object, "defaultDecimalNumberHandler");
 	}
 
 	Object initWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
@@ -271,18 +314,12 @@
 
 	this (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(objcObject, roundingMode, scale, exact, overflow, underflow, divideByZero);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithRoundingMode(roundingMode, scale, exact, overflow, underflow, divideByZero);
 	}
 
 	static Object decimalNumberHandlerWithRoundingMode (uint roundingMode, short scale, bool exact, bool overflow, bool underflow, bool divideByZero)
 	{
-		return invokeObjcSelfClass!(Object, "decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero);
+		return invokeObjcSuperClass!(Object, "decimalNumberHandlerWithRoundingMode:scale:raiseOnExactness:raiseOnOverflow:raiseOnUnderflow:raiseOnDivideByZero:", uint, short, bool, bool, bool, bool)(roundingMode, scale, exact, overflow, underflow, divideByZero);
 	}
 
 	uint roundingMode ()
@@ -312,13 +349,7 @@
 
 	this (NSCoder aDecoder)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithCoder(aDecoder);
 	}
 }
 
@@ -327,21 +358,4 @@
 	uint roundingMode ();
 	short scale ();
 	NSDecimalNumber exceptionDuringOperation (SEL operation, uint error, NSDecimalNumber leftOperand, NSDecimalNumber rightOperand);
-}
-
-template TNSDecimalNumberExtensions ()
-{
-	NSDecimal decimalValue ()
-	{
-		return invokeObjcSelf!(NSDecimal, "decimalValue");
-	}
-}
-
-template TNSDecimalNumberScanning ()
-{
-	bool scanDecimal (NSDecimal* dcm)
-	{
-		return invokeObjcSelf!(bool, "scanDecimal:", NSDecimal*)(dcm);
-	}
-}
-
+}
\ No newline at end of file