view dstep/foundation/NSHashTable.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 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.NSHashTable;

import dstep.foundation.NSArray;
import dstep.foundation.NSCoder;
import dstep.foundation.NSEnumerator;
import dstep.foundation.NSHashTable;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSPointerFunctions;
import dstep.foundation.NSSet;
import dstep.foundation.NSString;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;



import bindings = dstep.foundation.NSHashTable_bindings;

alias NSUInteger NSHashTableOptions;

extern (C)
{
	extern
	{
		const NSHashTableCallBacks NSIntegerHashCallBacks;
		const NSHashTableCallBacks NSNonOwnedPointerHashCallBacks;
		const NSHashTableCallBacks NSNonRetainedObjectHashCallBacks;
		const NSHashTableCallBacks NSObjectHashCallBacks;
		const NSHashTableCallBacks NSOwnedObjectIdentityHashCallBacks;
		const NSHashTableCallBacks NSOwnedPointerHashCallBacks;
		const NSHashTableCallBacks NSPointerToStructHashCallBacks;
	}
}

enum
{
	NSHashTableStrongMemory = 0,
	NSHashTableZeroingWeakMemory = NSPointerFunctionsZeroingWeakMemory,
	NSHashTableCopyIn = NSPointerFunctionsCopyIn,
	NSHashTableObjectPointerPersonality = NSPointerFunctionsObjectPointerPersonality
}

struct NSHashEnumerator
{
	NSUInteger _pi;
	NSUInteger _si;
	void* _bs;
}


struct NSHashTableCallBacks
{
	extern (C) uint function (id table, /*const*/ void*) hash;
	extern (C) bool function (id table, /*const*/ void*, /*const*/ void*) isEqual;
	extern (C) void function (id table, /*const*/ void*) retain;
	extern (C) uint function (id table, void*) release;
	extern (C) id function (id table, /*const*/ void*) describe;	
}

class NSHashTable : NSObject, INSCopying, INSCoding, INSFastEnumeration
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	Object initWithOptions (uint options, NSUInteger initialCapacity)
	{
		return invokeObjcSelf!(Object, "initWithOptions:capacity:", uint, NSUInteger)(options, initialCapacity);
	}

	this (uint options, NSUInteger initialCapacity)
	{
		typeof(this).alloc.initWithOptions(options, initialCapacity);
	}

	Object initWithPointerFunctions (NSPointerFunctions functions, NSUInteger initialCapacity)
	{
		return invokeObjcSelf!(Object, "initWithPointerFunctions:capacity:", NSPointerFunctions, NSUInteger)(functions, initialCapacity);
	}

	this (NSPointerFunctions functions, NSUInteger initialCapacity)
	{
		typeof(this).alloc.initWithPointerFunctions(functions, initialCapacity);
	}

	static Object hashTableWithOptions (uint options)
	{
		return invokeObjcSuperClass!(Object, "hashTableWithOptions:", uint)(options);
	}

	static Object hashTableWithWeakObjects ()
	{
		return invokeObjcSuperClass!(Object, "hashTableWithWeakObjects");
	}

	NSPointerFunctions pointerFunctions ()
	{
		return invokeObjcSelf!(NSPointerFunctions, "pointerFunctions");
	}

	NSUInteger count ()
	{
		return invokeObjcSelf!(NSUInteger, "count");
	}

	Object member (Object object)
	{
		return invokeObjcSelf!(Object, "member:", 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);
	}

	void removeAllObjects ()
	{
		return invokeObjcSelf!(void, "removeAllObjects");
	}

	NSArray allObjects ()
	{
		return invokeObjcSelf!(NSArray, "allObjects");
	}

	Object anyObject ()
	{
		return invokeObjcSelf!(Object, "anyObject");
	}

	bool containsObject (Object anObject)
	{
		return invokeObjcSelf!(bool, "containsObject:", Object)(anObject);
	}

	bool intersectsHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(bool, "intersectsHashTable:", NSHashTable)(other);
	}

	bool isEqualToHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(bool, "isEqualToHashTable:", NSHashTable)(other);
	}

	bool isSubsetOfHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(bool, "isSubsetOfHashTable:", NSHashTable)(other);
	}

	void intersectHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(void, "intersectHashTable:", NSHashTable)(other);
	}

	void unionHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(void, "unionHashTable:", NSHashTable)(other);
	}

	void minusHashTable (NSHashTable other)
	{
		return invokeObjcSelf!(void, "minusHashTable:", NSHashTable)(other);
	}

	NSSet setRepresentation ()
	{
		return invokeObjcSelf!(NSSet, "setRepresentation");
	}

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

