Mercurial > projects > dstep
diff dstep/foundation/NSDate.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/NSDate.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSDate.d Sun Jan 03 22:06:11 2010 +0100 @@ -6,55 +6,19 @@ */ module dstep.foundation.NSDate; +import dstep.foundation.NSCalendarDate; +import dstep.foundation.NSCoder; import dstep.foundation.NSObject; import dstep.foundation.NSString; +import dstep.foundation.NSTimeZone; +import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; alias double NSTimeInterval; -class NSDate : NSObject, INSCopying, INSCoding -{ - mixin ObjcWrap; - mixin TNSExtendedDate; - mixin TNSDateCreation; - mixin TNSNaturalLangage; - mixin TNSCalendarDateExtras; - - double timeIntervalSinceReferenceDate () - { - return invokeObjcSelf!(double, "timeIntervalSinceReferenceDate"); - } - - Object copyWithZone (NSZone* zone) - { - return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); - } +const TNSExtendedDate = ` - void encodeWithCoder (NSCoder aCoder) - { - return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); - } - - 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; - } -} - -template TNSExtendedDate () -{ double timeIntervalSinceDate (NSDate anotherDate) { return invokeObjcSelf!(double, "timeIntervalSinceDate:", NSDate)(anotherDate); @@ -100,58 +64,42 @@ return invokeObjcSelf!(bool, "isEqualToDate:", NSDate)(otherDate); } - static double timeIntervalSinceReferenceDate () + static double timeIntervalSinceReferenceDate_static () { - return invokeObjcSelfClass!(double, "timeIntervalSinceReferenceDate"); + return invokeObjcSuperClass!(double, "timeIntervalSinceReferenceDate"); } -} +`; -template TNSDateCreation () -{ +const TNSDateCreation = ` + static Object date () { - return invokeObjcSelfClass!(Object, "date"); + return invokeObjcSuperClass!(Object, "date"); } static Object dateWithTimeIntervalSinceNow (double secs) { - return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSinceNow:", double)(secs); + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSinceNow:", double)(secs); } static Object dateWithTimeIntervalSinceReferenceDate (double secs) { - return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSinceReferenceDate:", double)(secs); + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSinceReferenceDate:", double)(secs); } static Object dateWithTimeIntervalSince1970 (double secs) { - return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSince1970:", double)(secs); + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSince1970:", double)(secs); } static Object distantFuture () { - return invokeObjcSelfClass!(Object, "distantFuture"); + return invokeObjcSuperClass!(Object, "distantFuture"); } static Object distantPast () { - return invokeObjcSelfClass!(Object, "distantPast"); - } - - Object init () - { - return invokeObjcSelf!(Object, "init"); - } - - this () - { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); - - if (result) - objcObject = ret; - - dObject = this; + return invokeObjcSuperClass!(Object, "distantPast"); } Object initWithTimeIntervalSinceReferenceDate (double secsToBeAdded) @@ -161,13 +109,7 @@ this (double secsToBeAdded) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithTimeIntervalSinceReferenceDate:", double)(objcObject, secsToBeAdded); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithTimeIntervalSinceReferenceDate(secsToBeAdded); } Object initWithTimeInterval (double secsToBeAdded, NSDate anotherDate) @@ -177,13 +119,7 @@ this (double secsToBeAdded, NSDate anotherDate) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithTimeInterval:sinceDate:", double, NSDate)(objcObject, secsToBeAdded, anotherDate); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithTimeInterval(secsToBeAdded, anotherDate); } Object initWithTimeIntervalSinceNow (double secsToBeAddedToNow) @@ -193,13 +129,195 @@ this (double secsToBeAddedToNow) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithTimeIntervalSinceNow:", double)(objcObject, secsToBeAddedToNow); + typeof(this).alloc.initWithTimeIntervalSinceNow(secsToBeAddedToNow); + } +`; + +class NSDate : NSObject, INSCopying, INSCoding +{ + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } + + double timeIntervalSinceReferenceDate () + { + return invokeObjcSelf!(double, "timeIntervalSinceReferenceDate"); + } + + Object copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); + } + + void encodeWithCoder (NSCoder aCoder) + { + return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); + } + + NSDate initWithCoder (NSCoder aDecoder) + { + return invokeObjcSelf!(NSDate, "initWithCoder:", NSCoder)(aDecoder); + } - if (result) - objcObject = ret; - - dObject = this; + this (NSCoder aDecoder) + { + typeof(this).alloc.initWithCoder(aDecoder); + } + + // TNSExtendedDate + double timeIntervalSinceDate (NSDate anotherDate) + { + return invokeObjcSelf!(double, "timeIntervalSinceDate:", NSDate)(anotherDate); + } + + double timeIntervalSinceNow () + { + return invokeObjcSelf!(double, "timeIntervalSinceNow"); + } + + double timeIntervalSince1970 () + { + return invokeObjcSelf!(double, "timeIntervalSince1970"); + } + + Object addTimeInterval (double seconds) + { + return invokeObjcSelf!(Object, "addTimeInterval:", double)(seconds); + } + + NSDate earlierDate (NSDate anotherDate) + { + return invokeObjcSelf!(NSDate, "earlierDate:", NSDate)(anotherDate); + } + + NSDate laterDate (NSDate anotherDate) + { + return invokeObjcSelf!(NSDate, "laterDate:", NSDate)(anotherDate); + } + + int compare (NSDate other) + { + return invokeObjcSelf!(int, "compare:", NSDate)(other); + } + + NSString description () + { + return invokeObjcSelf!(NSString, "description"); + } + + bool isEqualToDate (NSDate otherDate) + { + return invokeObjcSelf!(bool, "isEqualToDate:", NSDate)(otherDate); + } + + static double timeIntervalSinceReferenceDate_static () + { + return invokeObjcSuperClass!(double, "timeIntervalSinceReferenceDate"); + } + + // TNSDateCreation + static Object date () + { + return invokeObjcSuperClass!(Object, "date"); + } + + static Object dateWithTimeIntervalSinceNow (double secs) + { + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSinceNow:", double)(secs); + } + + static Object dateWithTimeIntervalSinceReferenceDate (double secs) + { + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSinceReferenceDate:", double)(secs); + } + + static Object dateWithTimeIntervalSince1970 (double secs) + { + return invokeObjcSuperClass!(Object, "dateWithTimeIntervalSince1970:", double)(secs); } -} - + + static Object distantFuture () + { + return invokeObjcSuperClass!(Object, "distantFuture"); + } + + static Object distantPast () + { + return invokeObjcSuperClass!(Object, "distantPast"); + } + + Object initWithTimeIntervalSinceReferenceDate (double secsToBeAdded) + { + return invokeObjcSelf!(Object, "initWithTimeIntervalSinceReferenceDate:", double)(secsToBeAdded); + } + + this (double secsToBeAdded) + { + typeof(this).alloc.initWithTimeIntervalSinceReferenceDate(secsToBeAdded); + } + + Object initWithTimeInterval (double secsToBeAdded, NSDate anotherDate) + { + return invokeObjcSelf!(Object, "initWithTimeInterval:sinceDate:", double, NSDate)(secsToBeAdded, anotherDate); + } + + this (double secsToBeAdded, NSDate anotherDate) + { + typeof(this).alloc.initWithTimeInterval(secsToBeAdded, anotherDate); + } + + Object initWithTimeIntervalSinceNow (double secsToBeAddedToNow) + { + return invokeObjcSelf!(Object, "initWithTimeIntervalSinceNow:", double)(secsToBeAddedToNow); + } + + // TNSNaturalLangage + static Object dateWithNaturalLanguageString (NSString string) + { + return invokeObjcSuperClass!(Object, "dateWithNaturalLanguageString:", NSString)(string); + } + + static Object dateWithNaturalLanguageString (NSString string, Object locale) + { + return invokeObjcSuperClass!(Object, "dateWithNaturalLanguageString:locale:", NSString, Object)(string, locale); + } + + // TNSCalendarDateExtras + static Object dateWithString (NSString aString) + { + return invokeObjcSuperClass!(Object, "dateWithString:", NSString)(aString); + } + + Object initWithString (NSString description) + { + return invokeObjcSelf!(Object, "initWithString:", NSString)(description); + } + + this (NSString description) + { + typeof(this).alloc.initWithString(description); + } + + NSCalendarDate dateWithCalendarFormat (NSString format, NSTimeZone aTimeZone) + { + return invokeObjcSelf!(NSCalendarDate, "dateWithCalendarFormat:timeZone:", NSString, NSTimeZone)(format, aTimeZone); + } + + NSString descriptionWithLocale (Object locale) + { + return invokeObjcSelf!(NSString, "descriptionWithLocale:", Object)(locale); + } + + NSString descriptionWithCalendarFormat (NSString format, NSTimeZone aTimeZone, Object locale) + { + return invokeObjcSelf!(NSString, "descriptionWithCalendarFormat:timeZone:locale:", NSString, NSTimeZone, Object)(format, aTimeZone, locale); + } +} \ No newline at end of file