diff dstep/foundation/NSException.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 7ff919f595d5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSException.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,172 @@
+/**
+ * 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.NSException;
+
+import dstep.foundation.NSArray;
+import dstep.foundation.NSAssertionHandler;
+import dstep.foundation.NSDictionary;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSString;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+import dstep.setjmp;
+import dstep.stdarg;
+
+import bindings = dstep.foundation.NSException_bindings;
+
+extern (C)
+{
+	alias void function (id) NSUncaughtExceptionHandler *;
+}
+
+const NSString NSGenericException;
+const NSString NSRangeException;
+const NSString NSInvalidArgumentException;
+const NSString NSInternalInconsistencyException;
+const NSString NSMallocException;
+const NSString NSObjectInaccessibleException;
+const NSString NSObjectNotAvailableException;
+const NSString NSDestinationInvalidException;
+const NSString NSPortTimeoutException;
+const NSString NSInvalidSendPortException;
+const NSString NSInvalidReceivePortException;
+const NSString NSPortSendException;
+const NSString NSPortReceiveException;
+const NSString NSOldStyleException;
+
+static this ()
+{
+	NSGenericException = new NSString(bindings.NSGenericException);
+	NSRangeException = new NSString(bindings.NSRangeException);
+	NSInvalidArgumentException = new NSString(bindings.NSInvalidArgumentException);
+	NSInternalInconsistencyException = new NSString(bindings.NSInternalInconsistencyException);
+	NSMallocException = new NSString(bindings.NSMallocException);
+	NSObjectInaccessibleException = new NSString(bindings.NSObjectInaccessibleException);
+	NSObjectNotAvailableException = new NSString(bindings.NSObjectNotAvailableException);
+	NSDestinationInvalidException = new NSString(bindings.NSDestinationInvalidException);
+	NSPortTimeoutException = new NSString(bindings.NSPortTimeoutException);
+	NSInvalidSendPortException = new NSString(bindings.NSInvalidSendPortException);
+	NSInvalidReceivePortException = new NSString(bindings.NSInvalidReceivePortException);
+	NSPortSendException = new NSString(bindings.NSPortSendException);
+	NSPortReceiveException = new NSString(bindings.NSPortReceiveException);
+	NSOldStyleException = new NSString(bindings.NSOldStyleException);
+}
+
+class NSAssertionHandler : NSObject
+{
+	mixin ObjcWrap;
+
+	static NSAssertionHandler currentHandler ()
+	{
+		return invokeObjcSelfClass!(NSAssertionHandler, "currentHandler"return result is this.objcObject ? this : (result !is null ? new NSAssertionHandler(result) : null);	}
+
+	void handleFailureInMethod (SEL selector, Object object, NSString fileName, NSInteger line, NSString description, ...)
+	{
+		return invokeObjcSelf!(void, "handleFailureInMethod:object:file:lineNumber:description:", SEL, Object, NSString, NSInteger, NSString)(selector, object, fileName, line, description);
+	}
+
+	void handleFailureInFunction (NSString functionName, NSString fileName, NSInteger line, NSString description, ...)
+	{
+		return invokeObjcSelf!(void, "handleFailureInFunction:file:lineNumber:description:", NSString, NSString, NSInteger, NSString)(functionName, fileName, line, description);
+	}
+}
+
+class NSException : NSObject, INSCopying, INSCoding
+{
+	mixin ObjcWrap;
+	mixin TNSExceptionRaisingConveniences;
+
+	static NSException exceptionWithName (NSString name, NSString reason, NSDictionary userInfo)
+	{
+		return invokeObjcSelfClass!(NSException, "exceptionWithName:reason:userInfo:", NSString, NSString, NSDictionary)(name, reason, userInforeturn result is this.objcObject ? this : (result !is null ? new NSException(result) : null);	}
+
+	Object initWithName (NSString aName, NSString aReason, NSDictionary aUserInfo)
+	{
+		return invokeObjcSelf!(Object, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(aName, aReason, aUserInfo);
+	}
+
+	this (NSString aName, NSString aReason, NSDictionary aUserInfo)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(objcObject, aName, aReason, aUserInfo);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	NSString name ()
+	{
+		return invokeObjcSelf!(NSString, "name");
+	}
+
+	NSString reason ()
+	{
+		return invokeObjcSelf!(NSString, "reason");
+	}
+
+	NSDictionary userInfo ()
+	{
+		return invokeObjcSelf!(NSDictionary, "userInfo");
+	}
+
+	NSArray callStackReturnAddresses ()
+	{
+		return invokeObjcSelf!(NSArray, "callStackReturnAddresses");
+	}
+
+	void raise ()
+	{
+		return invokeObjcSelf!(void, "raise");
+	}
+
+	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)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+}
+
+template TNSExceptionRaisingConveniences ()
+{
+	static void raise (NSString name, NSString format, ...)
+	{
+		return invokeObjcSelfClass!(void, "raise:format:", NSString, NSString)(name, format);
+	}
+
+	static void raise (NSString name, NSString format, char* argList)
+	{
+		return invokeObjcSelfClass!(void, "raise:format:arguments:", NSString, NSString, char*)(name, format, argList);
+	}
+}
+
+extern (C)
+{
+	NSUncaughtExceptionHandler* NSGetUncaughtExceptionHandler ();
+	void NSSetUncaughtExceptionHandler (NSUncaughtExceptionHandler* dummy);
+}
\ No newline at end of file