void NSFreeHashTable (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(void, bindings.NSFreeHashTable, NSHashTable)(table);
}

void NSResetHashTable (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(void, bindings.NSResetHashTable, NSHashTable)(table);
}

bool NSCompareHashTables (NSHashTable table1, NSHashTable table2)
{
	return Bridge.invokeObjcFunction!(bool, bindings.NSCompareHashTables, NSHashTable, NSHashTable)(table1, table2);
}

NSHashTable NSCopyHashTableWithZone (NSHashTable table, NSZone* zone)
{
	return Bridge.invokeObjcFunction!(NSHashTable, bindings.NSCopyHashTableWithZone, NSHashTable, NSZone*)(table, zone);
}

void* NSHashGet (NSHashTable table, void* pointer)
{
	return Bridge.invokeObjcFunction!(void*, bindings.NSHashGet, NSHashTable, void*)(table, pointer);
}

void NSHashInsert (NSHashTable table, void* pointer)
{
	return Bridge.invokeObjcFunction!(void, bindings.NSHashInsert, NSHashTable, void*)(table, pointer);
}

void NSHashInsertKnownAbsent (NSHashTable table, void* pointer)
{
	return Bridge.invokeObjcFunction!(void, bindings.NSHashInsertKnownAbsent, NSHashTable, void*)(table, pointer);
}

void* NSHashInsertIfAbsent (NSHashTable table, void* pointer)
{
	return Bridge.invokeObjcFunction!(void*, bindings.NSHashInsertIfAbsent, NSHashTable, void*)(table, pointer);
}

void NSHashRemove (NSHashTable table, void* pointer)
{
	return Bridge.invokeObjcFunction!(void, bindings.NSHashRemove, NSHashTable, void*)(table, pointer);
}

NSHashEnumerator NSEnumerateHashTable (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(NSHashEnumerator, bindings.NSEnumerateHashTable, NSHashTable)(table);
}

NSUInteger NSCountHashTable (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(NSUInteger, bindings.NSCountHashTable, NSHashTable)(table);
}

NSString NSStringFromHashTable (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(NSString, bindings.NSStringFromHashTable, NSHashTable)(table);
}

NSArray NSAllHashTableObjects (NSHashTable table)
{
	return Bridge.invokeObjcFunction!(NSArray, bindings.NSAllHashTableObjects, NSHashTable)(table);
}

NSHashTable NSCreateHashTableWithZone (NSHashTableCallBacks callBacks, NSUInteger capacity, NSZone* zone)
{
	return Bridge.invokeObjcFunction!(NSHashTable, bindings.NSCreateHashTableWithZone, NSHashTableCallBacks, NSUInteger, NSZone*)(callBacks, capacity, zone);
}

NSHashTable NSCreateHashTable (NSHashTableCallBacks callBacks, NSUInteger capacity)
{
	return Bridge.invokeObjcFunction!(NSHashTable, bindings.NSCreateHashTable, NSHashTableCallBacks, NSUInteger)(callBacks, capacity);
}

extern (C)
{
	void* NSNextHashEnumeratorItem (NSHashEnumerator* enumerator);
	void NSEndHashTableEnumeration (NSHashEnumerator* enumerator);
}