2002-06-06 14:02:59 +00:00
|
|
|
|
/** Interface for NSArchiver for GNUStep
|
1998-10-24 09:58:16 +00:00
|
|
|
|
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
|
1995-07-01 18:34:58 +00:00
|
|
|
|
|
1996-04-17 20:17:45 +00:00
|
|
|
|
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
2002-06-06 14:02:59 +00:00
|
|
|
|
Rewrite by: Richard Frith-Macdonald <rfm@gnu.org>
|
1995-07-01 18:34:58 +00:00
|
|
|
|
Date: March 1995
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-09 02:42:37 +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:42:37 +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:42:37 +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:42:37 +00:00
|
|
|
|
License along with this library; if not, write to the Free
|
2006-09-13 10:20:49 +00:00
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
Boston, MA 02111 USA.
|
2002-06-06 14:02:59 +00:00
|
|
|
|
|
2004-06-22 22:27:39 +00:00
|
|
|
|
AutogsdocSource:NSUnarchiver.m
|
|
|
|
|
AutogsdocSource:NSArchiver.m
|
|
|
|
|
*/
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#ifndef __NSArchiver_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
|
#define __NSArchiver_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
|
#import <Foundation/NSCoder.h>
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-04-11 05:22:33 +00:00
|
|
|
|
@class NSMutableArray, NSMutableDictionary, NSMutableData, NSData, NSString;
|
1998-10-24 09:58:16 +00:00
|
|
|
|
|
2005-06-05 05:24:45 +00:00
|
|
|
|
#if OS_API_VERSION(GS_API_OSSPEC,GS_API_LATEST)
|
|
|
|
|
|
1995-04-09 02:42:37 +00:00
|
|
|
|
@interface NSArchiver : NSCoder
|
1998-10-24 09:58:16 +00:00
|
|
|
|
{
|
2010-02-14 10:48:10 +00:00
|
|
|
|
#if GS_EXPOSE(NSArchiver)
|
2000-07-04 09:44:05 +00:00
|
|
|
|
@private
|
1999-09-16 07:21:34 +00:00
|
|
|
|
NSMutableData *_data; /* Data to write into. */
|
|
|
|
|
id _dst; /* Serialization destination. */
|
2000-06-26 11:12:13 +00:00
|
|
|
|
IMP _serImp; /* Method to serialize with. */
|
|
|
|
|
IMP _tagImp; /* Serialize a type tag. */
|
1999-09-16 07:21:34 +00:00
|
|
|
|
IMP _xRefImp; /* Serialize a crossref. */
|
|
|
|
|
IMP _eObjImp; /* Method to encode an id. */
|
|
|
|
|
IMP _eValImp; /* Method to encode others. */
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#ifndef _IN_NSARCHIVER_M
|
1999-06-21 08:30:26 +00:00
|
|
|
|
#define GSIMapTable void*
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#endif
|
2000-06-26 11:12:13 +00:00
|
|
|
|
GSIMapTable _clsMap; /* Class cross references. */
|
|
|
|
|
GSIMapTable _cIdMap; /* Conditionally coded. */
|
|
|
|
|
GSIMapTable _uIdMap; /* Unconditionally coded. */
|
|
|
|
|
GSIMapTable _ptrMap; /* Constant pointers. */
|
|
|
|
|
GSIMapTable _namMap; /* Mappings for class names. */
|
|
|
|
|
GSIMapTable _repMap; /* Mappings for objects. */
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#ifndef _IN_NSARCHIVER_M
|
1999-06-21 08:30:26 +00:00
|
|
|
|
#undef GSIMapTable
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
|
unsigned _xRefC; /* Counter for cross-reference. */
|
|
|
|
|
unsigned _xRefO; /* Counter for cross-reference. */
|
|
|
|
|
unsigned _xRefP; /* Counter for cross-reference. */
|
|
|
|
|
unsigned _startPos; /* Where in data we started. */
|
|
|
|
|
BOOL _encodingRoot;
|
|
|
|
|
BOOL _initialPass;
|
2010-03-02 09:51:12 +00:00
|
|
|
|
#endif
|
2011-02-16 05:49:45 +00:00
|
|
|
|
#if GS_NONFRAGILE
|
|
|
|
|
#else
|
2011-02-14 06:37:45 +00:00
|
|
|
|
/* Pointer to private additional data used to avoid breaking ABI
|
|
|
|
|
* when we don't have the non-fragile ABI available.
|
2011-02-16 05:49:45 +00:00
|
|
|
|
* Use this mechanism rather than changing the instance variable
|
|
|
|
|
* layout (see Source/GSInternal.h for details).
|
2011-02-14 06:37:45 +00:00
|
|
|
|
*/
|
2011-03-05 18:12:55 +00:00
|
|
|
|
@private id _internal GS_UNUSED_IVAR;
|
2011-02-14 06:37:45 +00:00
|
|
|
|
#endif
|
1998-10-24 09:58:16 +00:00
|
|
|
|
}
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
/* Initializing an archiver */
|
1995-04-09 02:42:37 +00:00
|
|
|
|
- (id) initForWritingWithMutableData: (NSMutableData*)mdata;
|
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
/* Archiving Data */
|
1995-04-15 19:39:41 +00:00
|
|
|
|
+ (NSData*) archivedDataWithRootObject: (id)rootObject;
|
1995-04-09 02:42:37 +00:00
|
|
|
|
+ (BOOL) archiveRootObject: (id)rootObject toFile: (NSString*)path;
|
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
/* Getting data from the archiver */
|
1995-04-09 02:42:37 +00:00
|
|
|
|
- (NSMutableData*) archiverData;
|
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
/* Substituting Classes */
|
1998-10-24 09:58:16 +00:00
|
|
|
|
- (NSString*) classNameEncodedForTrueClassName: (NSString*) trueName;
|
1997-05-03 20:20:14 +00:00
|
|
|
|
- (void) encodeClassName: (NSString*)trueName
|
1996-01-26 03:13:00 +00:00
|
|
|
|
intoClassName: (NSString*)inArchiveName;
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
2005-06-05 05:24:45 +00:00
|
|
|
|
#if OS_API_VERSION(GS_API_MACOSX,GS_API_LATEST)
|
1998-10-24 09:58:16 +00:00
|
|
|
|
/* Substituting Objects */
|
|
|
|
|
- (void) replaceObject: (id)object
|
|
|
|
|
withObject: (id)newObject;
|
1998-11-10 20:16:33 +00:00
|
|
|
|
#endif
|
1998-10-24 09:58:16 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2008-06-10 18:20:23 +00:00
|
|
|
|
#if GS_API_VERSION(GS_API_NONE,011700)
|
1998-10-24 09:58:16 +00:00
|
|
|
|
@interface NSArchiver (GNUstep)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Re-using the archiver - the 'resetArchiver' method resets the internal
|
|
|
|
|
* state of the archiver so that you can re-use it rather than having to
|
|
|
|
|
* destroy it and create a new one.
|
|
|
|
|
* NB. you would normally want to issue a 'setLength:0' message to the
|
|
|
|
|
* mutable data object used by the archiver as well, othewrwise the next
|
|
|
|
|
* root object encoded will be appended to data.
|
|
|
|
|
*/
|
|
|
|
|
- (void) resetArchiver;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Subclassing with different output format.
|
|
|
|
|
* NSArchiver normally writes directly to an NSMutableData object using
|
|
|
|
|
* the methods -
|
|
|
|
|
* [-serializeTypeTag:]
|
|
|
|
|
* to encode type tags for data items, the tag is the
|
|
|
|
|
* first byte of the character encoding string for the
|
|
|
|
|
* data type (as provided by '@encode(xxx)'), possibly
|
|
|
|
|
* with the top bit set to indicate that what follows is
|
|
|
|
|
* a crossreference to an item already encoded.
|
|
|
|
|
* [-serializeCrossRef:],
|
|
|
|
|
* to encode a crossreference number either to identify the
|
|
|
|
|
* following item, or to refer to a previously encoded item.
|
|
|
|
|
* Objects, Classes, Selectors, CStrings and Pointer items
|
|
|
|
|
* have crossreference encoding, other types do not.
|
|
|
|
|
* [-serializeData:ofObjCType:context:]
|
|
|
|
|
* to encode all other information.
|
|
|
|
|
*
|
|
|
|
|
* And uses other NSMutableData methods to write the archive header
|
|
|
|
|
* information from within the method:
|
|
|
|
|
* [-serializeHeaderAt:version:classes:objects:pointers:]
|
|
|
|
|
* to write a fixed size header including archiver version
|
|
|
|
|
* (obtained by [self systemVersion]) and crossreference
|
|
|
|
|
* table sizes. The archiver will do this twice, once with
|
|
|
|
|
* dummy values at initialisation time and once with the real
|
|
|
|
|
* values.
|
|
|
|
|
*
|
|
|
|
|
* To subclass NSArchiver, you must implement your own versions of the
|
|
|
|
|
* four methods above, and override the 'directDataAccess' method to
|
|
|
|
|
* return NO so that the archiver knows to use your serialization
|
|
|
|
|
* methods rather than those in the NSMutableData object.
|
|
|
|
|
*/
|
|
|
|
|
- (BOOL) directDataAccess;
|
|
|
|
|
- (void) serializeHeaderAt: (unsigned)positionInData
|
|
|
|
|
version: (unsigned)systemVersion
|
|
|
|
|
classes: (unsigned)classCount
|
|
|
|
|
objects: (unsigned)objectCount
|
|
|
|
|
pointers: (unsigned)pointerCount;
|
1995-04-09 02:42:37 +00:00
|
|
|
|
@end
|
1998-11-02 10:55:53 +00:00
|
|
|
|
#endif
|
1995-04-09 02:42:37 +00:00
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
1998-10-24 09:58:16 +00:00
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
@interface NSUnarchiver : NSCoder
|
1998-10-24 09:58:16 +00:00
|
|
|
|
{
|
2010-02-14 10:48:10 +00:00
|
|
|
|
#if GS_EXPOSE(NSUnarchiver)
|
2000-07-04 09:44:05 +00:00
|
|
|
|
@private
|
1998-10-24 09:58:16 +00:00
|
|
|
|
NSData *data; /* Data to write into. */
|
|
|
|
|
Class dataClass; /* What sort of data is it? */
|
|
|
|
|
id src; /* Deserialization source. */
|
|
|
|
|
IMP desImp; /* Method to deserialize with. */
|
1999-01-27 12:49:49 +00:00
|
|
|
|
void (*tagImp)(id, SEL, unsigned char*, unsigned*,unsigned*);
|
1998-10-24 09:58:16 +00:00
|
|
|
|
IMP dValImp; /* Method to decode data with. */
|
|
|
|
|
#ifndef _IN_NSUNARCHIVER_M
|
1999-06-21 08:30:26 +00:00
|
|
|
|
#define GSIArray void*
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#endif
|
1999-06-21 08:30:26 +00:00
|
|
|
|
GSIArray clsMap; /* Class crossreference map. */
|
|
|
|
|
GSIArray objMap; /* Object crossreference map. */
|
|
|
|
|
GSIArray ptrMap; /* Pointer crossreference map. */
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#ifndef _IN_NSUNARCHIVER_M
|
2009-06-13 07:33:51 +00:00
|
|
|
|
#undef GSIArray
|
1998-10-24 09:58:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
unsigned cursor; /* Position in data buffer. */
|
|
|
|
|
unsigned version; /* Version of archiver used. */
|
|
|
|
|
NSZone *zone; /* Zone for allocating objs. */
|
|
|
|
|
NSMutableDictionary *objDict; /* Class information store. */
|
2004-04-11 05:22:33 +00:00
|
|
|
|
NSMutableArray *objSave;
|
2010-03-02 09:51:12 +00:00
|
|
|
|
#endif
|
2011-02-16 05:49:45 +00:00
|
|
|
|
#if GS_NONFRAGILE
|
|
|
|
|
#else
|
2011-02-14 06:37:45 +00:00
|
|
|
|
/* Pointer to private additional data used to avoid breaking ABI
|
|
|
|
|
* when we don't have the non-fragile ABI available.
|
2011-02-16 05:49:45 +00:00
|
|
|
|
* Use this mechanism rather than changing the instance variable
|
|
|
|
|
* layout (see Source/GSInternal.h for details).
|
2011-02-14 06:37:45 +00:00
|
|
|
|
*/
|
2011-03-05 18:12:55 +00:00
|
|
|
|
@private id _internal GS_UNUSED_IVAR;
|
2011-02-14 06:37:45 +00:00
|
|
|
|
#endif
|
1998-10-24 09:58:16 +00:00
|
|
|
|
}
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
|
|
|
|
/* Initializing an unarchiver */
|
2002-06-06 14:02:59 +00:00
|
|
|
|
- (id) initForReadingWithData: (NSData*)anObject;
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
|
|
|
|
/* Decoding objects */
|
2002-06-06 14:02:59 +00:00
|
|
|
|
+ (id) unarchiveObjectWithData: (NSData*)anObject;
|
1996-01-26 20:03:57 +00:00
|
|
|
|
+ (id) unarchiveObjectWithFile: (NSString*)path;
|
|
|
|
|
|
|
|
|
|
/* Managing */
|
|
|
|
|
- (BOOL) isAtEnd;
|
|
|
|
|
- (NSZone*) objectZone;
|
2002-06-06 14:02:59 +00:00
|
|
|
|
- (void) setObjectZone: (NSZone*)aZone;
|
1996-01-26 20:32:33 +00:00
|
|
|
|
- (unsigned int) systemVersion;
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
|
|
|
|
/* Substituting Classes */
|
|
|
|
|
+ (NSString*) classNameDecodedForArchiveClassName: (NSString*)nameInArchive;
|
|
|
|
|
+ (void) decodeClassName: (NSString*)nameInArchive
|
|
|
|
|
asClassName: (NSString*)trueName;
|
|
|
|
|
- (NSString*) classNameDecodedForArchiveClassName: (NSString*)nameInArchive;
|
|
|
|
|
- (void) decodeClassName: (NSString*)nameInArchive
|
|
|
|
|
asClassName: (NSString*)trueName;
|
|
|
|
|
|
2005-06-05 05:24:45 +00:00
|
|
|
|
#if OS_API_VERSION(GS_API_MACOSX,GS_API_LATEST)
|
1998-10-24 09:58:16 +00:00
|
|
|
|
/* Substituting objects */
|
|
|
|
|
- (void) replaceObject: (id)anObject withObject: (id)replacement;
|
1998-11-10 20:16:33 +00:00
|
|
|
|
#endif
|
1998-10-24 09:58:16 +00:00
|
|
|
|
@end
|
|
|
|
|
|
2005-06-05 05:24:45 +00:00
|
|
|
|
#if OS_API_VERSION(GS_API_NONE,GS_API_NONE) && GS_API_VERSION(1,GS_API_LATEST)
|
1998-10-24 09:58:16 +00:00
|
|
|
|
@interface NSUnarchiver (GNUstep)
|
|
|
|
|
|
|
|
|
|
- (unsigned) cursor;
|
2002-06-06 14:02:59 +00:00
|
|
|
|
- (void) resetUnarchiverWithData: (NSData*)anObject
|
1998-10-24 09:58:16 +00:00
|
|
|
|
atIndex: (unsigned)pos;
|
|
|
|
|
|
|
|
|
|
- (BOOL) directDataAccess;
|
2002-06-06 14:02:59 +00:00
|
|
|
|
- (void) deserializeHeaderAt: (unsigned*)pos
|
|
|
|
|
version: (unsigned*)v
|
|
|
|
|
classes: (unsigned*)c
|
|
|
|
|
objects: (unsigned*)o
|
|
|
|
|
pointers: (unsigned*)p;
|
1996-01-26 20:03:57 +00:00
|
|
|
|
@end
|
1998-11-02 10:55:53 +00:00
|
|
|
|
#endif
|
1998-10-24 09:58:16 +00:00
|
|
|
|
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
|
|
|
|
/* Exceptions */
|
2004-07-29 15:30:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specified in OpenStep to be raised by [NSArchiver] or subclasses if there
|
|
|
|
|
* are problems initializing or encoding. <em>Not currently used.
|
|
|
|
|
* NSInternalInconsistencyException usually raised instead.</em>
|
|
|
|
|
*/
|
2002-05-08 05:43:15 +00:00
|
|
|
|
GS_EXPORT NSString * const NSInconsistentArchiveException;
|
1996-01-26 20:03:57 +00:00
|
|
|
|
|
2005-06-05 05:24:45 +00:00
|
|
|
|
#endif /* OS_API_VERSION */
|
|
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
|
#endif /* __NSArchiver_h_GNUSTEP_BASE_INCLUDE */
|