view dstep/foundation/NSKeyedArchiver.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 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.NSKeyedArchiver;

import dstep.foundation.NSArray;
import dstep.foundation.NSCoder;
import dstep.foundation.NSData;
import dstep.foundation.NSGeometry;
import dstep.foundation.NSObjCRuntime;
import dstep.foundation.NSPropertyList;
import dstep.foundation.NSString;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;
import bindings = dstep.foundation.NSKeyedArchiver_bindings;

private
{
	NSString NSInvalidArchiveOperationException_;
	NSString NSInvalidUnarchiveOperationException_;
}

NSString NSInvalidArchiveOperationException ()
{
	if (NSInvalidArchiveOperationException_)
		return NSInvalidArchiveOperationException_;
		
	return NSInvalidArchiveOperationException_ = new NSString(bindings.NSInvalidArchiveOperationException);
}

NSString NSInvalidUnarchiveOperationException ()
{
	if (NSInvalidUnarchiveOperationException_)
		return NSInvalidUnarchiveOperationException_;
		
	return NSInvalidUnarchiveOperationException_ = new NSString(bindings.NSInvalidUnarchiveOperationException);
}

const TNSKeyedArchiverObjectSubstitution = `

	Class classForKeyedArchiver ()
	{
		return invokeObjcSelf!(Class, "classForKeyedArchiver");
	}
	
	Object replacementObjectForKeyedArchiver (NSKeyedArchiver archiver)
	{
		return invokeObjcSelf!(Object, "replacementObjectForKeyedArchiver:", NSKeyedArchiver)(archiver);
	}
	
	static NSArray classFallbacksForKeyedArchiver ()
	{
		return invokeObjcSelfClass!(NSArray, "classFallbacksForKeyedArchiver");
	}
	
	//mixin ObjcBindMethod!(classForKeyedArchiver, "classForKeyedArchiver");
	//mixin ObjcBindMethod!(replacementObjectForKeyedArchiver, "replacementObjectForKeyedArchiver:");
	//mixin ObjcBindClassMethod!(classFallbacksForKeyedArchiver, "classFallbacksForKeyedArchiver");
`;

const TNSKeyedUnarchiverObjectSubstitution = `

	static Class classForKeyedUnarchiver ()
	{
		return invokeObjcSelfClass!(Class, "classForKeyedUnarchiver");
	}
	
	//mixin ObjcBindClassMethod!(classForKeyedUnarchiver, "classForKeyedUnarchiver");
`;

const TNSKeyedUnarchiverDelegate = `

	Class unarchiver (NSKeyedUnarchiver unarchiver, NSString name, NSArray classNames)
	{
		return invokeObjcSelf!(Class, "unarchiver:cannotDecodeObjectOfClassName:originalClasses:", NSKeyedUnarchiver, NSString, NSArray)(unarchiver, name, classNames);
	}
	
	Object unarchiver (NSKeyedUnarchiver unarchiver, Object object)
	{
		return invokeObjcSelf!(Object, "unarchiver:didDecodeObject:", NSKeyedUnarchiver, Object)(unarchiver, object);
	}
	
	void unarchiver (NSKeyedUnarchiver unarchiver, Object object, Object newObject)
	{
		return invokeObjcSelf!(void, "unarchiver:willReplaceObject:withObject:", NSKeyedUnarchiver, Object, Object)(unarchiver, object, newObject);
	}
	
	void unarchiverWillFinish (NSKeyedUnarchiver unarchiver)
	{
		return invokeObjcSelf!(void, "unarchiverWillFinish:", NSKeyedUnarchiver)(unarchiver);
	}
	
	void unarchiverDidFinish (NSKeyedUnarchiver unarchiver)
	{
		return invokeObjcSelf!(void, "unarchiverDidFinish:", NSKeyedUnarchiver)(unarchiver);
	}
	
	//mixin ObjcBindMethod!(unarchiver, "unarchiver:cannotDecodeObjectOfClassName:originalClasses:");
	//mixin ObjcBindMethod!(unarchiver, "unarchiver:didDecodeObject:");
	//mixin ObjcBindMethod!(unarchiver, "unarchiver:willReplaceObject:withObject:");
	//mixin ObjcBindMethod!(unarchiverWillFinish, "unarchiverWillFinish:");
	//mixin ObjcBindMethod!(unarchiverDidFinish, "unarchiverDidFinish:");
`;

