Initial revision

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@361 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1995-04-15 19:39:49 +00:00
parent e695d837c2
commit 41579a1b05
8 changed files with 625 additions and 0 deletions

View file

@ -0,0 +1,56 @@
/* Interface to concrete implementation of NSArchiver
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSGArchiver_h_OBJECTS_INCLUDE
#define __NSGArchiver_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h>
#include <foundation/NSArchiver.h>
#include <objects/Stream.h>
#include <objects/Dictionary.h>
#include <objects/Stack.h>
#include <objects/Coding.h>
@interface NSGArchiver : NSArchiver
{
/* For now, these must match the instance variables in foundation/NSGCoder.h.
This will change. */
int format_version;
int concrete_format_version;
Stream *stream;
BOOL is_decoding;
BOOL doing_root_object;
Dictionary *object_table; /* read/written objects */
Dictionary *const_ptr_table; /* read/written const *'s */
Stack *root_object_tables; /* Stack of Dicts for interconnt'd objs */
Stack *forward_object_tables; /* Stack of Dictionaries for frwd refs */
NSZone *object_zone;
}
@end
@interface NSGArchiver (GNU) <Encoding>
@end
#endif /* __NSGArchiver_h_OBJECTS_INCLUDE */

View file

@ -0,0 +1,68 @@
/* Interface to concrete implementation of NSData based on MemoryStream class
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSGData_h_OBJECTS_INCLUDE
#define __NSGData_h_OBJECTS_INCLUDE
#include <objects/stdobjects.h>
#include <foundation/NSData.h>
#include <foundation/NSMutableData.h>
#include <objects/MemoryStream.h>
@interface NSGData : NSData
{
/* For now, these must match the instance variables in
objects/MemoryStream.h.
This will change. */
int type;
char *buffer;
int size;
int eofPosition;
int prefix;
int position;
}
@end
@interface NSGData (GNU) <MemoryStreaming>
@end
@interface NSGMutableData : NSMutableData
{
/* For now, these must match the instance variables in
objects/MemoryStream.h.
This will change. */
int type;
char *buffer;
int size;
int eofPosition;
int prefix;
int position;
}
@end
@interface NSGMutableData (GNU) <MemoryStreaming>
@end
#endif /* __NSGData_h_OBJECTS_INCLUDE */

42
Source/NSGArchiver.m Normal file
View file

@ -0,0 +1,42 @@
/* Concrete NSArchiver for GNUStep based on GNU Coder class
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <objects/stdobjects.h>
#include <foundation/NSGArchiver.h>
#include <foundation/NSGCoder.h>
#include <objects/behavior.h>
@implementation NSGArchiver
+ (void) initialize
{
static int done = 0;
[self error:"This class not ready for business yet."];
if (!done)
{
done = 1;
class_add_behavior([NSGArchiver class], [NSGCoder class]);
}
}
@end

136
Source/NSGData.m Normal file
View file

@ -0,0 +1,136 @@
/* Concrete NSData for GNUStep based on GNU MemoryStream class
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <objects/stdobjects.h>
#include <foundation/NSGData.h>
#include <objects/NSCoder.h>
#include <objects/behavior.h>
#include <objects/MemoryStream.h>
#include <foundation/NSString.h>
/* This from objects/MemoryStream.h */
@interface NSGData (MemoryStream)
- _initOnMallocBuffer: (char*)b
size: (unsigned)s /* size of malloc'ed buffer */
eofPosition: (unsigned)l /* length of buffer with data for reading */
prefix: (unsigned)p /* reset for this position */
position: (unsigned)i; /* current position for reading/writing */
@end
@implementation NSGData
+ (void) initialize
{
static int done = 0;
if (!done)
{
done = 1;
class_add_behavior([NSGData class], [MemoryStream class]);
}
}
/* This is the designated initializer */
- (id) initWithBytesNoCopy: (void*)bytes
length: (unsigned int)length
{
[self _initOnMallocBuffer:bytes
size:length
eofPosition:length
prefix:0
position:0];
return self;
}
- (const void*) bytes
{
return buffer;
}
- (unsigned int) length
{
return eofPosition;
}
// Storing Data
- (BOOL) writeToFile: (NSString*)path
atomically: (BOOL)useAuxiliaryFile
{
/* xxx This currently ignores useAuxiliaryFile. */
int written;
FILE* fp = fopen([path cString], "w");
assert (fp); /* This should raise NSException instead. */
written = fwrite(buffer+prefix, 1, eofPosition, fp);
assert (eofPosition == written);
fclose(fp);
return YES;
}
@end
@implementation NSGMutableData
+ (void) initialize
{
static int done = 0;
if (!done)
{
done = 1;
class_add_behavior([NSGMutableData class], [NSGData class]);
}
}
/* Make sure we do this, and not what MemoryStream says. */
- (id) initWithCapacity: (unsigned int)capacity
{
return [self initWithBytesNoCopy:(*objc_malloc)(capacity)
length:capacity];
}
/* This is the designated initializer. The behavior comes from NSGData.
- (id) initWithBytesNoCopy: (void*)bytes
length: (unsigned int)length */
- (unsigned) capacity
{
return size;
}
- (void) setLength: (unsigned int)length
{
[self setStreamBufferCapacity:length];
}
- (void*) mutableBytes
{
return buffer;
}
- (void) appendBytes: (const void*)bytes
length: (unsigned int)length
{
[self writeBytes:bytes length:length];
}
@end

42
Source/NSGUnarchiver.m Normal file
View file

