Mercurial > projects > dstep
diff dstep/foundation/NSURLRequest.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/NSURLRequest.d Mon Aug 03 15:31:48 2009 +0200 +++ b/dstep/foundation/NSURLRequest.d Sun Jan 03 22:06:11 2010 +0100 @@ -6,17 +6,18 @@ */ module dstep.foundation.NSURLRequest; -import dstep.AvailabilityMacros; +import dstep.foundation.NSCoder; import dstep.foundation.NSData; import dstep.foundation.NSDate; import dstep.foundation.NSDictionary; -import dstep.foundation.NSInputStream; +import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; +import dstep.foundation.NSStream; import dstep.foundation.NSString; import dstep.foundation.NSURL; -import dstep.foundation.NSURLRequestInternal; +import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; -import dstep.objc.objc : id; +import dstep.objc.objc; alias NSUInteger NSURLRequestCachePolicy; @@ -31,19 +32,99 @@ NSURLRequestReloadRevalidatingCacheData = 5 } +const TNSHTTPURLRequest = ` + + NSString HTTPMethod () + { + return invokeObjcSelf!(NSString, "HTTPMethod"); + } + + NSDictionary allHTTPHeaderFields () + { + return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields"); + } + + NSString valueForHTTPHeaderField (NSString field) + { + return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field); + } + + NSData HTTPBody () + { + return invokeObjcSelf!(NSData, "HTTPBody"); + } + + NSInputStream HTTPBodyStream () + { + return invokeObjcSelf!(NSInputStream, "HTTPBodyStream"); + } + + bool HTTPShouldHandleCookies () + { + return invokeObjcSelf!(bool, "HTTPShouldHandleCookies"); + } +`; + +const TNSMutableHTTPURLRequest = ` + + void setHTTPMethod (NSString method) + { + return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method); + } + + void setAllHTTPHeaderFields (NSDictionary headerFields) + { + return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields); + } + + void setValue (NSString value, NSString field) + { + return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field); + } + + void addValue (NSString value, NSString field) + { + return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field); + } + + void setHTTPBody (NSData data) + { + return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data); + } + + void setHTTPBodyStream (NSInputStream inputStream) + { + return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream); + } + + void setHTTPShouldHandleCookies (bool should) + { + return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should); + } +`; + class NSURLRequest : NSObject, INSCoding, INSCopying, INSMutableCopying { - mixin ObjcWrap; - mixin TNSHTTPURLRequest; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } static Object requestWithURL (NSURL URL) { - return invokeObjcSelfClass!(Object, "requestWithURL:", NSURL)(URL); + return invokeObjcSuperClass!(Object, "requestWithURL:", NSURL)(URL); } static Object requestWithURL (NSURL URL, uint cachePolicy, double timeoutInterval) { - return invokeObjcSelfClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval); + return invokeObjcSuperClass!(Object, "requestWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(URL, cachePolicy, timeoutInterval); } Object initWithURL (NSURL URL) @@ -53,13 +134,7 @@ this (NSURL URL) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithURL:", NSURL)(objcObject, URL); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithURL(URL); } Object initWithURL (NSURL URL, uint cachePolicy, double timeoutInterval) @@ -69,13 +144,7 @@ this (NSURL URL, uint cachePolicy, double timeoutInterval) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithURL:cachePolicy:timeoutInterval:", NSURL, uint, double)(objcObject, URL, cachePolicy, timeoutInterval); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithURL(URL, cachePolicy, timeoutInterval); } NSURL URL () @@ -110,13 +179,7 @@ this (NSCoder aDecoder) { - objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); - id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); - - if (result) - objcObject = ret; - - dObject = this; + typeof(this).alloc.initWithCoder(aDecoder); } Object copyWithZone (NSZone* zone) @@ -128,12 +191,52 @@ { return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); } + + // TNSHTTPURLRequest + NSString HTTPMethod () + { + return invokeObjcSelf!(NSString, "HTTPMethod"); + } + + NSDictionary allHTTPHeaderFields () + { + return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields"); + } + + NSString valueForHTTPHeaderField (NSString field) + { + return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field); + } + + NSData HTTPBody () + { + return invokeObjcSelf!(NSData, "HTTPBody"); + } + + NSInputStream HTTPBodyStream () + { + return invokeObjcSelf!(NSInputStream, "HTTPBodyStream"); + } + + bool HTTPShouldHandleCookies () + { + return invokeObjcSelf!(bool, "HTTPShouldHandleCookies"); + } } class NSMutableURLRequest : NSURLRequest { - mixin ObjcWrap; - mixin TNSMutableHTTPURLRequest; + mixin (ObjcWrap); + + this () + { + super(typeof(this).alloc.init.objcObject); + } + + typeof(this) init () + { + return invokeObjcSelf!(typeof(this), "init"); + } void setURL (NSURL URL) { @@ -154,76 +257,40 @@ { return invokeObjcSelf!(void, "setMainDocumentURL:", NSURL)(URL); } -} - -template TNSHTTPURLRequest () -{ - NSString HTTPMethod () - { - return invokeObjcSelf!(NSString, "HTTPMethod"); - } - - NSDictionary allHTTPHeaderFields () - { - return invokeObjcSelf!(NSDictionary, "allHTTPHeaderFields"); - } - - NSString valueForHTTPHeaderField (NSString field) - { - return invokeObjcSelf!(NSString, "valueForHTTPHeaderField:", NSString)(field); - } - - NSData HTTPBody () - { - return invokeObjcSelf!(NSData, "HTTPBody"); - } - - NSInputStream HTTPBodyStream () - { - return invokeObjcSelf!(NSInputStream, "HTTPBodyStream"); - } - - bool HTTPShouldHandleCookies () - { - return invokeObjcSelf!(bool, "HTTPShouldHandleCookies"); - } -} - -template TNSMutableHTTPURLRequest () -{ + + // TNSMutableHTTPURLRequest void setHTTPMethod (NSString method) { return invokeObjcSelf!(void, "setHTTPMethod:", NSString)(method); } - + void setAllHTTPHeaderFields (NSDictionary headerFields) { return invokeObjcSelf!(void, "setAllHTTPHeaderFields:", NSDictionary)(headerFields); } - + void setValue (NSString value, NSString field) { return invokeObjcSelf!(void, "setValue:forHTTPHeaderField:", NSString, NSString)(value, field); } - + void addValue (NSString value, NSString field) { return invokeObjcSelf!(void, "addValue:forHTTPHeaderField:", NSString, NSString)(value, field); } - + void setHTTPBody (NSData data) { return invokeObjcSelf!(void, "setHTTPBody:", NSData)(data); } - + void setHTTPBodyStream (NSInputStream inputStream) { return invokeObjcSelf!(void, "setHTTPBodyStream:", NSInputStream)(inputStream); } - + void setHTTPShouldHandleCookies (bool should) { return invokeObjcSelf!(void, "setHTTPShouldHandleCookies:", bool)(should); } -} - +} \ No newline at end of file