const TNSKeyedArchiverDelegate = `

	Object archiver (NSKeyedArchiver archiver, Object object)
	{
		return invokeObjcSelf!(Object, "archiver:willEncodeObject:", NSKeyedArchiver, Object)(archiver, object);
	}
	
	void archiver_didEncodeObject (NSKeyedArchiver archiver, Object object)
	{
		return invokeObjcSelf!(void, "archiver:didEncodeObject:", NSKeyedArchiver, Object)(archiver, object);
	}
	
	void archiver (NSKeyedArchiver archiver, Object object, Object newObject)
	{
		return invokeObjcSelf!(void, "archiver:willReplaceObject:withObject:", NSKeyedArchiver, Object, Object)(archiver, object, newObject);
	}
	
	void archiverWillFinish (NSKeyedArchiver archiver)
	{
		return invokeObjcSelf!(void, "archiverWillFinish:", NSKeyedArchiver)(archiver);
	}
	
	void archiverDidFinish (NSKeyedArchiver archiver)
	{
		return invokeObjcSelf!(void, "archiverDidFinish:", NSKeyedArchiver)(archiver);
	}
	
	//mixin ObjcBindMethod!(archiver, "archiver:willEncodeObject:");
	//mixin ObjcBindMethod!(archiver_didEncodeObject, "archiver:didEncodeObject:");
	//mixin ObjcBindMethod!(archiver, "archiver:willReplaceObject:withObject::");
	//mixin ObjcBindMethod!(archiverWillFinish, "archiverWillFinish:");
	//mixin ObjcBindMethod!(archiverDidFinish, "archiverDidFinish:");
`;

