diff dstep/foundation/NSFileHandle.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 diff
--- a/dstep/foundation/NSFileHandle.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSFileHandle.d	Sun Jan 03 22:06:11 2010 +0100
@@ -8,38 +8,213 @@
 
 import dstep.foundation.NSArray;
 import dstep.foundation.NSData;
+import dstep.foundation.NSObjCRuntime;
 import dstep.foundation.NSObject;
 import dstep.foundation.NSRange;
 import dstep.foundation.NSString;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
 
 import bindings = dstep.foundation.NSFileHandle_bindings;
 
-const NSString NSFileHandleOperationException;
-const NSString NSFileHandleReadCompletionNotification;
-const NSString NSFileHandleReadToEndOfFileCompletionNotification;
-const NSString NSFileHandleConnectionAcceptedNotification;
-const NSString NSFileHandleDataAvailableNotification;
-const NSString NSFileHandleNotificationDataItem;
-const NSString NSFileHandleNotificationFileHandleItem;
-const NSString NSFileHandleNotificationMonitorModes;
+private
+{
+	NSString NSFileHandleOperationException_;
+	NSString NSFileHandleReadCompletionNotification_;
+	NSString NSFileHandleReadToEndOfFileCompletionNotification_;
+	NSString NSFileHandleConnectionAcceptedNotification_;
+	NSString NSFileHandleDataAvailableNotification_;
+	NSString NSFileHandleNotificationDataItem_;
+	NSString NSFileHandleNotificationFileHandleItem_;
+	NSString NSFileHandleNotificationMonitorModes_;
+}
+
+NSString NSFileHandleOperationException ()
+{
+	if (NSFileHandleOperationException_)
+		return NSFileHandleOperationException_;
+		
+	return NSFileHandleOperationException_ = new NSString(bindings.NSFileHandleOperationException);
+}
+
+NSString NSFileHandleReadCompletionNotification ()
+{
+	if (NSFileHandleReadCompletionNotification_)
+		return NSFileHandleReadCompletionNotification_;
+		
+	return NSFileHandleReadCompletionNotification_ = new NSString(bindings.NSFileHandleReadCompletionNotification);
+}
+
+NSString NSFileHandleReadToEndOfFileCompletionNotification ()
+{
+	if (NSFileHandleReadToEndOfFileCompletionNotification_)
+		return NSFileHandleReadToEndOfFileCompletionNotification_;
+		
+	return NSFileHandleReadToEndOfFileCompletionNotification_ = new NSString(bindings.NSFileHandleReadToEndOfFileCompletionNotification);
+}
+
+NSString NSFileHandleConnectionAcceptedNotification ()
+{
+	if (NSFileHandleConnectionAcceptedNotification_)
+		return NSFileHandleConnectionAcceptedNotification_;
+		
+	return NSFileHandleConnectionAcceptedNotification_ = new NSString(bindings.NSFileHandleConnectionAcceptedNotification);
+}
+
+NSString NSFileHandleDataAvailableNotification ()
+{
+	if (NSFileHandleDataAvailableNotification_)
+		return NSFileHandleDataAvailableNotification_;
+		
+	return NSFileHandleDataAvailableNotification_ = new NSString(bindings.NSFileHandleDataAvailableNotification);
+}
+
+NSString NSFileHandleNotificationDataItem ()
+{
+	if (NSFileHandleNotificationDataItem_)
+		return NSFileHandleNotificationDataItem_;
+		
+	return NSFileHandleNotificationDataItem_ = new NSString(bindings.NSFileHandleNotificationDataItem);
+}
+
+NSString NSFileHandleNotificationFileHandleItem ()
+{
+	if (NSFileHandleNotificationFileHandleItem_)
+		return NSFileHandleNotificationFileHandleItem_;
+		
+	return NSFileHandleNotificationFileHandleItem_ = new NSString(bindings.NSFileHandleNotificationFileHandleItem);
+}
+
+NSString NSFileHandleNotificationMonitorModes ()
+{
+	if (NSFileHandleNotificationMonitorModes_)
+		return NSFileHandleNotificationMonitorModes_;
+		
+	return NSFileHandleNotificationMonitorModes_ = new NSString(bindings.NSFileHandleNotificationMonitorModes);
+}
+
+const TNSFileHandleAsynchronousAccess = `
+
+	void readInBackgroundAndNotifyForModes (NSArray modes)
+	{
+		return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes);
+	}
+
+	void readInBackgroundAndNotify ()
+	{
+		return invokeObjcSelf!(void, "readInBackgroundAndNotify");
+	}
 
-static this ()
-{
-	NSFileHandleOperationException = new NSString(bindings.NSFileHandleOperationException);
-	NSFileHandleReadCompletionNotification = new NSString(bindings.NSFileHandleReadCompletionNotification);
-	NSFileHandleReadToEndOfFileCompletionNotification = new NSString(bindings.NSFileHandleReadToEndOfFileCompletionNotification);
-	NSFileHandleConnectionAcceptedNotification = new NSString(bindings.NSFileHandleConnectionAcceptedNotification);
-	NSFileHandleDataAvailableNotification = new NSString(bindings.NSFileHandleDataAvailableNotification);
-	NSFileHandleNotificationDataItem = new NSString(bindings.NSFileHandleNotificationDataItem);
-	NSFileHandleNotificationFileHandleItem = new NSString(bindings.NSFileHandleNotificationFileHandleItem);
-	NSFileHandleNotificationMonitorModes = new NSString(bindings.NSFileHandleNotificationMonitorModes);
-}
+	void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes)
+	{
+		return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes);
+	}
+
+	void readToEndOfFileInBackgroundAndNotify ()
+	{
+		return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify");
+	}
+
+	void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes)
+	{
+		return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes);
+	}
+
+	void acceptConnectionInBackgroundAndNotify ()
+	{
+		return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify");
+	}
+
+	void waitForDataInBackgroundAndNotifyForModes (NSArray modes)
+	{
+		return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes);
+	}
+
+	void waitForDataInBackgroundAndNotify ()
+	{
+		return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify");
+	}
+`;
+
+const TNSFileHandleCreation = `
+
+	static Object fileHandleWithStandardInput ()
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardInput");
+	}
+
+	static Object fileHandleWithStandardOutput ()
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardOutput");
+	}
+
+	static Object fileHandleWithStandardError ()
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardError");
+	}
+
+	static Object fileHandleWithNullDevice ()
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleWithNullDevice");
+	}
+
+	static Object fileHandleForReadingAtPath (NSString path)
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
+	}
+
+	static Object fileHandleForWritingAtPath (NSString path)
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
+	}
+
+	static Object fileHandleForUpdatingAtPath (NSString path)
+	{
+		return invokeObjcSuperClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
+	}
+`;
+
+const TNSFileHandlePlatformSpecific = `
+
+	Object initWithFileDescriptor (int fd, bool closeopt)
+	{
+		return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt);
+	}
+
+	this (int fd, bool closeopt)
+	{
+		typeof(this).alloc.initWithFileDescriptor(fd, closeopt);
+	}
+
+	Object initWithFileDescriptor (int fd)
+	{
+		return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd);
+	}
+
+	this (int fd)
+	{
+		typeof(this).alloc.initWithFileDescriptor(fd);
+	}
+
+	int fileDescriptor ()
+	{
+		return invokeObjcSelf!(int, "fileDescriptor");
+	}
+`;
 
 class NSPipe : NSObject
 {
-	mixin ObjcWrap;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	NSFileHandle fileHandleForReading ()
 	{
@@ -51,34 +226,25 @@
 		return invokeObjcSelf!(NSFileHandle, "fileHandleForWriting");
 	}
 
-	Object init ()
-	{
-		return invokeObjcSelf!(Object, "init");
-	}
-
-	this ()
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "init")(objcObject);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
-	}
-
 	static Object pipe ()
 	{
-		return invokeObjcSelfClass!(Object, "pipe");
+		return invokeObjcSuperClass!(Object, "pipe");
 	}
 }
 
 class NSFileHandle : NSObject
 {
-	mixin ObjcWrap;
-	mixin TNSFileHandleAsynchronousAccess;
-	mixin TNSFileHandleCreation;
-	mixin TNSFileHandlePlatformSpecific;
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
 
 	NSData availableData ()
 	{
@@ -129,126 +295,107 @@
 	{
 		return invokeObjcSelf!(void, "closeFile");
 	}
-}
-
-template TNSFileHandleAsynchronousAccess ()
-{
+	
+	// TNSFileHandleAsynchronousAccess
 	void readInBackgroundAndNotifyForModes (NSArray modes)
 	{
 		return invokeObjcSelf!(void, "readInBackgroundAndNotifyForModes:", NSArray)(modes);
 	}
-
+	
 	void readInBackgroundAndNotify ()
 	{
 		return invokeObjcSelf!(void, "readInBackgroundAndNotify");
 	}
-
+	
 	void readToEndOfFileInBackgroundAndNotifyForModes (NSArray modes)
 	{
 		return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotifyForModes:", NSArray)(modes);
 	}
-
+	
 	void readToEndOfFileInBackgroundAndNotify ()
 	{
 		return invokeObjcSelf!(void, "readToEndOfFileInBackgroundAndNotify");
 	}
-
+	
 	void acceptConnectionInBackgroundAndNotifyForModes (NSArray modes)
 	{
 		return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotifyForModes:", NSArray)(modes);
 	}
-
+	
 	void acceptConnectionInBackgroundAndNotify ()
 	{
 		return invokeObjcSelf!(void, "acceptConnectionInBackgroundAndNotify");
 	}
-
+	
 	void waitForDataInBackgroundAndNotifyForModes (NSArray modes)
 	{
 		return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotifyForModes:", NSArray)(modes);
 	}
-
+	
 	void waitForDataInBackgroundAndNotify ()
 	{
 		return invokeObjcSelf!(void, "waitForDataInBackgroundAndNotify");
 	}
-}
-
-template TNSFileHandleCreation ()
-{
+	
+	// TNSFileHandleCreation
 	static Object fileHandleWithStandardInput ()
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleWithStandardInput");
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardInput");
 	}
-
+	
 	static Object fileHandleWithStandardOutput ()
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleWithStandardOutput");
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardOutput");
 	}
