diff dstep/foundation/NSURLCache.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 7ff919f595d5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dstep/foundation/NSURLCache.d	Mon Aug 03 15:23:15 2009 +0200
@@ -0,0 +1,191 @@
+/**
+ * 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.NSURLCache;
+
+import dstep.AvailabilityMacros;
+import dstep.foundation.NSCachedURLResponseInternal;
+import dstep.foundation.NSData;
+import dstep.foundation.NSDictionary;
+import dstep.foundation.NSObject;
+import dstep.foundation.NSURLCacheInternal;
+import dstep.foundation.NSURLRequest;
+import dstep.foundation.NSURLResponse;
+import dstep.objc.bridge.Bridge;
+import dstep.objc.objc : id;
+
+alias NSUInteger NSURLCacheStoragePolicy;
+
+enum
+{
+	NSURLCacheStorageAllowed,
+	NSURLCacheStorageAllowedInMemoryOnly,
+	NSURLCacheStorageNotAllowed
+}
+
+class NSCachedURLResponse : NSObject, INSCoding, INSCopying
+{
+	mixin ObjcWrap;
+
+	Object initWithResponse (NSURLResponse response, NSData data)
+	{
+		return invokeObjcSelf!(Object, "initWithResponse:data:", NSURLResponse, NSData)(response, data);
+	}
+
+	this (NSURLResponse response, NSData data)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithResponse:data:", NSURLResponse, NSData)(objcObject, response, data);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	Object initWithResponse (NSURLResponse response, NSData data, NSDictionary userInfo, uint storagePolicy)
+	{
+		return invokeObjcSelf!(Object, "initWithResponse:data:userInfo:storagePolicy:", NSURLResponse, NSData, NSDictionary, uint)(response, data, userInfo, storagePolicy);
+	}
+
+	this (NSURLResponse response, NSData data, NSDictionary userInfo, uint storagePolicy)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithResponse:data:userInfo:storagePolicy:", NSURLResponse, NSData, NSDictionary, uint)(objcObject, response, data, userInfo, storagePolicy);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	NSURLResponse response ()
+	{
+		return invokeObjcSelf!(NSURLResponse, "response");
+	}
+
+	NSData data ()
+	{
+		return invokeObjcSelf!(NSData, "data");
+	}
+
+	NSDictionary userInfo ()
+	{
+		return invokeObjcSelf!(NSDictionary, "userInfo");
+	}
+
+	uint storagePolicy ()
+	{
+		return invokeObjcSelf!(uint, "storagePolicy");
+	}
+
+	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;
+	}
+
+	Object copyWithZone (NSZone* zone)
+	{
+		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
+	}
+}
+
+class NSURLCache : NSObject
+{
+	mixin ObjcWrap;
+
+	static NSURLCache sharedURLCache ()
+	{
+		return invokeObjcSelfClass!(NSURLCache, "sharedURLCache"return result is this.objcObject ? this : (result !is null ? new NSURLCache(result) : null);	}
+
+	static void setSharedURLCache (NSURLCache cache)
+	{
+		return invokeObjcSelfClass!(void, "setSharedURLCache:", NSURLCache)(cache);
+	}
+
+	Object initWithMemoryCapacity (NSUInteger memoryCapacity, NSUInteger diskCapacity, NSString path)
+	{
+		return invokeObjcSelf!(Object, "initWithMemoryCapacity:diskCapacity:diskPath:", NSUInteger, NSUInteger, NSString)(memoryCapacity, diskCapacity, path);
+	}
+
+	this (NSUInteger memoryCapacity, NSUInteger diskCapacity, NSString path)
+	{
+		objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
+		id result = Bridge.invokeObjcMethod!(id, "initWithMemoryCapacity:diskCapacity:diskPath:", NSUInteger, NSUInteger, NSString)(objcObject, memoryCapacity, diskCapacity, path);
+
+		if (result)
+			objcObject = ret;
+
+		dObject = this;
+	}
+
+	NSCachedURLResponse cachedResponseForRequest (NSURLRequest request)
+	{
+		return invokeObjcSelf!(NSCachedURLResponse, "cachedResponseForRequest:", NSURLRequest)(request);
+	}
+
+	void storeCachedResponse (NSCachedURLResponse cachedResponse, NSURLRequest request)
+	{
+		return invokeObjcSelf!(void, "storeCachedResponse:forRequest:", NSCachedURLResponse, NSURLRequest)(cachedResponse, request);
+	}
+
+	void removeCachedResponseForRequest (NSURLRequest request)
+	{
+		return invokeObjcSelf!(void, "removeCachedResponseForRequest:", NSURLRequest)(request);
+	}
+
+	void removeAllCachedResponses ()
+	{
+		return invokeObjcSelf!(void, "removeAllCachedResponses");
+	}
+
+	NSUInteger memoryCapacity ()
+	{
+		return invokeObjcSelf!(NSUInteger, "memoryCapacity");
+	}
+
+	NSUInteger diskCapacity ()
+	{
+		return invokeObjcSelf!(NSUInteger, "diskCapacity");
+	}
+
+	void setMemoryCapacity (NSUInteger memoryCapacity)
+	{
+		return invokeObjcSelf!(void, "setMemoryCapacity:", NSUInteger)(memoryCapacity);
+	}
+
+	void setDiskCapacity (NSUInteger diskCapacity)
+	{
+		return invokeObjcSelf!(void, "setDiskCapacity:", NSUInteger)(diskCapacity);
+	}
+
+	NSUInteger currentMemoryUsage ()
+	{
+		return invokeObjcSelf!(NSUInteger, "currentMemoryUsage");
+	}
+
+	NSUInteger currentDiskUsage ()
+	{
+		return invokeObjcSelf!(NSUInteger, "currentDiskUsage");
+	}
+}
+