const TNSGeometryKeyedCoding = `

	void encodePoint (NSPoint point, NSString key)
	{
		return invokeObjcSelf!(void, "encodePoint:forKey:", NSPoint, NSString)(point, key);
	}

	void encodeSize (NSSize size, NSString key)
	{
		return invokeObjcSelf!(void, "encodeSize:forKey:", NSSize, NSString)(size, key);
	}

	void encodeRect (NSRect rect, NSString key)
	{
		return invokeObjcSelf!(void, "encodeRect:forKey:", NSRect, NSString)(rect, key);
	}

	NSPoint decodePointForKey (NSString key)
	{
		return invokeObjcSelf!(NSPoint, "decodePointForKey:", NSString)(key);
	}

	NSSize decodeSizeForKey (NSString key)
	{
		return invokeObjcSelf!(NSSize, "decodeSizeForKey:", NSString)(key);
	}

	NSRect decodeRectForKey (NSString key)
	{
		return invokeObjcSelf!(NSRect, "decodeRectForKey:", NSString)(key);
	}
`;

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

	static NSData archivedDataWithRootObject (Object rootObject)
	{
		return invokeObjcSuperClass!(NSData, "archivedDataWithRootObject:", Object)(rootObject);
	}

	static bool archiveRootObject (Object rootObject, NSString path)
	{
		return invokeObjcSuperClass!(bool, "archiveRootObject:toFile:", Object, NSString)(rootObject, path);
	}

	Object initForWritingWithMutableData (NSMutableData data)
	{
		return invokeObjcSelf!(Object, "initForWritingWithMutableData:", NSMutableData)(data);
	}

	this (NSMutableData data)
	{
		typeof(this).alloc.initForWritingWithMutableData(data);
	}

	void setDelegate (Object delegate_)
	{
		return invokeObjcSelf!(void, "setDelegate:", Object)(delegate_);
	}

	Object delegate_ ()
	{
		return invokeObjcSelf!(Object, "delegate");
	}

	void setOutputFormat (uint format)
	{
		return invokeObjcSelf!(void, "setOutputFormat:", uint)(format);
	}

	uint outputFormat ()
	{
		return invokeObjcSelf!(uint, "outputFormat");
	}

	void finishEncoding ()
	{
		return invokeObjcSelf!(void, "finishEncoding");
	}

	static void setClassName (NSString codedName, Class cls)
	{
		return invokeObjcSuperClass!(void, "setClassName:forClass:", NSString, Class)(codedName, cls);
	}

	void setClassName (NSString codedName, Class cls)
	{
		return invokeObjcSelf!(void, "setClassName:forClass:", NSString, Class)(codedName, cls);
	}

	static NSString classNameForClass (Class cls)
	{
		return invokeObjcSuperClass!(NSString, "classNameForClass:", Class)(cls);
	}

	NSString classNameForClass (Class cls)
	{
		return invokeObjcSelf!(NSString, "classNameForClass:", Class)(cls);
	}

	void encodeObject (Object objv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeObject:forKey:", Object, NSString)(objv, key);
	}

	void encodeConditionalObject (Object objv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeConditionalObject:forKey:", Object, NSString)(objv, key);
	}

	void encodeBool (bool boolv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeBool:forKey:", bool, NSString)(boolv, key);
	}

	void encodeInt (int intv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeInt:forKey:", int, NSString)(intv, key);
	}

	void encodeInt32 (int intv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeInt32:forKey:", int, NSString)(intv, key);
	}

	void encodeInt64 (long intv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeInt64:forKey:", long, NSString)(intv, key);
	}

	void encodeFloat (float realv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeFloat:forKey:", float, NSString)(realv, key);
	}

	void encodeDouble (double realv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeDouble:forKey:", double, NSString)(realv, key);
	}

	void encodeBytes (char* bytesp, NSUInteger lenv, NSString key)
	{
		return invokeObjcSelf!(void, "encodeBytes:length:forKey:", char*, NSUInteger, NSString)(bytesp, lenv, key);
	}
}

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

	static Object unarchiveObjectWithData (NSData data)
	{
		return invokeObjcSuperClass!(Object, "unarchiveObjectWithData:", NSData)(data);
	}

	static Object unarchiveObjectWithFile (NSString path)
	{
		return invokeObjcSuperClass!(Object, "unarchiveObjectWithFile:", NSString)(path);
	}

	Object initForReadingWithData (NSData data)
	{
		return invokeObjcSelf!(Object, "initForReadingWithData:", NSData)(data);
	}

	this (NSData data)
	{
		typeof(this).alloc.initForReadingWithData(data);
	}

	void setDelegate (Object delegate_)
	{
		return invokeObjcSelf!(void, "setDelegate:", Object)(delegate_);
	}

	Object delegate_ ()
	{
		return invokeObjcSelf!(Object, "delegate");
	}

	void finishDecoding ()
	{
		return invokeObjcSelf!(void, "finishDecoding");
	}

	static void setClass (Class cls, NSString codedName)
	{
		return invokeObjcSuperClass!(void, "setClass:forClassName:", Class, NSString)(cls, codedName);
	}

	void setClass (Class cls, NSString codedName)
	{
		return invokeObjcSelf!(void, "setClass:forClassName:", Class, NSString)(cls, codedName);
	}

	static Class classForClassName (NSString codedName)
	{
		return invokeObjcSuperClass!(Class, "classForClassName:", NSString)(codedName);
	}

	Class classForClassName (NSString codedName)
	{
		return invokeObjcSelf!(Class, "classForClassName:", NSString)(codedName);
	}

	bool containsValueForKey (NSString key)
	{
		return invokeObjcSelf!(bool, "containsValueForKey:", NSString)(key);
	}

	Object decodeObjectForKey (NSString key)
	{
		return invokeObjcSelf!(Object, "decodeObjectForKey:", NSString)(key);
	}

	bool decodeBoolForKey (NSString key)
	{
		return invokeObjcSelf!(bool, "decodeBoolForKey:", NSString)(key);
	}

	int decodeIntForKey (NSString key)
	{
		return invokeObjcSelf!(int, "decodeIntForKey:", NSString)(key);
	}

	int decodeInt32ForKey (NSString key)
	{
		return invokeObjcSelf!(int, "decodeInt32ForKey:", NSString)(key);
	}

	long decodeInt64ForKey (NSString key)
	{
		return invokeObjcSelf!(long, "decodeInt64ForKey:", NSString)(key);
	}

	float decodeFloatForKey (NSString key)
	{
		return invokeObjcSelf!(float, "decodeFloatForKey:", NSString)(key);
	}

	double decodeDoubleForKey (NSString key)
	{
		return invokeObjcSelf!(double, "decodeDoubleForKey:", NSString)(key);
	}

	char* decodeBytesForKey (NSString key, NSUInteger* lengthp)
	{
		return invokeObjcSelf!(char*, "decodeBytesForKey:returnedLength:", NSString, NSUInteger*)(key, lengthp);
	}
}