-
+	
 	static Object fileHandleWithStandardError ()
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleWithStandardError");
+		return invokeObjcSuperClass!(Object, "fileHandleWithStandardError");
 	}
-
+	
 	static Object fileHandleWithNullDevice ()
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleWithNullDevice");
+		return invokeObjcSuperClass!(Object, "fileHandleWithNullDevice");
 	}
-
+	
 	static Object fileHandleForReadingAtPath (NSString path)
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
+		return invokeObjcSuperClass!(Object, "fileHandleForReadingAtPath:", NSString)(path);
 	}
-
+	
 	static Object fileHandleForWritingAtPath (NSString path)
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
+		return invokeObjcSuperClass!(Object, "fileHandleForWritingAtPath:", NSString)(path);
 	}
-
+	
 	static Object fileHandleForUpdatingAtPath (NSString path)
 	{
-		return invokeObjcSelfClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
+		return invokeObjcSuperClass!(Object, "fileHandleForUpdatingAtPath:", NSString)(path);
 	}
-}
-
-template TNSFileHandlePlatformSpecific ()
-{
+	
+	// TNSFileHandlePlatformSpecific
 	Object initWithFileDescriptor (int fd, bool closeopt)
 	{
 		return invokeObjcSelf!(Object, "initWithFileDescriptor:closeOnDealloc:", int, bool)(fd, closeopt);
 	}
-
+	
 	this (int fd, bool closeopt)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:closeOnDealloc:", int, bool)(objcObject, fd, closeopt);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithFileDescriptor(fd, closeopt);
 	}
-
+	
 	Object initWithFileDescriptor (int fd)
 	{
 		return invokeObjcSelf!(Object, "initWithFileDescriptor:", int)(fd);
 	}
-
+	
 	this (int fd)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithFileDescriptor:", int)(objcObject, fd);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithFileDescriptor(fd);
 	}
-
+	
 	int fileDescriptor ()
 	{
 		return invokeObjcSelf!(int, "fileDescriptor");
 	}
-}
-
+}
\ No newline at end of file