Mercurial > projects > dstep
diff dstep/foundation/NSDictionary.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 diff
--- a/dstep/foundation/NSDictionary.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSDictionary.d Sun Jan 03 22:06:11 2010 +0100 @@ -7,119 +7,49 @@ module dstep.foundation.NSDictionary; import dstep.foundation.NSArray; +import dstep.foundation.NSCoder; +import dstep.foundation.NSDate; import dstep.foundation.NSEnumerator; +import dstep.foundation.NSFileManager; +import dstep.foundation.NSValue; +import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; import dstep.foundation.NSString; import dstep.foundation.NSURL; +import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; - -class NSMutableDictionary : NSDictionary -{ - mixin ObjcWrap; - mixin TNSMutableDictionaryCreation; - mixin TNSExtendedMutableDictionary; - - void removeObjectForKey (Object aKey) - { - return invokeObjcSelf!(void, "removeObjectForKey:", Object)(aKey); - } - - void setObject (Object anObject, Object aKey) - { - return invokeObjcSelf!(void, "setObject:forKey:", Object, Object)(anObject, aKey); - } -} - -class NSDictionary : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration -{ - mixin ObjcWrap; - mixin TNSDictionaryCreation; - mixin TNSFileAttributes; - mixin TNSExtendedDictionary; - - NSUInteger count () - { - return invokeObjcSelf!(NSUInteger, "count"); - } - - Object objectForKey (Object aKey) - { - return invokeObjcSelf!(Object, "objectForKey:", Object)(aKey); - } +import dstep.objc.objc; - NSEnumerator keyEnumerator () - { - return invokeObjcSelf!(NSEnumerator, "keyEnumerator"); - } - - Object copyWithZone (NSZone* zone) - { - return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); - } - - Object mutableCopyWithZone (NSZone* zone) - { - return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); - } - - void encodeWithCoder (NSCoder aCoder) - { - return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); - } +const TNSDictionaryCreation = ` - Object initWithCoder (NSCoder aDecoder) - { - return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); - } - - this (NSCoder aDecoder) - { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); - - if (result) - objcObject = ret; - - dObject = this; - } - - NSUInteger countByEnumeratingWithState (NSFastEnumerationState* state, id* stackbuf, NSUInteger len) - { - return invokeObjcSelf!(NSUInteger, "countByEnumeratingWithState:objects:count:", NSFastEnumerationState*, id*, NSUInteger)(state, stackbuf, len); - } -} - -template TNSDictionaryCreation () -{ static Object dictionary () { - return invokeObjcSelfClass!(Object, "dictionary"); + return invokeObjcSuperClass!(Object, "dictionary"); } static Object dictionaryWithObject (Object object, Object key) { - return invokeObjcSelfClass!(Object, "dictionaryWithObject:forKey:", Object, Object)(object, key); + return invokeObjcSuperClass!(Object, "dictionaryWithObject:forKey:", Object, Object)(object, key); } static Object dictionaryWithObjects (id* objects, id* keys, NSUInteger cnt) { - return invokeObjcSelfClass!(Object, "dictionaryWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt); + return invokeObjcSuperClass!(Object, "dictionaryWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt); } static Object dictionaryWithObjectsAndKeys (Object dictionaryWithObjectsAndKeys, ...) { - return invokeObjcSelfClass!(Object, "dictionaryWithObjectsAndKeys:", Object)(dictionaryWithObjectsAndKeys); + return invokeObjcSuperClass!(Object, "dictionaryWithObjectsAndKeys:", Object)(dictionaryWithObjectsAndKeys); } static Object dictionaryWithDictionary (NSDictionary dict) { - return invokeObjcSelfClass!(Object, "dictionaryWithDictionary:", NSDictionary)(dict); + return invokeObjcSuperClass!(Object, "dictionaryWithDictionary:", NSDictionary)(dict); } static Object dictionaryWithObjects (NSArray objects, NSArray keys) { - return invokeObjcSelfClass!(Object, "dictionaryWithObjects:forKeys:", NSArray, NSArray)(objects, keys); + return invokeObjcSuperClass!(Object, "dictionaryWithObjects:forKeys:", NSArray, NSArray)(objects, keys); } Object initWithObjects (id* objects, id* keys, NSUInteger cnt) @@ -129,13 +59,7 @@ this (id* objects, id* keys, NSUInteger cnt) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithObjects:forKeys:count:", id*, id*, NSUInteger)(objcObject, objects, keys, cnt); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithObjects(objects, keys, cnt); } Object initWithObjectsAndKeys (Object initWithObjectsAndKeys, ...) @@ -145,13 +69,7 @@ this (Object initWithObjectsAndKeys, ...) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithObjectsAndKeys:", Object)(objcObject, initWithObjectsAndKeys); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithObjectsAndKeys(initWithObjectsAndKeys); } Object initWithDictionary (NSDictionary otherDictionary) @@ -161,13 +79,7 @@ this (NSDictionary otherDictionary) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithDictionary:", NSDictionary)(objcObject, otherDictionary); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithDictionary(otherDictionary); } Object initWithDictionary (NSDictionary otherDictionary, bool flag) @@ -177,13 +89,7 @@ this (NSDictionary otherDictionary, bool flag) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithDictionary:copyItems:", NSDictionary, bool)(objcObject, otherDictionary, flag); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithDictionary(otherDictionary, flag); } Object initWithObjects (NSArray objects, NSArray keys) @@ -193,23 +99,17 @@ this (NSArray objects, NSArray keys) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithObjects:forKeys:", NSArray, NSArray)(objcObject, objects, keys); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithObjects(objects, keys); } static Object dictionaryWithContentsOfFile (NSString path) { - return invokeObjcSelfClass!(Object, "dictionaryWithContentsOfFile:", NSString)(path); + return invokeObjcSuperClass!(Object, "dictionaryWithContentsOfFile:", NSString)(path); } static Object dictionaryWithContentsOfURL (NSURL url) { - return invokeObjcSelfClass!(Object, "dictionaryWithContentsOfURL:", NSURL)(url); + return invokeObjcSuperClass!(Object, "dictionaryWithContentsOfURL:", NSURL)(url); } Object initWithContentsOfFile (NSString path) @@ -219,13 +119,7 @@ this (NSString path) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:", NSString)(objcObject, path); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithContentsOfFile(path); } Object initWithContentsOfURL (NSURL url) @@ -235,21 +129,15 @@ this (NSURL url) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:", NSURL)(objcObject, url); - - if (result) - objcObject = ret; + typeof(this).alloc.initWithContentsOfURL(url); + } +`; - dObject = this; - } -} +const TNSMutableDictionaryCreation = ` -template TNSMutableDictionaryCreation () -{ static Object dictionaryWithCapacity (NSUInteger numItems) { - return invokeObjcSelfClass!(Object, "dictionaryWithCapacity:", NSUInteger)(numItems); + return invokeObjcSuperClass!(Object, "dictionaryWithCapacity:", NSUInteger)(numItems); } Object initWithCapacity (NSUInteger numItems) @@ -259,18 +147,12 @@ this (NSUInteger numItems) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, numItems); - - if (result) - objcObject = ret; + typeof(this).alloc.initWithCapacity(numItems); + } +`; - dObject = this; - } -} +const TNSExtendedMutableDictionary = ` -template TNSExtendedMutableDictionary () -{ void addEntriesFromDictionary (NSDictionary otherDictionary) { return invokeObjcSelf!(void, "addEntriesFromDictionary:", NSDictionary)(otherDictionary); @@ -290,10 +172,10 @@ { return invokeObjcSelf!(void, "setDictionary:", NSDictionary)(otherDictionary); } -} +`; -template TNSExtendedDictionary () -{ +const TNSExtendedDictionary = ` + NSArray allKeys () { return invokeObjcSelf!(NSArray, "allKeys"); @@ -363,5 +245,389 @@ { return invokeObjcSelf!(void, "getObjects:andKeys:", id*, id*)(objects, keys); } +`; + +class NSMutableDictionary : NSDictionary +{ + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + + void removeObjectForKey (Object aKey) + { + return invokeObjcSelf!(void, "removeObjectForKey:", Object)(aKey); + } + + void setObject (Object anObject, Object aKey) + { + return invokeObjcSelf!(void, "setObject:forKey:", Object, Object)(anObject, aKey); + } + + // TNSMutableDictionaryCreation + static Object dictionaryWithCapacity (NSUInteger numItems) + { + return invokeObjcSuperClass!(Object, "dictionaryWithCapacity:", NSUInteger)(numItems); + } + + Object initWithCapacity (NSUInteger numItems) + { + return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(numItems); + } + + this (NSUInteger numItems) + { + typeof(this).alloc.initWithCapacity(numItems); + } + + // TNSExtendedMutableDictionary + void addEntriesFromDictionary (NSDictionary otherDictionary) + { + return invokeObjcSelf!(void, "addEntriesFromDictionary:", NSDictionary)(otherDictionary); + } + + void removeAllObjects () + { + return invokeObjcSelf!(void, "removeAllObjects"); + } + + void removeObjectsForKeys (NSArray keyArray) + { + return invokeObjcSelf!(void, "removeObjectsForKeys:", NSArray)(keyArray); + } + + void setDictionary (NSDictionary otherDictionary) + { + return invokeObjcSelf!(void, "setDictionary:", NSDictionary)(otherDictionary); + } } +class NSDictionary : NSObject, INSCopying, INSMutableCopying, INSCoding, INSFastEnumeration +{ + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + + NSUInteger count () + { + return invokeObjcSelf!(NSUInteger, "count"); + } + + Object objectForKey (Object aKey) + { + return invokeObjcSelf!(Object, "objectForKey:", Object)(aKey); + } + + NSEnumerator keyEnumerator () + { + return invokeObjcSelf!(NSEnumerator, "keyEnumerator"); + } + + Object copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); + } + + Object mutableCopyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "mutableCopyWithZone:", 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); + } + + // TNSDictionaryCreation + static Object dictionary () + { + return invokeObjcSuperClass!(Object, "dictionary"); + } + + static Object dictionaryWithObject (Object object, Object key) + { + return invokeObjcSuperClass!(Object, "dictionaryWithObject:forKey:", Object, Object)(object, key); + } + + static Object dictionaryWithObjects (id* objects, id* keys, NSUInteger cnt) + { + return invokeObjcSuperClass!(Object, "dictionaryWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt); + } + + static Object dictionaryWithObjectsAndKeys (Object dictionaryWithObjectsAndKeys, ...) + { + return invokeObjcSuperClass!(Object, "dictionaryWithObjectsAndKeys:", Object)(dictionaryWithObjectsAndKeys); + } + + static Object dictionaryWithDictionary (NSDictionary dict) + { + return invokeObjcSuperClass!(Object, "dictionaryWithDictionary:", NSDictionary)(dict); + } + + static Object dictionaryWithObjects (NSArray objects, NSArray keys) + { + return invokeObjcSuperClass!(Object, "dictionaryWithObjects:forKeys:", NSArray, NSArray)(objects, keys); + } + + Object initWithObjects (id* objects, id* keys, NSUInteger cnt) + { + return invokeObjcSelf!(Object, "initWithObjects:forKeys:count:", id*, id*, NSUInteger)(objects, keys, cnt); + } + + this (id* objects, id* keys, NSUInteger cnt) + { + typeof(this).alloc.initWithObjects(objects, keys, cnt); + } + + Object initWithObjectsAndKeys (Object initWithObjectsAndKeys, ...) + { + return invokeObjcSelf!(Object, "initWithObjectsAndKeys:", Object)(initWithObjectsAndKeys); + } + + this (Object initWithObjectsAndKeys, ...) + { + typeof(this).alloc.initWithObjectsAndKeys(initWithObjectsAndKeys); + } + + Object initWithDictionary (NSDictionary otherDictionary) + { + return invokeObjcSelf!(Object, "initWithDictionary:", NSDictionary)(otherDictionary); + } + + this (NSDictionary otherDictionary) + { + typeof(this).alloc.initWithDictionary(otherDictionary); + } + + Object initWithDictionary (NSDictionary otherDictionary, bool flag) + { + return invokeObjcSelf!(Object, "initWithDictionary:copyItems:", NSDictionary, bool)(otherDictionary, flag); + } + + this (NSDictionary otherDictionary, bool flag) + { + typeof(this).alloc.initWithDictionary(otherDictionary, flag); + } + + Object initWithObjects (NSArray objects, NSArray keys) + { + return invokeObjcSelf!(Object, "initWithObjects:forKeys:", NSArray, NSArray)(objects, keys); + } + + this (NSArray objects, NSArray keys) + { + typeof(this).alloc.initWithObjects(objects, keys); + } + + static Object dictionaryWithContentsOfFile (NSString path) + { + return invokeObjcSuperClass!(Object, "dictionaryWithContentsOfFile:", NSString)(path); + } + + static Object dictionaryWithContentsOfURL (NSURL url) + { + return invokeObjcSuperClass!(Object, "dictionaryWithContentsOfURL:", NSURL)(url); + } + + Object initWithContentsOfFile (NSString path) + { + return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); + } + + this (NSString path) + { + typeof(this).alloc.initWithContentsOfFile(path); + } + + Object initWithContentsOfURL (NSURL url) + { + return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); + } + + this (NSURL url) + { + typeof(this).alloc.initWithContentsOfURL(url); + } + + // TNSFileAttributes + ulong fileSize () + { + return invokeObjcSelf!(ulong, "fileSize"); + } + + NSDate fileModificationDate () + { + return invokeObjcSelf!(NSDate, "fileModificationDate"); + } + + NSString fileType () + { + return invokeObjcSelf!(NSString, "fileType"); + } + + NSUInteger filePosixPermissions () + { + return invokeObjcSelf!(NSUInteger, "filePosixPermissions"); + } + + NSString fileOwnerAccountName () + { + return invokeObjcSelf!(NSString, "fileOwnerAccountName"); + } + + NSString fileGroupOwnerAccountName () + { + return invokeObjcSelf!(NSString, "fileGroupOwnerAccountName"); + } + + NSInteger fileSystemNumber () + { + return invokeObjcSelf!(NSInteger, "fileSystemNumber"); + } + + NSUInteger fileSystemFileNumber () + { + return invokeObjcSelf!(NSUInteger, "fileSystemFileNumber"); + } + + bool fileExtensionHidden () + { + return invokeObjcSelf!(bool, "fileExtensionHidden"); + } + + uint fileHFSCreatorCode () + { + return invokeObjcSelf!(uint, "fileHFSCreatorCode"); + } + + uint fileHFSTypeCode () + { + return invokeObjcSelf!(uint, "fileHFSTypeCode"); + } + + bool fileIsImmutable () + { + return invokeObjcSelf!(bool, "fileIsImmutable"); + } + + bool fileIsAppendOnly () + { + return invokeObjcSelf!(bool, "fileIsAppendOnly"); + } + + NSDate fileCreationDate () + { + return invokeObjcSelf!(NSDate, "fileCreationDate"); + } + + NSNumber fileOwnerAccountID () + { + return invokeObjcSelf!(NSNumber, "fileOwnerAccountID"); + } + + NSNumber fileGroupOwnerAccountID () + { + return invokeObjcSelf!(NSNumber, "fileGroupOwnerAccountID"); + } + + // TNSExtendedDictionary + NSArray allKeys () + { + return invokeObjcSelf!(NSArray, "allKeys"); + } + + NSArray allKeysForObject (Object anObject) + { + return invokeObjcSelf!(NSArray, "allKeysForObject:", Object)(anObject); + } + + NSArray allValues () + { + return invokeObjcSelf!(NSArray, "allValues"); + } + + NSString description () + { + return invokeObjcSelf!(NSString, "description"); + } + + NSString descriptionInStringsFileFormat () + { + return invokeObjcSelf!(NSString, "descriptionInStringsFileFormat"); + } + + NSString descriptionWithLocale (Object locale) + { + return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale); + } + + NSString descriptionWithLocale (Object locale, NSUInteger level) + { + return invokeObjcSelf!(NSString, "descriptionWithLocale:indent:", Object, NSUInteger)(locale, level); + } + + bool isEqualToDictionary (NSDictionary otherDictionary) + { + return invokeObjcSelf!(bool, "isEqualToDictionary:", NSDictionary)(otherDictionary); + } + + NSEnumerator objectEnumerator () + { + return invokeObjcSelf!(NSEnumerator, "objectEnumerator"); + } + + NSArray objectsForKeys (NSArray keys, Object marker) + { + return invokeObjcSelf!(NSArray, "objectsForKeys:notFoundMarker:", NSArray, Object)(keys, marker); + } + + bool writeToFile (NSString path, bool useAuxiliaryFile) + { + return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); + } + + bool writeToURL (NSURL url, bool atomically) + { + return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); + } + + NSArray keysSortedByValueUsingSelector (SEL comparator) + { + return invokeObjcSelf!(NSArray, "keysSortedByValueUsingSelector:", SEL)(comparator); + } + + void getObjects (id* objects, id* keys) + { + return invokeObjcSelf!(void, "getObjects:andKeys:", id*, id*)(objects, keys); + } +} \ No newline at end of file