diff dstep/foundation/NSSet.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/NSSet.d	Mon Aug 03 15:31:48 2009 +0200
+++ b/dstep/foundation/NSSet.d	Sun Jan 03 22:06:11 2010 +0100
@@ -7,124 +7,68 @@
 module dstep.foundation.NSSet;
 
 import dstep.foundation.NSArray;
+import dstep.foundation.NSCoder;
 import dstep.foundation.NSDictionary;
 import dstep.foundation.NSEnumerator;
+import dstep.foundation.NSKeyValueObserving;
 import dstep.foundation.NSObject;
+import dstep.foundation.NSObjCRuntime;
+import dstep.foundation.NSPredicate;
 import dstep.foundation.NSString;
+import dstep.foundation.NSZone;
 import dstep.objc.bridge.Bridge;
-import dstep.objc.objc : id;
+import dstep.objc.objc;
 
-class NSSet : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
-{
-	mixin ObjcWrap;
-	mixin TNSSetCreation;
-	mixin TNSExtendedSet;
-	mixin TNSKeyValueObserverRegistration;
+const TNSSetCreation = `
 
-	NSUInteger count ()
+	static Object set ()
 	{
-		return invokeObjcSelf!(NSUInteger, "count");
-	}
-
-	Object member (Object object)
-	{
-		return invokeObjcSelf!(Object, "member:", Object)(object);
+		return invokeObjcSuperClass!(Object, "set");
 	}
 
-	NSEnumerator objectEnumerator ()
+	static Object setWithObject (Object object)
 	{
-		return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
-	}
-
-	Object copyWithZone (NSZone* zone)
-	{
-		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
+		return invokeObjcSuperClass!(Object, "setWithObject:", Object)(object);
 	}
 
-	Object mutableCopyWithZone (NSZone* zone)
-	{
-		return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone);
-	}
-
-	void encodeWithCoder (NSCoder aCoder)
+	static Object setWithObjects (id* objects, NSUInteger cnt)
 	{
-		return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
-	}
-
-	Object initWithCoder (NSCoder aDecoder)
-	{
-		return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
+		return invokeObjcSuperClass!(Object, "setWithObjects:count:", id*, NSUInteger)(objects, cnt);
 	}
 
-	this (NSCoder aDecoder)
+	static Object setWithObjects (Object setWithObjects, ...)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		return invokeObjcSuperClass!(Object, "setWithObjects:", Object)(setWithObjects);
 	}
 
-	NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
+	static Object setWithSet (NSSet set)
 	{
-		return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
+		return invokeObjcSuperClass!(Object, "setWithSet:", NSSet)(set);
 	}
-}
 
-class NSMutableSet : NSSet
-{
-	mixin ObjcWrap;
-	mixin TNSPredicateSupport;
-	mixin TNSMutableSetCreation;
-	mixin TNSExtendedMutableSet;
-
-	void addObject (Object object)
+	static Object setWithArray (NSArray array)
 	{
-		return invokeObjcSelf!(void, "addObject:", Object)(object);
+		return invokeObjcSuperClass!(Object, "setWithArray:", NSArray)(array);
 	}
 
-	void removeObject (Object object)
+	Object initWithObjects (id* objects, NSUInteger cnt)
 	{
-		return invokeObjcSelf!(void, "removeObject:", Object)(object);
-	}
-}
-
-class NSCountedSet : NSMutableSet
-{
-	mixin ObjcWrap;
-
-	Object initWithCapacity (NSUInteger numItems)
-	{
-		return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
+		return invokeObjcSelf!(Object, "initWithObjects:count:", id*, NSUInteger)(objects, cnt);
 	}
 
-	this (NSUInteger numItems)
+	this (id* objects, NSUInteger cnt)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithObjects(objects, cnt);
 	}
 
-	Object initWithArray (NSArray array)
+	Object initWithObjects (Object initWithObjects, ...)
 	{
-		return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
+		return invokeObjcSelf!(Object, "initWithObjects:", Object)(initWithObjects);
 	}
 
-	this (NSArray array)
+	this (Object initWithObjects, ...)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithObjects(initWithObjects);
 	}
 
 	Object initWithSet (NSSet set)
@@ -134,114 +78,7 @@
 
 	this (NSSet set)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithSet:", NSSet)(objcObject, set);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
-	}
-
-	NSUInteger countForObject (Object object)
-	{
-		return invokeObjcSelf!(NSUInteger, "countForObject:", Object)(object);
-	}
-
-	NSEnumerator objectEnumerator ()
-	{
-		return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
-	}
-
-	void addObject (Object object)
-	{
-		return invokeObjcSelf!(void, "addObject:", Object)(object);
-	}
-
-	void removeObject (Object object)
-	{
-		return invokeObjcSelf!(void, "removeObject:", Object)(object);
-	}
-}
-
-template TNSSetCreation ()
-{
-	static Object set ()
-	{
-		return invokeObjcSelfClass!(Object, "set");
-	}
-
-	static Object setWithObject (Object object)
-	{
-		return invokeObjcSelfClass!(Object, "setWithObject:", Object)(object);
-	}
-
-	static Object setWithObjects (id* objects, NSUInteger cnt)
-	{
-		return invokeObjcSelfClass!(Object, "setWithObjects:count:", id*, NSUInteger)(objects, cnt);
-	}
-
-	static Object setWithObjects (Object setWithObjects, ...)
-	{
-		return invokeObjcSelfClass!(Object, "setWithObjects:", Object)(setWithObjects);
-	}
-
-	static Object setWithSet (NSSet set)
-	{
-		return invokeObjcSelfClass!(Object, "setWithSet:", NSSet)(set);
-	}
-
-	static Object setWithArray (NSArray array)
-	{
-		return invokeObjcSelfClass!(Object, "setWithArray:", NSArray)(array);
-	}
-
-	Object initWithObjects (id* objects, NSUInteger cnt)
-	{
-		return invokeObjcSelf!(Object, "initWithObjects:count:", id*, NSUInteger)(objects, cnt);
-	}
-
-	this (id* objects, NSUInteger cnt)
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithObjects:count:", id*, NSUInteger)(objcObject, objects, cnt);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
-	}
-
-	Object initWithObjects (Object initWithObjects, ...)
-	{
-		return invokeObjcSelf!(Object, "initWithObjects:", Object)(initWithObjects);
-	}
-
-	this (Object initWithObjects, ...)
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithObjects:", Object)(objcObject, initWithObjects);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
-	}
-
-	Object initWithSet (NSSet set)
-	{
-		return invokeObjcSelf!(Object, "initWithSet:", NSSet)(set);
-	}
-
-	this (NSSet set)
-	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithSet:", NSSet)(objcObject, set);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithSet(set);
 	}
 
 	Object initWithSet (NSSet set, bool flag)
@@ -251,13 +88,7 @@
 
 	this (NSSet set, bool flag)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithSet:copyItems:", NSSet, bool)(objcObject, set, flag);
-
-		if (result)
-			objcObject = ret;
-
-		dObject = this;
+		typeof(this).alloc.initWithSet(set, flag);
 	}
 
 	Object initWithArray (NSArray array)
@@ -267,18 +98,12 @@
 
 	this (NSArray array)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);
-
-		if (result)
-			objcObject = ret;
+		typeof(this).alloc.initWithArray(array);
+	}
+`;
 
-		dObject = this;
-	}
-}
+const TNSExtendedSet = `
 
-template TNSExtendedSet ()
-{
 	NSArray allObjects ()
 	{
 		return invokeObjcSelf!(NSArray, "allObjects");
@@ -343,13 +168,13 @@
 	{
 		return invokeObjcSelf!(NSSet, "setByAddingObjectsFromArray:", NSArray)(other);
 	}
-}
+`;
 
