view dstep/foundation/NSURLCache.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 7ff919f595d5
children b9de51448c6b
line wrap: on
line source

/**
 * 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.foundation.NSCoder;
import dstep.foundation.NSData;
import dstep.foundation.NSDictionary;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.foundation.NSURLRequest;
import dstep.foundation.NSURLResponse;
import dstep.foundation.NSZone;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

alias NSUInteger NSURLCacheStoragePolicy;

enum
{
	NSURLCacheStorageAllowed,
	NSURLCacheStorageAllowedInMemoryOnly,
	NSURLCacheStorageNotAllowed
}

class NSCachedURLResponse : NSObject, INSCoding, INSCopying
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	Object initWithResponse (NSURLResponse response, NSData data)
	{
		return invokeObjcSelf!(Object, "initWithResponse:data:", NSURLResponse, NSData)(response, data);
	}

	this (NSURLResponse response, NSData data)
	{
		typeof(this).alloc.initWithResponse(response, data);
	}

	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)
	{
		typeof(this).alloc.initWithResponse(response, data, userInfo, storagePolicy);
	}

	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)
	{
		typeof(this).alloc.initWithCoder(aDecoder);
	}

	Object copyWithZone (NSZone* zone)
	{
		return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
	}
}

class NSURLCache : NSObject
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	static NSURLCache sharedURLCache ()
	{
		return invokeObjcSuperClass!(NSURLCache, "sharedURLCache");
	}

	static void setSharedURLCache (NSURLCache cache)
	{
		return invokeObjcSuperClass!(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)
	{
		typeof(this).alloc.initWithMemoryCapacity(memoryCapacity, diskCapacity, path);
	}

	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");
	}
}