Mercurial > projects > dstep
view dstep/foundation/NSData.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.NSData; import dstep.foundation.NSCoder; import dstep.foundation.NSError; import dstep.foundation.NSObjCRuntime; import dstep.foundation.NSObject; import dstep.foundation.NSRange; import dstep.foundation.NSString; import dstep.foundation.NSURL; import dstep.foundation.NSZone; import dstep.objc.bridge.Bridge; import dstep.objc.objc; enum { NSMappedRead = 1, NSUncachedRead = 2 } enum { NSAtomicWrite = 1 } const TNSDataCreation = ` static Object data () { return invokeObjcSuperClass!(Object, "data"); } static Object dataWithBytes (void* bytes, NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) { return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); } static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } static Object dataWithContentsOfFile (NSString path) { return invokeObjcSuperClass!(Object, "dataWithContentsOfFile:", NSString)(path); } static Object dataWithContentsOfURL (NSURL url) { return invokeObjcSuperClass!(Object, "dataWithContentsOfURL:", NSURL)(url); } static Object dataWithContentsOfMappedFile (NSString path) { return invokeObjcSuperClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); } Object initWithBytes (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); } this (void* bytes, NSUInteger length) { typeof(this).alloc.initWithBytes(bytes, length); } Object initWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } this (void* bytes, NSUInteger length) { typeof(this).alloc.initWithBytesNoCopy(bytes, length); } Object initWithBytesNoCopy (void* bytes, NSUInteger length, bool b) { return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); } this (void* bytes, NSUInteger length, bool b) { typeof(this).alloc.initWithBytesNoCopy(bytes, length, b); } Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } this (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { typeof(this).alloc.initWithContentsOfFile(path, readOptionsMask, errorPtr); } Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } this (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { typeof(this).alloc.initWithContentsOfURL(url, readOptionsMask, errorPtr); } Object initWithContentsOfFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); } this (NSString path) { typeof(this).alloc.initWithContentsOfFile(path); } Object initWithContentsOfURL (NSURL url) { return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); } this (NSURL url) { typeof(this).alloc.initWithContentsOfURL(url); } Object initWithContentsOfMappedFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); } this (NSString path) { typeof(this).alloc.initWithContentsOfMappedFile(path); } Object initWithData (NSData data) { return invokeObjcSelf!(Object, "initWithData:", NSData)(data); } this (NSData data) { typeof(this).alloc.initWithData(data); } static Object dataWithData (NSData data) { return invokeObjcSuperClass!(Object, "dataWithData:", NSData)(data); } `; const TNSMutableDataCreation = ` static Object dataWithCapacity (NSUInteger aNumItems) { return invokeObjcSuperClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); } static Object dataWithLength (NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithLength:", NSUInteger)(length); } Object initWithCapacity (NSUInteger capacity) { return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); } this (NSUInteger capacity) { typeof(this).alloc.initWithCapacity(capacity); } Object initWithLength (NSUInteger length) { return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); } this (NSUInteger length) { typeof(this).alloc.initWithLength(length); } `; const TNSExtendedMutableData = ` void appendBytes (void* bytes, NSUInteger length) { return invokeObjcSelf!(void, "appendBytes:length:", void*, NSUInteger)(bytes, length); } void appendData (NSData other) { return invokeObjcSelf!(void, "appendData:", NSData)(other); } void increaseLengthBy (NSUInteger extraLength) { return invokeObjcSelf!(void, "increaseLengthBy:", NSUInteger)(extraLength); } void replaceBytesInRange (NSRange range, void* bytes) { return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:", NSRange, void*)(range, bytes); } void resetBytesInRange (NSRange range) { return invokeObjcSelf!(void, "resetBytesInRange:", NSRange)(range); } void setData (NSData data) { return invokeObjcSelf!(void, "setData:", NSData)(data); } void replaceBytesInRange (NSRange range, void* replacementBytes, NSUInteger replacementLength) { return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:length:", NSRange, void*, NSUInteger)(range, replacementBytes, replacementLength); } `; const TNSExtendedData = ` NSString description () { return invokeObjcSelf!(NSString, "description"); } void getBytes (void* buffer) { return invokeObjcSelf!(void, "getBytes:", void*)(buffer); } void getBytes (void* buffer, NSUInteger length) { return invokeObjcSelf!(void, "getBytes:length:", void*, NSUInteger)(buffer, length); } void getBytes (void* buffer, NSRange range) { return invokeObjcSelf!(void, "getBytes:range:", void*, NSRange)(buffer, range); } bool isEqualToData (NSData other) { return invokeObjcSelf!(bool, "isEqualToData:", NSData)(other); } NSData subdataWithRange (NSRange range) { return invokeObjcSelf!(NSData, "subdataWithRange:", NSRange)(range); } bool writeToFile (NSString path, bool useAuxiliaryFile) { return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); } bool writeToURL (NSURL url, bool atomically) { return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); } bool writeToFile (NSString path, NSUInteger writeOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(bool, "writeToFile:options:error:", NSString, NSUInteger, NSError**)(path, writeOptionsMask, errorPtr); } bool writeToURL (NSURL url, NSUInteger writeOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(bool, "writeToURL:options:error:", NSURL, NSUInteger, NSError**)(url, writeOptionsMask, errorPtr); } `; class NSData : NSObject, INSCopying, INSMutableCopying, INSCoding { mixin (ObjcWrap); this () { super(typeof(this).alloc.init.objcObject); } typeof(this) init () { return invokeObjcSelf!(typeof(this), "init"); } NSUInteger length () { return invokeObjcSelf!(NSUInteger, "length"); } void* bytes () { return invokeObjcSelf!(void*, "bytes"); } Object copyWithZone (NSZone* zone) { return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); } Object mutableCopyWithZone (NSZone* zone) { return invokeObjcSelf!(Object, "mutableCopyWithZone:", NSZone*)(zone); } 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); } // TNSDataCreation static Object data () { return invokeObjcSuperClass!(Object, "data"); } static Object dataWithBytes (void* bytes, NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) { return invokeObjcSuperClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); } static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSuperClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } static Object dataWithContentsOfFile (NSString path) { return invokeObjcSuperClass!(Object, "dataWithContentsOfFile:", NSString)(path); } static Object dataWithContentsOfURL (NSURL url) { return invokeObjcSuperClass!(Object, "dataWithContentsOfURL:", NSURL)(url); } static Object dataWithContentsOfMappedFile (NSString path) { return invokeObjcSuperClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); } Object initWithBytes (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); } this (void* bytes, NSUInteger length) { typeof(this).alloc.initWithBytes(bytes, length); } Object initWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } Object initWithBytesNoCopy (void* bytes, NSUInteger length, bool b) { return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); } this (void* bytes, NSUInteger length, bool b) { typeof(this).alloc.initWithBytesNoCopy(bytes, length, b); } Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, id*)(path, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } this (NSString path, NSUInteger readOptionsMask, ref NSError errorPtr) { typeof(this).alloc.initWithContentsOfFile(path, readOptionsMask, errorPtr); } Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { id error; if (errorPtr) error = new objc_object; Object result = invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, id*)(url, readOptionsMask, &error); if (error) errorPtr = new NSError(error); return result; } this (NSURL url, NSUInteger readOptionsMask, ref NSError errorPtr) { typeof(this).alloc.initWithContentsOfURL(url, readOptionsMask, errorPtr); } Object initWithContentsOfFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); } this (NSString path) { typeof(this).alloc.initWithContentsOfFile(path); } Object initWithContentsOfURL (NSURL url) { return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); } this (NSURL url) { typeof(this).alloc.initWithContentsOfURL(url); } Object initWithContentsOfMappedFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); } Object initWithData (NSData data) { return invokeObjcSelf!(Object, "initWithData:", NSData)(data); } this (NSData data) { typeof(this).alloc.initWithData(data); } static Object dataWithData (NSData data) { return invokeObjcSuperClass!(Object, "dataWithData:", NSData)(data); } // TNSExtendedData NSString description () { return invokeObjcSelf!(NSString, "description"); } void getBytes (void* buffer) { return invokeObjcSelf!(void, "getBytes:", void*)(buffer); } void getBytes (void* buffer, NSUInteger length) { return invokeObjcSelf!(void, "getBytes:length:", void*, NSUInteger)(buffer, length); } void getBytes (void* buffer, NSRange range) { return invokeObjcSelf!(void, "getBytes:range:", void*, NSRange)(buffer, range); } bool isEqualToData (NSData other) { return invokeObjcSelf!(bool, "isEqualToData:", NSData)(other); } NSData subdataWithRange (NSRange range) { return invokeObjcSelf!(NSData, "subdataWithRange:", NSRange)(range); } bool writeToFile (NSString path, bool useAuxiliaryFile) { return invokeObjcSelf!(bool, "writeToFile:atomically:", NSString, bool)(path, useAuxiliaryFile); } bool writeToURL (NSURL url, bool atomically) { return invokeObjcSelf!(bool, "writeToURL:atomically:", NSURL, bool)(url, atomically); } bool writeToFile (NSString path, NSUInteger writeOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(bool, "writeToFile:options:error:", NSString, NSUInteger, NSError**)(path, writeOptionsMask, errorPtr); } bool writeToURL (NSURL url, NSUInteger writeOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(bool, "writeToURL:options:error:", NSURL, NSUInteger, NSError**)(url, writeOptionsMask, errorPtr); } } class NSMutableData : NSData { mixin (ObjcWrap); this () { super(typeof(this).alloc.init.objcObject); } typeof(this) init () { return invokeObjcSelf!(typeof(this), "init"); } void* mutableBytes () { return invokeObjcSelf!(void*, "mutableBytes"); } void setLength (NSUInteger length) { return invokeObjcSelf!(void, "setLength:", NSUInteger)(length); } // TNSMutableDataCreation static Object dataWithCapacity (NSUInteger aNumItems) { return invokeObjcSuperClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); } static Object dataWithLength (NSUInteger length) { return invokeObjcSuperClass!(Object, "dataWithLength:", NSUInteger)(length); } Object initWithCapacity (NSUInteger capacity) { return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); } Object initWithLength (NSUInteger length) { return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); } this (NSUInteger length) { typeof(this).alloc.initWithLength(length); } // TNSExtendedMutableData void appendBytes (void* bytes, NSUInteger length) { return invokeObjcSelf!(void, "appendBytes:length:", void*, NSUInteger)(bytes, length); } void appendData (NSData other) { return invokeObjcSelf!(void, "appendData:", NSData)(other); } void increaseLengthBy (NSUInteger extraLength) { return invokeObjcSelf!(void, "increaseLengthBy:", NSUInteger)(extraLength); } void replaceBytesInRange (NSRange range, void* bytes) { return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:", NSRange, void*)(range, bytes); } void resetBytesInRange (NSRange range) { return invokeObjcSelf!(void, "resetBytesInRange:", NSRange)(range); } void setData (NSData data) { return invokeObjcSelf!(void, "setData:", NSData)(data); } void replaceBytesInRange (NSRange range, void* replacementBytes, NSUInteger replacementLength) { return invokeObjcSelf!(void, "replaceBytesInRange:withBytes:length:", NSRange, void*, NSUInteger)(range, replacementBytes, replacementLength); } }