-template TNSMutableSetCreation ()
-{
+const TNSMutableSetCreation = `
+
 	static Object setWithCapacity (NSUInteger numItems)
 	{
-		return invokeObjcSelfClass!(Object, "setWithCapacity:", NSUInteger)(numItems);
+		return invokeObjcSuperClass!(Object, "setWithCapacity:", NSUInteger)(numItems);
 	}
 
 	Object initWithCapacity (NSUInteger numItems)
@@ -359,18 +184,12 @@
 
 	this (NSUInteger numItems)
 	{
-		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
-		id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);
-
-		if (result)
-			objcObject = ret;
+		typeof(this).alloc.initWithCapacity(numItems);
+	}
+`;
 
-		dObject = this;
-	}
-}
+const TNSExtendedMutableSet = `
 
-template TNSExtendedMutableSet ()
-{
 	void addObjectsFromArray (NSArray array)
 	{
 		return invokeObjcSelf!(void, "addObjectsFromArray:", NSArray)(array);
@@ -400,5 +219,365 @@
 	{
 		return invokeObjcSelf!(void, "setSet:", NSSet)(otherSet);
 	}
+`;
+
+class NSSet : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
+{
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
+
+	NSUInteger count ()
+	{
+		return invokeObjcSelf!(NSUInteger, "count");
+	}
+
+	Object member (Object object)
+	{
+		return invokeObjcSelf!(Object, "member:", Object)(object);
+	}
+
+	NSEnumerator objectEnumerator ()
+	{
+		return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
+	}
+
+	Object copyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
+	}
+
+	Object mutableCopyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(Object, "mutableCopyWithZone:", 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);
+	}
+
+	NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
+	{
+		return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
+	}
+	
+	// TNSSetCreation
+	static Object set ()
+	{
+		return invokeObjcSuperClass!(Object, "set");
+	}
+	
+	static Object setWithObject (Object object)
+	{
+		return invokeObjcSuperClass!(Object, "setWithObject:", Object)(object);
+	}
+	
+	static Object setWithObjects (id* objects, NSUInteger cnt)
+	{
+		return invokeObjcSuperClass!(Object, "setWithObjects:count:", id*, NSUInteger)(objects, cnt);
+	}
+	
+	static Object setWithObjects (Object setWithObjects, ...)
+	{
+		return invokeObjcSuperClass!(Object, "setWithObjects:", Object)(setWithObjects);
+	}
+	
+	static Object setWithSet (NSSet set)
+	{
+		return invokeObjcSuperClass!(Object, "setWithSet:", NSSet)(set);
+	}
+	
+	static Object setWithArray (NSArray array)
+	{
+		return invokeObjcSuperClass!(Object, "setWithArray:", NSArray)(array);
+	}
+	
+	Object initWithObjects (id* objects, NSUInteger cnt)
+	{
+		return invokeObjcSelf!(Object, "initWithObjects:count:", id*, NSUInteger)(objects, cnt);
+	}
+	
+	this (id* objects, NSUInteger cnt)
+	{
+		typeof(this).alloc.initWithObjects(objects, cnt);
+	}
+	
+	Object initWithObjects (Object initWithObjects, ...)
+	{
+		return invokeObjcSelf!(Object, "initWithObjects:", Object)(initWithObjects);
+	}
+	
+	this (Object initWithObjects, ...)
+	{
+		typeof(this).alloc.initWithObjects(initWithObjects);
+	}
+	
+	Object initWithSet (NSSet set)
+	{
+		return invokeObjcSelf!(Object, "initWithSet:", NSSet)(set);
+	}
+	
+	this (NSSet set)
+	{
+		typeof(this).alloc.initWithSet(set);
+	}
+	
+	Object initWithSet (NSSet set, bool flag)
+	{
+		return invokeObjcSelf!(Object, "initWithSet:copyItems:", NSSet, bool)(set, flag);
+	}
+	
+	this (NSSet set, bool flag)
+	{
+		typeof(this).alloc.initWithSet(set, flag);
+	}
+	
+	Object initWithArray (NSArray array)
+	{
+		return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
+	}
+	
+	this (NSArray array)
+	{
+		typeof(this).alloc.initWithArray(array);
+	}
+	
+	// TNSExtendedSet
+	NSArray allObjects ()
+	{
+		return invokeObjcSelf!(NSArray, "allObjects");
+	}
+	
+	Object anyObject ()
+	{
+		return invokeObjcSelf!(Object, "anyObject");
+	}
+	
+	bool containsObject (Object anObject)
+	{
+		return invokeObjcSelf!(bool, "containsObject:", Object)(anObject);
+	}
+	
+	NSString description ()
+	{
+		return invokeObjcSelf!(NSString, "description");
+	}
+	
+	NSString descriptionWithLocale (Object locale)
+	{
+		return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale);
+	}
+	
+	bool intersectsSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(bool, "intersectsSet:", NSSet)(otherSet);
+	}
+	
+	bool isEqualToSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(bool, "isEqualToSet:", NSSet)(otherSet);
+	}
+	
+	bool isSubsetOfSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(bool, "isSubsetOfSet:", NSSet)(otherSet);
+	}
+	
+	void makeObjectsPerformSelector (SEL aSelector)
+	{
+		return invokeObjcSelf!(void, "makeObjectsPerformSelector:", SEL)(aSelector);
+	}
+	
+	void makeObjectsPerformSelector (SEL aSelector, Object argument)
+	{
+		return invokeObjcSelf!(void, "makeObjectsPerformSelector:withObject:", SEL, Object)(aSelector, argument);
+	}
+	
+	NSSet setByAddingObject (Object anObject)
+	{
+		return invokeObjcSelf!(NSSet, "setByAddingObject:", Object)(anObject);
+	}
+	
+	NSSet setByAddingObjectsFromSet (NSSet other)
+	{
+		return invokeObjcSelf!(NSSet, "setByAddingObjectsFromSet:", NSSet)(other);
+	}
+	
+	NSSet setByAddingObjectsFromArray (NSArray other)
+	{
+		return invokeObjcSelf!(NSSet, "setByAddingObjectsFromArray:", NSArray)(other);
+	}
+	
+	// TNSKeyValueObserverRegistration
+	void addObserver (NSObject observer, NSString keyPath, uint options, void* context)
+	{
+		return invokeObjcSelf!(void, "addObserver:forKeyPath:options:context:", NSObject, NSString, uint, void*)(observer, keyPath, options, context);
+	}
+	
+	void removeObserver (NSObject observer, NSString keyPath)
+	{
+		return invokeObjcSelf!(void, "removeObserver:forKeyPath:", NSObject, NSString)(observer, keyPath);
+	}
 }
 
