view dstep/foundation/NSPointerFunctions.d @ 25:b9de51448c6b

Added an id constructor. Changed the string mixin to a template mixin. Added support for building as a dynamic library
author Jacob Carlborg <doob@me.com>
date Tue, 06 Apr 2010 11:37:27 +0200
parents 19885b43130e
children
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.NSPointerFunctions;

import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

alias NSUInteger NSPointerFunctionsOptions;

enum
{
	NSPointerFunctionsStrongMemory = (0 << 0),
	NSPointerFunctionsZeroingWeakMemory = (1 << 0),
	NSPointerFunctionsOpaqueMemory = (2 << 0),
	NSPointerFunctionsMallocMemory = (3 << 0),
	NSPointerFunctionsMachVirtualMemory = (4 << 0),
	NSPointerFunctionsObjectPersonality = (0 << 8),
	NSPointerFunctionsOpaquePersonality = (1 << 8),
	NSPointerFunctionsObjectPointerPersonality = (2 << 8),
	NSPointerFunctionsCStringPersonality = (3 << 8),
	NSPointerFunctionsStructPersonality = (4 << 8),
	NSPointerFunctionsIntegerPersonality = (5 << 8),
	NSPointerFunctionsCopyIn = (1 << 16)
}

class NSPointerFunctions : NSObject, INSCopying
{
	mixin ObjcWrap;
	
	this (id object)
	{
		super(object);
	}

	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}
	
	Object initWithOptions (uint options)
	{
		return invokeObjcSelf!(Object, "initWithOptions:", uint)(options);
	}

	this (uint options)
	{
		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
		id result = Bridge.invokeObjcMethod!(id, "initWithOptions:", uint)(objcObject, options);

		if (result)
			objcObject = result;

		dObject = this;
	}

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

	bool usesStrongWriteBarrier ()
	{
		return invokeObjcSelf!(bool, "usesStrongWriteBarrier");
	}

	void setUsesStrongWriteBarrier (bool arg)
	{
		return invokeObjcSelf!(void, "setUsesStrongWriteBarrier:", bool)(arg);
	}

	bool usesWeakReadAndWriteBarriers ()
	{
		return invokeObjcSelf!(bool, "usesWeakReadAndWriteBarriers");
	}

	void setUsesWeakReadAndWriteBarriers (bool arg)
	{
		return invokeObjcSelf!(void, "setUsesWeakReadAndWriteBarriers:", bool)(arg);
	}

	Object copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
	}
}