Mercurial > projects > dstep
diff 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 diff
--- a/dstep/foundation/NSKeyValueCoding.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSKeyValueCoding.d Sun Jan 03 22:06:11 2010 +0100 @@ -12,70 +12,303 @@ import dstep.foundation.NSSet; import dstep.foundation.NSString; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; + + import bindings = dstep.foundation.NSKeyValueCoding_bindings; -const NSString NSUndefinedKeyException; -const NSString NSAverageKeyValueOperator; -const NSString NSCountKeyValueOperator; -const NSString NSDistinctUnionOfArraysKeyValueOperator; -const NSString NSDistinctUnionOfObjectsKeyValueOperator; -const NSString NSDistinctUnionOfSetsKeyValueOperator; -const NSString NSMaximumKeyValueOperator; -const NSString NSMinimumKeyValueOperator; -const NSString NSSumKeyValueOperator; -const NSString NSUnionOfArraysKeyValueOperator; -const NSString NSUnionOfObjectsKeyValueOperator; -const NSString NSUnionOfSetsKeyValueOperator; +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); +} -static this () +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 () { - NSUndefinedKeyException = new NSString(bindings.NSUndefinedKeyException); - NSAverageKeyValueOperator = new NSString(bindings.NSAverageKeyValueOperator); - NSCountKeyValueOperator = new NSString(bindings.NSCountKeyValueOperator); - NSDistinctUnionOfArraysKeyValueOperator = new NSString(bindings.NSDistinctUnionOfArraysKeyValueOperator); - NSDistinctUnionOfObjectsKeyValueOperator = new NSString(bindings.NSDistinctUnionOfObjectsKeyValueOperator); - NSDistinctUnionOfSetsKeyValueOperator = new NSString(bindings.NSDistinctUnionOfSetsKeyValueOperator); - NSMaximumKeyValueOperator = new NSString(bindings.NSMaximumKeyValueOperator); - NSMinimumKeyValueOperator = new NSString(bindings.NSMinimumKeyValueOperator); - NSSumKeyValueOperator = new NSString(bindings.NSSumKeyValueOperator); - NSUnionOfArraysKeyValueOperator = new NSString(bindings.NSUnionOfArraysKeyValueOperator); - NSUnionOfObjectsKeyValueOperator = new NSString(bindings.NSUnionOfObjectsKeyValueOperator); - NSUnionOfSetsKeyValueOperator = new NSString(bindings.NSUnionOfSetsKeyValueOperator); + 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); } -template TNSDeprecatedKeyValueCoding () -{ - static bool useStoredAccessor (); - Object storedValueForKey (NSString key); - void takeStoredValue (Object value, NSString key); - void takeValue (Object value, NSString key); - void takeValue (Object value, NSString keyPath); - Object handleQueryWithUnboundKey (NSString key); - void handleTakeValue (Object value, NSString key); - void unableToSetNilForKey (NSString key); - NSDictionary valuesForKeys (NSArray keys); - void takeValuesFromDictionary (NSDictionary properties); -} +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 = ` -template TNSKeyValueCoding () -{ - static bool accessInstanceVariablesDirectly (); - Object valueForKey (NSString key); - void setValue (Object value, NSString key); - bool validateValue (id* ioValue, NSString inKey, NSError** outError); - NSMutableArray mutableArrayValueForKey (NSString key); - NSMutableSet mutableSetValueForKey (NSString key); - Object valueForKeyPath (NSString keyPath); - void setValue (Object value, NSString keyPath); - bool validateValue (id* ioValue, NSString inKeyPath, NSError** outError); - NSMutableArray mutableArrayValueForKeyPath (NSString keyPath); - NSMutableSet mutableSetValueForKeyPath (NSString keyPath); - Object valueForUndefinedKey (NSString key); - void setValue (Object value, NSString key); - void setNilValueForKey (NSString key); - NSDictionary dictionaryWithValuesForKeys (NSArray keys); - void setValuesForKeysWithDictionary (NSDictionary keyedValues); -} - + 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); +`; \ No newline at end of file