+class NSMutableSet : NSSet
+{
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
+
+	void addObject (Object object)
+	{
+		return invokeObjcSelf!(void, "addObject:", Object)(object);
+	}
+
+	void removeObject (Object object)
+	{
+		return invokeObjcSelf!(void, "removeObject:", Object)(object);
+	}
+	
+	// TNSPredicateSupport
+	void filterUsingPredicate (NSPredicate predicate)
+	{
+		return invokeObjcSelf!(void, "filterUsingPredicate:", NSPredicate)(predicate);
+	}
+	
+	// TNSMutableSetCreation
+	static Object setWithCapacity (NSUInteger numItems)
+	{
+		return invokeObjcSuperClass!(Object, "setWithCapacity:", NSUInteger)(numItems);
+	}
+	
+	Object initWithCapacity (NSUInteger numItems)
+	{
+		return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
+	}
+	
+	this (NSUInteger numItems)
+	{
+		typeof(this).alloc.initWithCapacity(numItems);
+	}
+	
+	// TNSExtendedMutableSet
+	void addObjectsFromArray (NSArray array)
+	{
+		return invokeObjcSelf!(void, "addObjectsFromArray:", NSArray)(array);
+	}
+	
+	void intersectSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(void, "intersectSet:", NSSet)(otherSet);
+	}
+	
+	void minusSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(void, "minusSet:", NSSet)(otherSet);
+	}
+	
+	void removeAllObjects ()
+	{
+		return invokeObjcSelf!(void, "removeAllObjects");
+	}
+	
+	void unionSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(void, "unionSet:", NSSet)(otherSet);
+	}
+	
+	void setSet (NSSet otherSet)
+	{
+		return invokeObjcSelf!(void, "setSet:", NSSet)(otherSet);
+	}
+}
+
+class NSCountedSet : NSMutableSet
+{
+	mixin (ObjcWrap);
+	
+	this ()
+	{
+		super(typeof(this).alloc.init.objcObject);
+	}
+	
+	typeof(this) init ()
+	{
+		return invokeObjcSelf!(typeof(this), "init");
+	}
+
+	Object initWithCapacity (NSUInteger numItems)
+	{
+		return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
+	}
+
+	this (NSUInteger numItems)
+	{
+		typeof(this).alloc.initWithCapacity(numItems);
+	}
+
+	Object initWithArray (NSArray array)
+	{
+		return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
+	}
+
+	this (NSArray array)
+	{
+		typeof(this).alloc.initWithArray(array);
+	}
+
+	Object initWithSet (NSSet set)
+	{
+		return invokeObjcSelf!(Object, "initWithSet:", NSSet)(set);
+	}
+
+	this (NSSet set)
+	{
+		typeof(this).alloc.initWithSet(set);
+	}
+
+	NSUInteger countForObject (Object object)
+	{
+		return invokeObjcSelf!(NSUInteger, "countForObject:", Object)(object);
+	}
+
+	NSEnumerator objectEnumerator ()
+	{
+		return invokeObjcSelf!(NSEnumerator, "objectEnumerator");
+	}
+
+	void addObject (Object object)
+	{
+		return invokeObjcSelf!(void, "addObject:", Object)(object);
+	}
+
+	void removeObject (Object object)
+	{
+		return invokeObjcSelf!(void, "removeObject:", Object)(object);
+	}
+}
\ No newline at end of file