1995-04-09 02:35:28 +00:00
|
|
|
/* Interface for NSData for GNUStep
|
1995-07-01 19:01:11 +00:00
|
|
|
Copyright (C) 1995 Free Software Foundation, Inc.
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
1995-07-01 19:01:11 +00:00
|
|
|
Date: 1995
|
1995-04-09 02:35:28 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-09 02:35:28 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1995-04-09 02:35:28 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1995-04-09 02:35:28 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1995-04-09 02:35:28 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2006-10-31 07:05:46 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
1995-04-09 02:35:28 +00:00
|
|
|
*/
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
#ifndef __NSData_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSData_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
1995-04-09 02:35:28 +00:00
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
#import <Foundation/NSRange.h>
|
|
|
|
#import <Foundation/NSSerialization.h>
|
1995-04-09 02:35:28 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2008-06-06 13:57:06 +00:00
|
|
|
@class NSError;
|
2000-09-22 13:45:58 +00:00
|
|
|
@class NSURL;
|
|
|
|
#endif
|
|
|
|
|
2008-06-06 13:57:06 +00:00
|
|
|
#if OS_API_VERSION(100400,GS_API_LATEST)
|
|
|
|
enum {
|
|
|
|
NSMappedRead = 1,
|
|
|
|
NSUncachedRead = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
NSAtomicWrite = 1
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1997-10-28 14:34:49 +00:00
|
|
|
@interface NSData : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
1995-04-09 02:35:28 +00:00
|
|
|
|
|
|
|
// Allocating and Initializing a Data Object
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) data;
|
|
|
|
+ (id) dataWithBytes: (const void*)bytes
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)length;
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) dataWithBytesNoCopy: (void*)bytes
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)length;
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2002-08-27 12:26:17 +00:00
|
|
|
+ (id) dataWithBytesNoCopy: (void*)aBuffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)bufferSize
|
2002-08-27 12:26:17 +00:00
|
|
|
freeWhenDone: (BOOL)shouldFree;
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) dataWithContentsOfFile: (NSString*)path;
|
|
|
|
+ (id) dataWithContentsOfMappedFile: (NSString*)path;
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2000-09-22 13:45:58 +00:00
|
|
|
+ (id) dataWithContentsOfURL: (NSURL*)url;
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) dataWithData: (NSData*)data;
|
2001-12-17 14:31:42 +00:00
|
|
|
- (id) initWithBytes: (const void*)aBuffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)bufferSize;
|
2001-12-17 14:31:42 +00:00
|
|
|
- (id) initWithBytesNoCopy: (void*)aBuffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)bufferSize;
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2002-08-27 12:26:17 +00:00
|
|
|
- (id) initWithBytesNoCopy: (void*)aBuffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)bufferSize
|
2002-08-27 12:26:17 +00:00
|
|
|
freeWhenDone: (BOOL)shouldFree;
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithContentsOfFile: (NSString*)path;
|
|
|
|
- (id) initWithContentsOfMappedFile: (NSString*)path;
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2000-09-22 13:45:58 +00:00
|
|
|
- (id) initWithContentsOfURL: (NSURL*)url;
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithData: (NSData*)data;
|
1995-04-09 02:35:28 +00:00
|
|
|
|
|
|
|
// Accessing Data
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (const void*) bytes;
|
|
|
|
- (NSString*) description;
|
|
|
|
- (void) getBytes: (void*)buffer;
|
|
|
|
- (void) getBytes: (void*)buffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)length;
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) getBytes: (void*)buffer
|
|
|
|
range: (NSRange)aRange;
|
|
|
|
- (NSData*) subdataWithRange: (NSRange)aRange;
|
1995-04-09 02:35:28 +00:00
|
|
|
|
|
|
|
// Querying a Data Object
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (BOOL) isEqualToData: (NSData*)other;
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSUInteger) length;
|
1995-04-09 02:35:28 +00:00
|
|
|
|
2009-04-27 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* <p>Writes a copy of the data encapsulated by the receiver to a file
|
|
|
|
* at path. If the useAuxiliaryFile flag is YES, this writes to a
|
|
|
|
* temporary file and then renames that to the file at path, thus
|
|
|
|
* ensuring that path exists and does not contain partially written
|
|
|
|
* data at any point.
|
|
|
|
* </p>
|
|
|
|
* <p>On success returns YES, on failure returns NO.
|
|
|
|
* </p>
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (BOOL) writeToFile: (NSString*)path
|
|
|
|
atomically: (BOOL)useAuxiliaryFile;
|
1995-04-09 02:35:28 +00:00
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2009-04-27 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* Writes a copy of the contents of the receiver to the specified URL.
|
|
|
|
*/
|
2002-01-02 10:27:26 +00:00
|
|
|
- (BOOL) writeToURL: (NSURL*)anURL atomically: (BOOL)flag;
|
|
|
|
#endif
|
|
|
|
|
1995-04-09 02:35:28 +00:00
|
|
|
// Deserializing Data
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
- (unsigned int) deserializeAlignedBytesLengthAtCursor: (unsigned int*)cursor;
|
|
|
|
- (void) deserializeBytes: (void*)buffer
|
|
|
|
length: (unsigned int)bytes
|
|
|
|
atCursor: (unsigned int*)cursor;
|
|
|
|
- (void) deserializeDataAt: (void*)data
|
|
|
|
ofObjCType: (const char*)type
|
|
|
|
atCursor: (unsigned int*)cursor
|
|
|
|
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
|
|
|
- (int) deserializeIntAtCursor: (unsigned int*)cursor;
|
2001-12-17 14:31:42 +00:00
|
|
|
- (int) deserializeIntAtIndex: (unsigned int)index;
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) deserializeInts: (int*)intBuffer
|
|
|
|
count: (unsigned int)numInts
|
|
|
|
atCursor: (unsigned int*)cursor;
|
|
|
|
- (void) deserializeInts: (int*)intBuffer
|
|
|
|
count: (unsigned int)numInts
|
|
|
|
atIndex: (unsigned int)index;
|
1995-04-09 02:35:28 +00:00
|
|
|
|
2008-06-06 13:57:06 +00:00
|
|
|
#if OS_API_VERSION(100400,GS_API_LATEST)
|
2009-04-27 08:16:06 +00:00
|
|
|
/**
|
|
|
|
* <p>Writes a copy of the data encapsulated by the receiver to a file
|
|
|
|
* at path. If the NSAtomicWrite option is set, this writes to a
|
|
|
|
* temporary file and then renames that to the file at path, thus
|
|
|
|
* ensuring that path exists and does not contain partially written
|
|
|
|
* data at any point.
|
|
|
|
* </p>
|
|
|
|
* <p>On success returns YES, on failure returns NO.
|
|
|
|
* </p>
|
|
|
|
*/
|
2008-06-06 13:57:06 +00:00
|
|
|
- (BOOL) writeToFile: (NSString *)path
|
|
|
|
options: (NSUInteger)writeOptionsMask
|
|
|
|
error: (NSError **)errorPtr;
|
2009-04-27 08:16:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes a copy of the contents of the receiver to the specified URL.
|
|
|
|
*/
|
2008-06-06 13:57:06 +00:00
|
|
|
- (BOOL) writeToURL: (NSURL *)url
|
|
|
|
options: (NSUInteger)writeOptionsMask
|
|
|
|
error: (NSError **)errorPtr;
|
|
|
|
#endif
|
1995-04-09 02:35:28 +00:00
|
|
|
@end
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
|
1999-01-27 12:49:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We include special support for coding/decoding - adding methods for
|
|
|
|
* serializing/deserializing type-tags and cross-references.
|
|
|
|
*
|
|
|
|
* A type-tag is a byte containing -
|
|
|
|
* Bit7 Set to indicate that the tag is for a cross-reference.
|
|
|
|
* Bit5-6 A value for the size of the type or cross-reference.
|
|
|
|
* Bit0-4 A value representing an Objective-C type.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _GSC_NONE 0x00 /* No type information. */
|
|
|
|
#define _GSC_XREF 0x80 /* Cross reference to an item. */
|
|
|
|
#define _GSC_SIZE 0x60 /* Type-size info mask. */
|
|
|
|
#define _GSC_MASK 0x1f /* Basic type info mask. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the tag is for a cross-reference, the size field defines the
|
|
|
|
* size of the cross-reference value -
|
|
|
|
* _GSC_X_0 (no crossref), _GSC_X_1, _GSC_X_2, _GSC_X_4
|
|
|
|
*/
|
|
|
|
#define _GSC_X_0 0x00 /* nil or null pointer */
|
|
|
|
#define _GSC_X_1 0x20 /* 8-bit cross-ref */
|
|
|
|
#define _GSC_X_2 0x40 /* 16-bit cross-ref */
|
|
|
|
#define _GSC_X_4 0x60 /* 32-bit cross-ref */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the tag is for an integer value, the size field defines the
|
|
|
|
* size of the the encoded integer -
|
|
|
|
* _GSC_I16, _GSC_I32, _GSC_I64, _GSC_I128
|
|
|
|
* The file GSConfig.h (produced by the configure script) defines the
|
|
|
|
* size codes for this machines 'natural' integers -
|
|
|
|
* _GSC_S_SHT, _GSC_S_INT, _GSC_S_LNG, _GSC_S_LNG_LNG
|
|
|
|
*/
|
|
|
|
#define _GSC_I16 0x00
|
|
|
|
#define _GSC_I32 0x20
|
|
|
|
#define _GSC_I64 0x40
|
|
|
|
#define _GSC_I128 0x60
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the first sixteen types, the size information applies to the
|
|
|
|
* size of the type, for the second sixteen it applies to the
|
|
|
|
* following cross-reference number (or is zero if no crossref follows).
|
|
|
|
*/
|
|
|
|
#define _GSC_MAYX 0x10 /* Item may have crossref. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the types that can be archived -
|
|
|
|
*/
|
|
|
|
#define _GSC_CHR 0x01
|
|
|
|
#define _GSC_UCHR 0x02
|
|
|
|
#define _GSC_SHT 0x03
|
|
|
|
#define _GSC_USHT 0x04
|
|
|
|
#define _GSC_INT 0x05
|
|
|
|
#define _GSC_UINT 0x06
|
|
|
|
#define _GSC_LNG 0x07
|
|
|
|
#define _GSC_ULNG 0x08
|
|
|
|
#define _GSC_LNG_LNG 0x09
|
|
|
|
#define _GSC_ULNG_LNG 0x0a
|
|
|
|
#define _GSC_FLT 0x0b
|
|
|
|
#define _GSC_DBL 0x0c
|
|
|
|
|
|
|
|
#define _GSC_ID 0x10
|
|
|
|
#define _GSC_CLASS 0x11
|
|
|
|
#define _GSC_SEL 0x12
|
|
|
|
#define _GSC_PTR 0x13
|
|
|
|
#define _GSC_CHARPTR 0x14
|
|
|
|
#define _GSC_ARY_B 0x15
|
|
|
|
#define _GSC_STRUCT_B 0x16
|
2000-08-07 22:00:31 +00:00
|
|
|
#define _GSC_CID 0x17 /* Class encoded as id */
|
1999-01-27 12:49:49 +00:00
|
|
|
|
1997-09-29 14:39:53 +00:00
|
|
|
@interface NSData (GNUstepExtensions)
|
2009-02-23 20:42:32 +00:00
|
|
|
+ (id) dataWithShmID: (int)anID length: (NSUInteger) length;
|
|
|
|
+ (id) dataWithSharedBytes: (const void*)bytes length: (NSUInteger) length;
|
1998-10-23 15:48:21 +00:00
|
|
|
|
|
|
|
/*
|
1999-01-27 12:49:49 +00:00
|
|
|
* -deserializeTypeTag:andCrossRef:atCursor:
|
|
|
|
* This method is provided in order to give the GNUstep version of
|
1998-10-23 15:48:21 +00:00
|
|
|
* NSUnarchiver maximum possible performance.
|
|
|
|
*/
|
1999-01-27 12:49:49 +00:00
|
|
|
- (void) deserializeTypeTag: (unsigned char*)tag
|
2001-12-17 14:31:42 +00:00
|
|
|
andCrossRef: (unsigned int*)ref
|
|
|
|
atCursor: (unsigned int*)cursor;
|
1997-09-29 14:39:53 +00:00
|
|
|
@end
|
1998-11-10 20:23:39 +00:00
|
|
|
#endif
|
1995-04-17 20:42:02 +00:00
|
|
|
|
|
|
|
@interface NSMutableData : NSData
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
+ (id) dataWithCapacity: (NSUInteger)numBytes;
|
|
|
|
+ (id) dataWithLength: (NSUInteger)length;
|
|
|
|
- (id) initWithCapacity: (NSUInteger)capacity;
|
|
|
|
- (id) initWithLength: (NSUInteger)length;
|
1995-04-17 20:42:02 +00:00
|
|
|
|
|
|
|
// Adjusting Capacity
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (void) increaseLengthBy: (NSUInteger)extraLength;
|
|
|
|
- (void) setLength: (NSUInteger)size;
|
1995-04-17 20:42:02 +00:00
|
|
|
- (void*) mutableBytes;
|
|
|
|
|
|
|
|
// Appending Data
|
|
|
|
|
2001-12-17 14:31:42 +00:00
|
|
|
- (void) appendBytes: (const void*)aBuffer
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)bufferSize;
|
1995-04-17 20:42:02 +00:00
|
|
|
- (void) appendData: (NSData*)other;
|
|
|
|
|
|
|
|
// Modifying Data
|
|
|
|
|
|
|
|
- (void) replaceBytesInRange: (NSRange)aRange
|
|
|
|
withBytes: (const void*)bytes;
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2002-08-27 12:26:17 +00:00
|
|
|
- (void) replaceBytesInRange: (NSRange)aRange
|
|
|
|
withBytes: (const void*)bytes
|
2009-02-23 20:42:32 +00:00
|
|
|
length: (NSUInteger)length;
|
2002-08-27 12:26:17 +00:00
|
|
|
#endif
|
1995-04-17 20:42:02 +00:00
|
|
|
- (void) resetBytesInRange: (NSRange)aRange;
|
1998-01-19 15:20:15 +00:00
|
|
|
- (void) setData: (NSData*)data;
|
1995-04-17 20:42:02 +00:00
|
|
|
|
|
|
|
// Serializing Data
|
|
|
|
|
|
|
|
- (void) serializeAlignedBytesLength: (unsigned int)length;
|
|
|
|
- (void) serializeDataAt: (const void*)data
|
|
|
|
ofObjCType: (const char*)type
|
|
|
|
context: (id <NSObjCTypeSerializationCallBack>)callback;
|
|
|
|
- (void) serializeInt: (int)value;
|
|
|
|
- (void) serializeInt: (int)value
|
2001-12-17 14:31:42 +00:00
|
|
|
atIndex: (unsigned int)index;
|
1995-04-17 20:42:02 +00:00
|
|
|
- (void) serializeInts: (int*)intBuffer
|
|
|
|
count: (unsigned int)numInts;
|
|
|
|
- (void) serializeInts: (int*)intBuffer
|
|
|
|
count: (unsigned int)numInts
|
2001-12-17 14:31:42 +00:00
|
|
|
atIndex: (unsigned int)index;
|
1995-04-17 20:42:02 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
|
2003-04-17 06:20:17 +00:00
|
|
|
|
1997-09-29 14:39:53 +00:00
|
|
|
@interface NSMutableData (GNUstepExtensions)
|
1998-10-23 15:48:21 +00:00
|
|
|
/*
|
|
|
|
* Capacity management - GNUstep gives you control over the size of
|
|
|
|
* the data buffer as well as the 'length' of valid data in it.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSUInteger) capacity;
|
|
|
|
- (id) setCapacity: (NSUInteger)newCapacity;
|
1998-10-23 15:48:21 +00:00
|
|
|
|
|
|
|
- (int) shmID; /* Shared memory ID for data buffer (if any) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -serializeTypeTag:
|
1999-01-27 12:49:49 +00:00
|
|
|
* -serializeTypeTag:andCrossRef:
|
1998-10-23 15:48:21 +00:00
|
|
|
* These methods are provided in order to give the GNUstep version of
|
|
|
|
* NSArchiver maximum possible performance.
|
|
|
|
*/
|
|
|
|
- (void) serializeTypeTag: (unsigned char)tag;
|
1999-01-27 12:49:49 +00:00
|
|
|
- (void) serializeTypeTag: (unsigned char)tag
|
2001-12-17 14:31:42 +00:00
|
|
|
andCrossRef: (unsigned int)xref;
|
1998-10-23 15:48:21 +00:00
|
|
|
|
1997-09-29 14:39:53 +00:00
|
|
|
@end
|
1998-11-10 20:23:39 +00:00
|
|
|
#endif
|
1997-09-29 14:39:53 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
1995-04-17 20:42:02 +00:00
|
|
|
|
2010-02-20 17:16:23 +00:00
|
|
|
#if !NO_GNUSTEP && !defined(GNUSTEP_BASE_INTERNAL)
|
2010-02-18 11:40:58 +00:00
|
|
|
#import <GNUstepBase/NSData+GNUstepBase.h>
|
|
|
|
#endif
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
#endif /* __NSData_h_GNUSTEP_BASE_INCLUDE */
|