Mercurial > projects > dstep
view dstep/foundation/NSKeyValueCoding.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 |
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.NSKeyValueCoding; import dstep.foundation.NSArray; import dstep.foundation.NSDictionary; import dstep.foundation.NSError; import dstep.foundation.NSSet; import dstep.foundation.NSString; import dstep.objc.bridge.Bridge; import dstep.objc.objc; import bindings = dstep.foundation.NSKeyValueCoding_bindings; private { NSString NSUndefinedKeyException_; NSString NSAverageKeyValueOperator_; NSString NSCountKeyValueOperator_; NSString NSDistinctUnionOfArraysKeyValueOperator_; NSString NSDistinctUnionOfObjectsKeyValueOperator_; NSString NSDistinctUnionOfSetsKeyValueOperator_; NSString NSMaximumKeyValueOperator_; NSString NSMinimumKeyValueOperator_; NSString NSSumKeyValueOperator_; NSString NSUnionOfArraysKeyValueOperator_; NSString NSUnionOfObjectsKeyValueOperator_; NSString NSUnionOfSetsKeyValueOperator_; } NSString NSUndefinedKeyException () { if (NSUndefinedKeyException_) return NSUndefinedKeyException_; return NSUndefinedKeyException_ = new NSString(bindings.NSUndefinedKeyException); } NSString NSAverageKeyValueOperator () { if (NSAverageKeyValueOperator_) return NSAverageKeyValueOperator_; return NSAverageKeyValueOperator_ = new NSString(bindings.NSAverageKeyValueOperator); } NSString NSCountKeyValueOperator () { if (NSCountKeyValueOperator_) return NSCountKeyValueOperator_; return NSCountKeyValueOperator_ = new NSString(bindings.NSCountKeyValueOperator); } NSString NSDistinctUnionOfArraysKeyValueOperator () { if (NSDistinctUnionOfArraysKeyValueOperator_) return NSDistinctUnionOfArraysKeyValueOperator_; return NSDistinctUnionOfArraysKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfArraysKeyValueOperator); } NSString NSDistinctUnionOfObjectsKeyValueOperator () { if (NSDistinctUnionOfObjectsKeyValueOperator_) return NSDistinctUnionOfObjectsKeyValueOperator_; return NSDistinctUnionOfObjectsKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfObjectsKeyValueOperator); } NSString NSDistinctUnionOfSetsKeyValueOperator () { if (NSDistinctUnionOfSetsKeyValueOperator_) return NSDistinctUnionOfSetsKeyValueOperator_; return NSDistinctUnionOfSetsKeyValueOperator_ = new NSString(bindings.NSDistinctUnionOfSetsKeyValueOperator); } NSString NSMaximumKeyValueOperator () { if (NSMaximumKeyValueOperator_) return NSMaximumKeyValueOperator_; return NSMaximumKeyValueOperator_ = new NSString(bindings.NSMaximumKeyValueOperator); } NSString NSMinimumKeyValueOperator () { if (NSMinimumKeyValueOperator_) return NSMinimumKeyValueOperator_; return NSMinimumKeyValueOperator_ = new NSString(bindings.NSMinimumKeyValueOperator); } NSString NSSumKeyValueOperator () { if (NSSumKeyValueOperator_) return NSSumKeyValueOperator_; return NSSumKeyValueOperator_ = new NSString(bindings.NSSumKeyValueOperator); } NSString NSUnionOfArraysKeyValueOperator () { if (NSUnionOfArraysKeyValueOperator_) return NSUnionOfArraysKeyValueOperator_; return NSUnionOfArraysKeyValueOperator_ = new NSString(bindings.NSUnionOfArraysKeyValueOperator); } NSString NSUnionOfObjectsKeyValueOperator () { if (NSUnionOfObjectsKeyValueOperator_) return NSUnionOfObjectsKeyValueOperator_; return NSUnionOfObjectsKeyValueOperator_ = new NSString(bindings.NSUnionOfObjectsKeyValueOperator); } NSString NSUnionOfSetsKeyValueOperator () { if (NSUnionOfSetsKeyValueOperator_) return NSUnionOfSetsKeyValueOperator_; return NSUnionOfSetsKeyValueOperator_ = new NSString(bindings.NSUnionOfSetsKeyValueOperator); } const TNSDeprecatedKeyValueCoding = ` static bool useStoredAccessor () { return invokeObjcSelfClass!(bool, "useStoredAccessor"); } Object storedValueForKey (NSString key) { return invokeObjcSelf!(Object, "storedValueForKey:", NSString)(key); } void takeStoredValue (Object value, NSString key) { return invokeObjcSelf!(void, "takeStoredValue:forKey:", Object, NSString)(value, key); } void takeValue (Object value, NSString key) { return invokeObjcSelf!(void, "takeValue:forKey:", Object, NSString)(value, key); } void takeValue_forKeyPath (Object value, NSString keyPath) { return invokeObjcSelf!(void, "takeValue:forKeyPath:", Object, NSString)(value, keyPath); } Object handleQueryWithUnboundKey (NSString key) { return invokeObjcSelf!(Object, "handleQueryWithUnboundKey:", NSString)(key); } void handleTakeValue (Object value, NSString key) { return invokeObjcSelf!(void, "handleTakeValue:forUnboundKey:", Object, NSString)(value, key); } void unableToSetNilForKey (NSString key) { return invokeObjcSelf!(void, "unableToSetNilForKey:", NSString)(key); } NSDictionary valuesForKeys (NSArray keys) { return invokeObjcSelf!(NSDictionary, "valuesForKeys:", NSArray)(keys); } void takeValuesFromDictionary (NSDictionary properties) { return invokeObjcSelf!(void, "takeValuesFromDictionary:", NSDictionary)(properties); } //mixin ObjcBindClassMethod!(useStoredAccessor, "useStoredAccessor"); //mixin ObjcBindMethod!(storedValueForKey, "storedValueForKey:"); //mixin ObjcBindMethod!(takeStoredValue, "takeStoredValue:forKey:"); //mixin ObjcBindMethod!(takeValue, "takeValue:forKey"); //mixin ObjcBindMethod!(takeValue_forKeyPath, "takeValue:forKeyPath:"); //mixin ObjcBindMethod!(handleQueryWithUnboundKey, "handleQueryWithUnboundKey:"); //mixin ObjcBindMethod!(handleTakeValue, "handleTakeValue:forUnboundKey:"); //mixin ObjcBindMethod!(unableToSetNilForKey, "unableToSetNilForKey:"); //mixin ObjcBindMethod!(valuesForKeys, "valuesForKeys:"); //mixin ObjcBindMethod!(takeValuesFromDictionary, "takeValuesFromDictionary:"); `; const TNSKeyValueCoding = ` static bool accessInstanceVariablesDirectly () { return invokeObjcSelfClass!(bool, "accessInstanceVariablesDirectly"); } Object valueForKey (NSString key) { return invokeObjcSelf!(Object, "valueForKey:", NSString)(key); } void setValue (Object value, NSString key) { return invokeObjcSelf!(void, "setValue:forKey:", Object, NSString)(value, key); } bool validateValue (id* ioValue, NSString inKey, ref NSError outError) { id error; if (outError) error = new objc_object; bool result = invokeObjcSelf!(bool, "validateValue:forKey:error:", id*, NSString, id*)(ioValue, inKey, &error); if (error) outError = new NSError(error); return result; } NSMutableArray mutableArrayValueForKey (NSString key) { return invokeObjcSelf!(NSMutableArray, "mutableArrayValueForKey:", NSString)(key); } NSMutableSet mutableSetValueForKey (NSString key) { return invokeObjcSelf!(NSMutableSet, "mutableSetValueForKey:", NSString)(key); } Object valueForKeyPath (NSString keyPath) { return invokeObjcSelf!(Object, "valueForKeyPath:", NSString)(keyPath); } void setValue_forKeyPath (Object value, NSString keyPath) { return invokeObjcSelf!(void, "setValue:forKeyPath:", Object, NSString)(value, keyPath); } bool validateValue_forKeyPath_error (id* ioValue, NSString inKeyPath, ref NSError outError) { id error; if (outError) error = new objc_object; bool result = invokeObjcSelf!(bool, "validateValue:forKeyPath:error:", id*, NSString, id*)(ioValue, inKeyPath, &error); if (error) outError = new NSError(error); return result; } NSMutableArray mutableArrayValueForKeyPath (NSString keyPath) { return invokeObjcSelf!(NSMutableArray, "mutableArrayValueForKeyPath:", NSString)(keyPath); } NSMutableSet mutableSetValueForKeyPath (NSString keyPath) { return invokeObjcSelf!(NSMutableSet, "mutableSetValueForKeyPath:", NSString)(keyPath); } Object valueForUndefinedKey (NSString key) { return invokeObjcSelf!(Object, "valueForUndefinedKey:", NSString)(key); } void setValue_forUndefinedKey (Object value, NSString key) { return invokeObjcSelf!(void, "setValue:forUndefinedKey:", Object, NSString)(value, key); } void setNilValueForKey (NSString key) { return invokeObjcSelf!(void, "setNilValueForKey:", NSString)(key); } NSDictionary dictionaryWithValuesForKeys (NSArray keys) { return invokeObjcSelf!(NSDictionary, "dictionaryWithValuesForKeys:", NSArray)(keys); } void setValuesForKeysWithDictionary (NSDictionary keyedValues) { return invokeObjcSelf!(void, "setValuesForKeysWithDictionary:", NSDictionary)(keyedValues); } //mixin ObjcBindClassMethod!(accessInstanceVariablesDirectly, bool, "accessInstanceVariablesDirectly"); //mixin ObjcBindMethod!(setValue, void, "setValue:forKey:", Object, NSString); ////mixin ObjcBindMethod!(validateValue, bool, "validateValue:forKey:error:", id*, NSString, NSError*); //mixin ObjcBindMethod!(mutableArrayValueForKey, NSMutableArray, "mutableArrayValueForKey:", NSString); //mixin ObjcBindMethod!(mutableSetValueForKey, NSMutableSet, "mutableSetValueForKey:", NSString); //mixin ObjcBindMethod!(valueForKeyPath, Object, "valueForKeyPath:", NSString); //mixin ObjcBindMethod!(setValue_forKeyPath, void, "setValue:forKeyPath:", Object, NSString); ////mixin ObjcBindMethod!(validateValue_forKeyPath_error, "validateValue:forKeyPath:error:"); //mixin ObjcBindMethod!(mutableArrayValueForKeyPath, NSMutableArray, "mutableArrayValueForKeyPath:", NSString); //mixin ObjcBindMethod!(mutableSetValueForKeyPath, NSMutableSet, "mutableSetValueForKeyPath:", NSString); //mixin ObjcBindMethod!(valueForUndefinedKey, Object, "valueForUndefinedKey:", NSString); //mixin ObjcBindMethod!(setValue_forUndefinedKey, void, "setValue:forUndefinedKey:", Object, NSString); //mixin ObjcBindMethod!(setNilValueForKey, void, "setNilValueForKey:", NSString); //mixin ObjcBindMethod!(dictionaryWithValuesForKeys, NSDictionary, "dictionaryWithValuesForKeys:", NSArray); //mixin ObjcBindMethod!(setValuesForKeysWithDictionary, void, "setValuesForKeysWithDictionary:", NSDictionary); `;