Mercurial > projects > dstep
view dstep/foundation/NSData.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.NSData; import dstep.foundation.NSError; import dstep.foundation.NSObject; import dstep.foundation.NSRange; import dstep.foundation.NSString; import dstep.foundation.NSURL; import dstep.objc.bridge.Bridge; import dstep.objc.objc : id; enum { NSMappedRead = 1, NSUncachedRead = 2 } enum { NSAtomicWrite = 1 } class NSData : NSObject, INSCopying, INSMutableCopying, INSCoding { mixin ObjcWrap; mixin TNSDataCreation; mixin TNSExtendedData; 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) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); if (result) objcObject = ret; dObject = this; } } class NSMutableData : NSData { mixin ObjcWrap; mixin TNSMutableDataCreation; mixin TNSExtendedMutableData; void* mutableBytes () { return invokeObjcSelf!(void*, "mutableBytes"); } void setLength (NSUInteger length) { return invokeObjcSelf!(void, "setLength:", NSUInteger)(length); } } template TNSDataCreation () { static Object data () { return invokeObjcSelfClass!(Object, "data"); } static Object dataWithBytes (void* bytes, NSUInteger length) { return invokeObjcSelfClass!(Object, "dataWithBytes:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSelfClass!(Object, "dataWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } static Object dataWithBytesNoCopy (void* bytes, NSUInteger length, bool b) { return invokeObjcSelfClass!(Object, "dataWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(bytes, length, b); } static Object dataWithContentsOfFile (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) { return invokeObjcSelfClass!(Object, "dataWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(path, readOptionsMask, errorPtr); } static Object dataWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) { return invokeObjcSelfClass!(Object, "dataWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(url, readOptionsMask, errorPtr); } static Object dataWithContentsOfFile (NSString path) { return invokeObjcSelfClass!(Object, "dataWithContentsOfFile:", NSString)(path); } static Object dataWithContentsOfURL (NSURL url) { return invokeObjcSelfClass!(Object, "dataWithContentsOfURL:", NSURL)(url); } static Object dataWithContentsOfMappedFile (NSString path) { return invokeObjcSelfClass!(Object, "dataWithContentsOfMappedFile:", NSString)(path); } Object initWithBytes (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytes:length:", void*, NSUInteger)(bytes, length); } this (void* bytes, NSUInteger length) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithBytes:length:", void*, NSUInteger)(objcObject, bytes, length); if (result) objcObject = ret; dObject = this; } Object initWithBytesNoCopy (void* bytes, NSUInteger length) { return invokeObjcSelf!(Object, "initWithBytesNoCopy:length:", void*, NSUInteger)(bytes, length); } this (void* bytes, NSUInteger length) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithBytesNoCopy:length:", void*, NSUInteger)(objcObject, bytes, length); if (result) objcObject = ret; dObject = this; } 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) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithBytesNoCopy:length:freeWhenDone:", void*, NSUInteger, bool)(objcObject, bytes, length, b); if (result) objcObject = ret; dObject = this; } Object initWithContentsOfFile (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(Object, "initWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(path, readOptionsMask, errorPtr); } this (NSString path, NSUInteger readOptionsMask, NSError** errorPtr) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:options:error:", NSString, NSUInteger, NSError**)(objcObject, path, readOptionsMask, errorPtr); if (result) objcObject = ret; dObject = this; } Object initWithContentsOfURL (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) { return invokeObjcSelf!(Object, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(url, readOptionsMask, errorPtr); } this (NSURL url, NSUInteger readOptionsMask, NSError** errorPtr) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:options:error:", NSURL, NSUInteger, NSError**)(objcObject, url, readOptionsMask, errorPtr); if (result) objcObject = ret; dObject = this; } Object initWithContentsOfFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfFile:", NSString)(path); } this (NSString path) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfFile:", NSString)(objcObject, path); if (result) objcObject = ret; dObject = this; } Object initWithContentsOfURL (NSURL url) { return invokeObjcSelf!(Object, "initWithContentsOfURL:", NSURL)(url); } this (NSURL url) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfURL:", NSURL)(objcObject, url); if (result) objcObject = ret; dObject = this; } Object initWithContentsOfMappedFile (NSString path) { return invokeObjcSelf!(Object, "initWithContentsOfMappedFile:", NSString)(path); } this (NSString path) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithContentsOfMappedFile:", NSString)(objcObject, path); if (result) objcObject = ret; dObject = this; } Object initWithData (NSData data) { return invokeObjcSelf!(Object, "initWithData:", NSData)(data); } this (NSData data) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithData:", NSData)(objcObject, data); if (result) objcObject = ret; dObject = this; } static Object dataWithData (NSData data) { return invokeObjcSelfClass!(Object, "dataWithData:", NSData)(data); } } template TNSMutableDataCreation () { static Object dataWithCapacity (NSUInteger aNumItems) { return invokeObjcSelfClass!(Object, "dataWithCapacity:", NSUInteger)(aNumItems); } static Object dataWithLength (NSUInteger length) { return invokeObjcSelfClass!(Object, "dataWithLength:", NSUInteger)(length); } Object initWithCapacity (NSUInteger capacity) { return invokeObjcSelf!(Object, "initWithCapacity:", NSUInteger)(capacity); } this (NSUInteger capacity) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithCapacity:", NSUInteger)(objcObject, capacity); if (result) objcObject = ret; dObject = this; } Object initWithLength (NSUInteger length) { return invokeObjcSelf!(Object, "initWithLength:", NSUInteger)(length); } this (NSUInteger length) { objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); id result = Bridge.invokeObjcMethod!(id, "initWithLength:", NSUInteger)(objcObject, length); if (result) objcObject = ret; dObject = this; } } template 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); } } template 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); } }