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

import dstep.foundation.NSArray;
import dstep.foundation.NSCoder;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSPredicate;
import dstep.foundation.NSString;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

alias NSUInteger NSExpressionType;

enum
{
	NSConstantValueExpressionType = 0,
	NSEvaluatedObjectExpressionType,
	NSVariableExpressionType,
	NSKeyPathExpressionType,
	NSFunctionExpressionType,
	NSUnionSetExpressionType,
	NSIntersectSetExpressionType,
	NSMinusSetExpressionType,
	NSSubqueryExpressionType = 13,
	NSAggregateExpressionType
}

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

	static NSExpression expressionForConstantValue (Object obj)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForConstantValue:", Object)(obj);
	}

	static NSExpression expressionForEvaluatedObject ()
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForEvaluatedObject");
	}

	static NSExpression expressionForVariable (NSString string)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForVariable:", NSString)(string);
	}

	static NSExpression expressionForKeyPath (NSString keyPath)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForKeyPath:", NSString)(keyPath);
	}

	static NSExpression expressionForFunction (NSString name, NSArray parameters)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForFunction:arguments:", NSString, NSArray)(name, parameters);
	}

	static NSExpression expressionForAggregate (NSArray subexpressions)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForAggregate:", NSArray)(subexpressions);
	}

	static NSExpression expressionForUnionSet (NSExpression left, NSExpression right)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForUnionSet:with:", NSExpression, NSExpression)(left, right);
	}

	static NSExpression expressionForIntersectSet (NSExpression left, NSExpression right)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForIntersectSet:with:", NSExpression, NSExpression)(left, right);
	}

	static NSExpression expressionForMinusSet (NSExpression left, NSExpression right)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForMinusSet:with:", NSExpression, NSExpression)(left, right);
	}

	static NSExpression expressionForSubquery (NSExpression expression, NSString variable, Object predicate)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForSubquery:usingIteratorVariable:predicate:", NSExpression, NSString, Object)(expression, variable, predicate);
	}

	static NSExpression expressionForFunction (NSExpression target, NSString name, NSArray parameters)
	{
		return invokeObjcSuperClass!(NSExpression, "expressionForFunction:selectorName:arguments:", NSExpression, NSString, NSArray)(target, name, parameters);
	}

	Object initWithExpressionType (uint type)
	{
		return invokeObjcSelf!(Object, "initWithExpressionType:", uint)(type);
	}

	this (uint type)
	{
		typeof(this).alloc.initWithExpressionType(type);
	}

	uint expressionType ()
	{
		return invokeObjcSelf!(uint, "expressionType");
	}

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

	NSString keyPath ()
	{
		return invokeObjcSelf!(NSString, "keyPath");
	}

	NSString function_ ()
	{
		return invokeObjcSelf!(NSString, "function");
	}

	NSString variable ()
	{
		return invokeObjcSelf!(NSString, "variable");
	}

	NSExpression operand ()
	{
		id result = invokeObjcSelf!(id, "operand");
		return result is this.objcObject ? this : (result !is null ? new NSExpression(result) : null);
	}

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

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

	NSPredicate predicate ()
	{
		return invokeObjcSelf!(NSPredicate, "predicate");
	}

	NSExpression leftExpression ()
	{
		id result = invokeObjcSelf!(id, "leftExpression");
		return result is this.objcObject ? this : (result !is null ? new NSExpression(result) : null);
	}

	NSExpression rightExpression ()
	{
		id result = invokeObjcSelf!(id, "rightExpression");
		return result is this.objcObject ? this : (result !is null ? new NSExpression(result) : null);
	}

	Object expressionValueWithObject (Object object, NSMutableDictionary context)
	{
		return invokeObjcSelf!(Object, "expressionValueWithObject:context:", Object, NSMutableDictionary)(object, context);
	}

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

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