view dstep/foundation/NSCoder.d @ 14:89f3c3ef1fd2

Added the Foundation framework
author Jacob Carlborg <doob@me.com>
date Mon, 03 Aug 2009 15:23:15 +0200
parents
children 19885b43130e
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.NSCoder;

import dstep.foundation.NSData;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc : id;

class NSCoder : NSObject
{
	mixin ObjcWrap;
	mixin TNSGeometryCoding;
	mixin TNSExtendedCoder;
	mixin TNSTypedstreamCompatibility;
	mixin TNSGeometryKeyedCoding;

	void encodeValueOfObjCType (char* type, void* addr)
	{
		return invokeObjcSelf!(void, "encodeValueOfObjCType:at:", char*, void*)(type, addr);
	}

	void encodeDataObject (NSData data)
	{
		return invokeObjcSelf!(void, "encodeDataObject:", NSData)(data);
	}

	void decodeValueOfObjCType (char* type, void* data)
	{
		return invokeObjcSelf!(void, "decodeValueOfObjCType:at:", char*, void*)(type, data);
	}

	NSData decodeDataObject ()
	{
		return invokeObjcSelf!(NSData, "decodeDataObject");
	}

	NSInteger versionForClassName (NSString className)
	{
		return invokeObjcSelf!(NSInteger, "versionForClassName:", NSString)(className);
	}
}

template TNSExtendedCoder ()
{
	void encodeObject (Object object)
	{
		return invokeObjcSelf!(void, "encodeObject:", Object)(object);
	}

	void encodePropertyList (Object aPropertyList)
	{
		return invokeObjcSelf!(void, "encodePropertyList:", Object)(aPropertyList);
	}

	void encodeRootObject (Object rootObject)
	{
		return invokeObjcSelf!(void, "encodeRootObject:", Object)(rootObject);
	}

	void encodeBycopyObject (Object anObject)
	{
		return invokeObjcSelf!(void, "encodeBycopyObject:", Object)(anObject);
	}

	void encodeByrefObject (Object anObject)
	{
		return invokeObjcSelf!(void, "encodeByrefObject:", Object)(anObject);
	}

	void encodeConditionalObject (Object object)
	{
		return invokeObjcSelf!(void, "encodeConditionalObject:", Object)(object);
	}

	void encodeValuesOfObjCTypes (char* encodeValuesOfObjCTypes, ...)
	{
		return invokeObjcSelf!(void, "encodeValuesOfObjCTypes:", char*)(encodeValuesOfObjCTypes);
	}

	void encodeArrayOfObjCType (char* type, NSUInteger count, void* array)
	{
		return invokeObjcSelf!(void, "encodeArrayOfObjCType:count:at:", char*, NSUInteger, void*)(type, count, array);
	}

	void encodeBytes (void* byteaddr, NSUInteger length)
	{
		return invokeObjcSelf!(void, "encodeBytes:length:", void*, NSUInteger)(byteaddr, length);
	}

	Object decodeObject ()
	{
		return invokeObjcSelf!(Object, "decodeObject");
	}

	Object decodePropertyList ()
	{
		return invokeObjcSelf!(Object, "decodePropertyList");
	}

	void decodeValuesOfObjCTypes (char* decodeValuesOfObjCTypes, ...)
	{
		return invokeObjcSelf!(void, "decodeValuesOfObjCTypes:", char*)(decodeValuesOfObjCTypes);
	}

	void decodeArrayOfObjCType (char* itemType, NSUInteger count, void* array)
	{
		return invokeObjcSelf!(void, "decodeArrayOfObjCType:count:at:", char*, NSUInteger, void*)(itemType, count, array);
	}

	void* decodeBytesWithReturnedLength (NSUInteger* lengthp)
	{
		return invokeObjcSelf!(void*, "decodeBytesWithReturnedLength:", NSUInteger*)(lengthp);
	}

	void setObjectZone (NSZone* zone)
	{
		return invokeObjcSelf!(void, "setObjectZone:", NSZone*)(zone);
	}

	NSZone* objectZone ()
	{
		return invokeObjcSelf!(NSZone*, "objectZone");
	}

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

	bool allowsKeyedCoding ()
	{
		return invokeObjcSelf!(bool, "allowsKeyedCoding");
	}

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

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

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

	NSInteger decodeIntegerForKey (NSString key)
	{
		return invokeObjcSelf!(NSInteger, "decodeIntegerForKey:", NSString)(key);
	}
}

template TNSTypedstreamCompatibility ()
{
	void encodeNXObject (Object object)
	{
		return invokeObjcSelf!(void, "encodeNXObject:", Object)(object);
	}

	Object decodeNXObject ()
	{
		return invokeObjcSelf!(Object, "decodeNXObject");
	}
}

NSObject NXReadNSObjectFromCoder (NSCoder decoder)
{
	return Bridge.invokeObjcFunction!(NSObject, bindings.NXReadNSObjectFromCoder, NSCoder)(decoder);
}