view dstep/foundation/NSSet.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
line wrap: on
line source

/**
 * 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.NSSet;

import dstep.foundation.NSArray;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSEnumerator;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc : id;

class NSSet : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration
{
	mixin ObjcWrap;
	mixin TNSSetCreation;
	mixin TNSExtendedSet;
	mixin TNSKeyValueObserverRegistration;

	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)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);

		if (result)
			objcObject = ret;

		dObject = this;
	}

	NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len)
	{
		return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len);
	}
}

class NSMutableSet : NSSet
{
	mixin ObjcWrap;
	mixin TNSPredicateSupport;
	mixin TNSMutableSetCreation;
	mixin TNSExtendedMutableSet;

	void addObject (Object object)
	{
		return invokeObjcSelf!(void, "addObject:", Object)(object);
	}

	void removeObject (Object object)
	{
		return invokeObjcSelf!(void, "removeObject:", Object)(object);
	}
}

class NSCountedSet : NSMutableSet
{
	mixin ObjcWrap;

	Object initWithCapacity (NSUInteger numItems)
	{
		return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
	}

	this (NSUInteger numItems)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);

		if (result)
			objcObject = ret;

		dObject = this;
	}

	Object initWithArray (NSArray array)
	{
		return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
	}

	this (NSArray array)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);

		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;
	}

	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;
	}

	Object initWithSet (NSSet set, bool flag)
	{
		return invokeObjcSelf!(Object, "initWithSet:copyItems:", NSSet, bool)(set, flag);
	}

	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;
	}

	Object initWithArray (NSArray array)
	{
		return invokeObjcSelf!(Object, "initWithArray:", NSArray)(array);
	}

	this (NSArray array)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithArray:", NSArray)(objcObject, array);

		if (result)
			objcObject = ret;

		dObject = this;
	}
}

template 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);
	}
}

template TNSMutableSetCreation ()
{
	static Object setWithCapacity (NSUInteger numItems)
	{
		return invokeObjcSelfClass!(Object, "setWithCapacity:", NSUInteger)(numItems);
	}

	Object initWithCapacity (NSUInteger numItems)
	{
		return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems);
	}

	this (NSUInteger numItems)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems);

		if (result)
			objcObject = ret;

		dObject = this;
	}
}

template 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);
	}
}