diff dstep/foundation/NSBundle.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/NSBundle.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSBundle.d	Sun Jan 03 22:06:11 2010 +0100
@@ -12,12 +12,33 @@
 import dstep.foundation.NSObject;
 import dstep.foundation.NSString;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
+
+
 
 import bindings = dstep.foundation.NSBundle_bindings;
 
-const NSString NSBundleDidLoadNotification;
-const NSString NSLoadedClasses;
+private
+{
+	NSString NSBundleDidLoadNotification_;
+	NSString NSLoadedClasses_;
+}
+
+NSString NSBundleDidLoadNotification ()
+{
+	if (NSBundleDidLoadNotification_)
+		return NSBundleDidLoadNotification_;
+	
+	return NSBundleDidLoadNotification_ = new NSString(bindings.NSBundleDidLoadNotification);
+}
+
+NSString NSLoadedClasses ()
+{
+	if (NSLoadedClasses_)
+		return NSLoadedClasses_;
+	
+	return NSLoadedClasses_ = new NSString(bindings.NSLoadedClasses);
+}
 
 enum
 {
@@ -27,24 +48,28 @@
 	NSBundleExecutableArchitecturePPC64 = 0x01000012
 }
 
-static this ()
-{
-	NSBundleDidLoadNotification = new NSString(bindings.NSBundleDidLoadNotification);
-	NSLoadedClasses = new NSString(bindings.NSLoadedClasses);
-}
-
 class NSBundle : NSObject
 {
-	mixin ObjcWrap;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	static NSBundle mainBundle ()
 	{
-		return invokeObjcSelfClass!(NSBundle, "mainBundle");
+		return invokeObjcSuperClass!(NSBundle, "mainBundle");
 	}
 
 	static NSBundle bundleWithPath (NSString path)
 	{
-		return invokeObjcSelfClass!(NSBundle, "bundleWithPath:", NSString)(path);
+		return invokeObjcSuperClass!(NSBundle, "bundleWithPath:", NSString)(path);
 	}
 
 	Object initWithPath (NSString path)
@@ -54,33 +79,27 @@
 
 	this (NSString path)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithPath:", NSString)(objcObject, path);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithPath(path);
 	}
 
 	static NSBundle bundleForClass (Class aClass)
 	{
-		return invokeObjcSelfClass!(NSBundle, "bundleForClass:", Class)(aClass);
+		return invokeObjcSuperClass!(NSBundle, "bundleForClass:", Class)(aClass);
 	}
 
 	static NSBundle bundleWithIdentifier (NSString identifier)
 	{
-		return invokeObjcSelfClass!(NSBundle, "bundleWithIdentifier:", NSString)(identifier);
+		return invokeObjcSuperClass!(NSBundle, "bundleWithIdentifier:", NSString)(identifier);
 	}
 
 	static NSArray allBundles ()
 	{
-		return invokeObjcSelfClass!(NSArray, "allBundles");
+		return invokeObjcSuperClass!(NSArray, "allBundles");
 	}
 
 	static NSArray allFrameworks ()
 	{
-		return invokeObjcSelfClass!(NSArray, "allFrameworks");
+		return invokeObjcSuperClass!(NSArray, "allFrameworks");
 	}
 
 	bool load ()
@@ -98,14 +117,34 @@
 		return invokeObjcSelf!(bool, "unload");
 	}
 
-	bool preflightAndReturnError (NSError** error)
+	bool preflightAndReturnError (ref NSError error)
 	{
-		return invokeObjcSelf!(bool, "preflightAndReturnError:", NSError**)(error);
+		id err;
+		
+		if (error)
+			err = new objc_object;
+		
+		bool result = invokeObjcSelf!(bool, "preflightAndReturnError:", id*)(&err);
+		
+		if (err)
+			error = new NSError(err);
+		
+		return result;
 	}
 
-	bool loadAndReturnError (NSError** error)
+	bool loadAndReturnError (ref NSError error)
 	{
-		return invokeObjcSelf!(bool, "loadAndReturnError:", NSError**)(error);
+		id err;
+		
+		if (error)
+			err = new objc_object;
+		
+		bool result = invokeObjcSelf!(bool, "loadAndReturnError:", id*)(&err);
+		
+		if (err)
+			error = new NSError(err);
+		
+		return result;
 	}
 
 	NSString bundlePath ()
@@ -165,7 +204,7 @@
 
 	static NSString pathForResource (NSString name, NSString ext, NSString bundlePath)
 	{
-		return invokeObjcSelfClass!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, bundlePath);
+		return invokeObjcSuperClass!(NSString, "pathForResource:ofType:inDirectory:", NSString, NSString, NSString)(name, ext, bundlePath);
 	}
 
 	NSString pathForResource (NSString name, NSString ext)
@@ -185,7 +224,7 @@
 
 	static NSArray pathsForResourcesOfType (NSString ext, NSString bundlePath)
 	{
-		return invokeObjcSelfClass!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, bundlePath);
+		return invokeObjcSuperClass!(NSArray, "pathsForResourcesOfType:inDirectory:", NSString, NSString)(ext, bundlePath);
 	}
 
 	NSArray pathsForResourcesOfType (NSString ext, NSString subpath)
@@ -235,12 +274,12 @@
 
 	static NSArray preferredLocalizationsFromArray (NSArray localizationsArray)
 	{
-		return invokeObjcSelfClass!(NSArray, "preferredLocalizationsFromArray:", NSArray)(localizationsArray);
+		return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:", NSArray)(localizationsArray);
 	}
 
 	static NSArray preferredLocalizationsFromArray (NSArray localizationsArray, NSArray preferencesArray)
 	{
-		return invokeObjcSelfClass!(NSArray, "preferredLocalizationsFromArray:forPreferences:", NSArray, NSArray)(localizationsArray, preferencesArray);
+		return invokeObjcSuperClass!(NSArray, "preferredLocalizationsFromArray:forPreferences:", NSArray, NSArray)(localizationsArray, preferencesArray);
 	}
 
 	NSArray executableArchitectures ()