Mercurial > projects > dstep
view dstep/foundation/NSCoder.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.NSCoder; import dstep.foundation.NSData; import dstep.foundation.NSGeometry; import dstep.foundation.NSKeyedArchiver; import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; import dstep.foundation.NSString; import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; import dstep.objc.objc; import bindings = dstep.foundation.NSCoder_bindings; const 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); } `; const TNSTypedstreamCompatibility = ` void encodeNXObject (Object object) { return invokeObjcSelf!(void, "encodeNXObject:", Object)(object); } Object decodeNXObject () { return invokeObjcSelf!(Object, "decodeNXObject"); } `; class NSCoder : NSObject { mixin (ObjcWrap); this () { super(typeof(this).alloc.init.objcObject); } NSCoder init () { return invokeObjcSelf!(NSCoder, "init"); } 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); } // TNSGeometryCoding void encodePoint (NSPoint point) { return invokeObjcSelf!(void, "encodePoint:", NSPoint)(point); } NSPoint decodePoint () { return invokeObjcSelf!(NSPoint, "decodePoint"); } void encodeSize (NSSize size) { return invokeObjcSelf!(void, "encodeSize:", NSSize)(size); } NSSize decodeSize () { return invokeObjcSelf!(NSSize, "decodeSize"); } void encodeRect (NSRect rect) { return invokeObjcSelf!(void, "encodeRect:", NSRect)(rect); } NSRect decodeRect () { return invokeObjcSelf!(NSRect, "decodeRect"); } // 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); } // 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); id result = bindings.NXReadNSObjectFromCoder(decoder ? decoder.objcObject : null); return result ? new NSObject(result) : null; }