@ -0,0 +1,42 @@
/* Concrete NSUnarchiver for GNUStep based on GNU Coder class
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <objects/stdobjects.h>
#include <foundation/NSGUnarchiver.h>
#include <foundation/NSGCoder.h>
#include <objects/behavior.h>
@implementation NSGUnarchiver
+ (void) initialize
{
static int done = 0;
[self error:"This class not ready for business yet."];
if (!done)
{
done = 1;
class_add_behavior([NSGUnarchiver class], [NSGCoder class]);
}
}
@end

155
Source/NSMutableData.m Normal file
View file

@ -0,0 +1,155 @@
/* Implementation of NSMutableData for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: April 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* xxx Pretty messy. Needs work. */
@implementation NSMutableData
+ (id) dataWithCapacity: (unsigned int)numBytes
{
return [[[[NSGMutableData class] alloc] initWithCapacity:numBytes]
autorelease];
}
+ (id) dataWithLength: (unsigned int)length
{
return [[[[NSGMutableData class] alloc] initWithLength:length]
autorelease];
}
- (id) initWithCapacity: (unsigned int)capacity
{
return [self initWithBytesNoCopy:(*objc_malloc)(capacity)
length:capacity];
}
/* This is the designated initializer */
- (id) initWithBytesNoCopy: (void*)bytes
length: (unsigned int)length
{
/* xxx Eventually we'll have to be aware of malloc'ed memory
vs vm_allocate'd memory, etc. */
[self notImplemented:_cmd];
return nil;
}
- (id) initWithLength: (unsigned int)length
{
[self initWithCapacity:length];
memset([self bytes], 0, length);
return self;
}
/* This method not in OpenStep */
- (unsigned) capacity
{
[self notImplemented:_cmd];
return 0;
}
// Adjusting Capacity
- (void) increaseLengthBy: (unsigned int)extraLength
{
[self setLength:[self length]+extraLength];
}
- (void) setLength: (unsigned int)length
{
[self notImplemented:_cmd];
}
- (void*) mutableBytes
{
[self notImplemented:_cmd];
return NULL;
}
// Appending Data
- (void) appendBytes: (const void*)bytes
length: (unsigned int)length
{
[self notImplemented:_cmd];
}
- (void) appendData: (NSData*)other
{
[self appendBytes:[other bytes]
length:[other length]];
}
// Modifying Data
- (void) replaceBytesInRange: (NSRange)aRange
withBytes: (const void*)bytes
{
memcpy([self bytes] + aRange.location, bytes, aRange.length);
}
- (void) resetBytesInRange: (NSRange)aRange
{
memset([self bytes] + aRange.location, 0, aRange.length);
}
// Serializing Data
- (void) serializeAlignedBytesLength: (unsigned int)length
{
[self notImplemented:_cmd];
}
- (void) serializeDataAt: (const void*)data
ofObjCType: (const char*)type
context: (id <NSObjCTypeSerializationCallBack>)callback
{
[self notImplemented:_cmd];
}
- (void) serializeInt: (int)value
{
[self notImplemented:_cmd];
}
- (void) serializeInt: (int)value
atIndex: (unsigned int)location
{
[self notImplemented:_cmd];
}
- (void) serializeInts: (int*)intBuffer
count: (unsigned int)numInts
{
[self notImplemented:_cmd];
}
- (void) serializeInts: (int*)intBuffer
count: (unsigned int)numInts
atIndex: (unsigned int)location
{
[self notImplemented:_cmd];
}
@end

108
Source/NSUnarchiver.m Normal file
View file

@ -0,0 +1,108 @@
/* Implementation of NSUnrchiver for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
Date: March 1995
This file is part of the GNU Objective C Class Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <foundation/NSUnarchiver.h>
@implementation NSUnarchiver
// Initializing an unarchiver
- (id) initForReadingWithData: (NSData*)data
{
[self notImplemented:_cmd];
return nil;
}
// Decoding objects
+ (id) unarchiveObjectWithData: (NSData*)data
{
[self notImplemented:_cmd];
return nil;
}
+ (id) unarchiveObjectWithFile: (NSString*)path
{
[self notImplemented:_cmd];
return nil;
}
- (void) decodeArrayOfObjCType: (const char*)type
count: (unsigned int)count
at: (void*)array
{
[self notImplemented:_cmd];
}
// Managing
- (BOOL) isAtEnd
{
[self notImplemented:_cmd];
return NO;
}
- (NSZone*) objectZone
{
[self notImplemented:_cmd];
return NULL;
}
- (void) setObjectZone: (NSZone*)zone
{
[self notImplemented:_cmd];
}
- (unsigned int) systermVersion
{
[self notImplemented:_cmd];
return 0;
}
// Substituting Classes
+ (NSString*) classNameDecodedForArchiveClassName: (NSString*)nameInArchive
{
[self notImplemented:_cmd];
return nil;
}
+ (void) decodeClassName: (NSString*)nameInArchive
asClassName: (NSString*)trueName
{
[self notImplemented:_cmd];
}
- (NSString*) classNameDecodedForArchiveClassName: (NSString*)nameInArchive
{
[self notImplemented:_cmd];
return nil;
}
- (void) decodeClassName: (NSString*)nameInArchive
asClassName: (NSString*)trueName
{
[self notImplemented:_cmd];
}
@end

18
Testing/nsarchiving.m Normal file
View file

@ -0,0 +1,18 @@
#include <foundation/NSArchiver.h>
#include <foundation/NSArray.h>
#include <foundation/NSString.h>
int
main ()
{
id a = [NSArray arrayWithObjects:
[NSObject class],
[NSArray class],
nil];
[NSArchiver archiveRootObject:a toFile:@"./nsarchiving.data"];
[a release];
/* NSUnarchiver not available yet. */
exit (0);
}