tidied a little

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3051 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-11 06:26:40 +00:00
parent 7cb68bb453
commit 522c47840a
7 changed files with 116 additions and 69 deletions

View file

@ -109,19 +109,19 @@
- (void) forwardInvocation: (NSInvocation*)anInvocation;
- (id) awakeAfterUsingCoder: (NSCoder*)aDecoder;
- (Class) classForArchiver;
- (Class) classForCoder;
- (Class) classForPortCoder;
- (id) replacementObjectForArchiver: (NSCoder*)anEncoder;
- (id) replacementObjectForCoder: (NSCoder*)anEncoder;
- (id) replacementObjectForPortCoder: (NSPortCoder*)anEncoder;
+ setVersion: (int)aVersion;
+ (int) version;
@end
@interface NSObject (NSPortCoder)
- (Class) classForPortCoder;
- (id) replacementObjectForPortCoder: (NSPortCoder*)anEncoder;
@end
/* Global lock to be used by classes when operating on any global
data that invoke other methods which also access global; thus,
creating the potential for deadlock. */
@ -143,6 +143,10 @@ NSComparisonResult;
enum {NSNotFound = 0x7fffffff};
@interface NSObject (GNUstep)
+ (id) newWithCoder: (NSCoder*)aCoder inZone: (NSZone*)aZone;
@end
@interface NSObject (NEXTSTEP)
- error:(const char *)aString, ...;
- notImplemented:(SEL)aSel;

View file

@ -29,6 +29,7 @@
#include <config.h>
#include <gnustep/base/behavior.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSString.h>
#include <Foundation/NSGArray.h>
#include <limits.h>
@ -133,13 +134,40 @@ static Class NSMutableArray_concrete_class;
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility:_cmd];
unsigned count = [self count];
[aCoder encodeValueOfObjCType: @encode(unsigned)
at: &count];
if (count > 0) {
unsigned i;
for (i = 0; i < count; i++) {
[aCoder encodeObject: [self objectAtIndex: i]];
}
}
}
- (id) initWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility:_cmd];
return nil;
unsigned count;
if ([aCoder systemVersion] == 0) {
unsigned dummy;
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &dummy];
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &dummy];
}
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0) {
id contents[count];
int i;
for (i = 0; i < count; i++) {
contents[i] = [aCoder decodeObject];
}
return [self initWithObjects: contents count: count];
}
return [self initWithObjects: 0 count: 0];
}
/* The NSCopying Protocol */

View file

@ -62,7 +62,7 @@
- (unsigned int) versionForClassName: (NSString*)className
{
[self subclassResponsibility:_cmd];
return 0;
return NSNotFound;
}
@end

View file

@ -55,6 +55,7 @@
+ (void) initialize
{
if (self == [NSGArray class]) {
[self setVersion: 1];
behavior_class_add_class(self, [NSArrayNonCore class]);
}
}
@ -97,6 +98,11 @@
return self;
}
- (Class) classForCoder
{
return [NSArray class];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
unsigned i;
@ -105,18 +111,9 @@
at: &_count
withName: @"Array content count"];
if ([aCoder isKindOfClass: [NSPortCoder class]] &&
[(NSPortCoder*)aCoder isBycopy]) {
for (i = 0; i < _count; i++) {
[(id<Encoding>)aCoder encodeBycopyObject: _contents_array[i]
withName: @"Array content"];
}
}
else {
for (i = 0; i < _count; i++) {
[(id<Encoding>)aCoder encodeObject: _contents_array[i]
withName: @"Array content"];
}
for (i = 0; i < _count; i++) {
[(id<Encoding>)aCoder encodeObject: _contents_array[i]
withName: @"Array content"];
}
}
@ -124,6 +121,15 @@
{
unsigned count;
if ([aCoder systemVersion] == 0) {
unsigned dummy;
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &dummy
withName: NULL];
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &dummy
withName: NULL];
}
[(id<Decoding>)aCoder decodeValueOfCType: @encode(unsigned)
at: &count
withName: NULL];
@ -216,6 +222,7 @@
+ (void) initialize
{
if (self == [NSGMutableArray class]) {
[self setVersion: 1];
behavior_class_add_class(self, [NSMutableArrayNonCore class]);
behavior_class_add_class(self, [NSGArray class]);
}
@ -269,6 +276,11 @@
return self;
}
- (Class) classForCoder
{
return [NSMutableArray class];
}
- (void) insertObject: (id)anObject atIndex: (unsigned)index
{
unsigned i;

View file

@ -361,7 +361,6 @@
case '\v':
case '\f':
case '\\':
case '\'' :
case '"' :
length += 2;
break;
@ -395,7 +394,6 @@
case '\v': *ptr++ = '\\'; *ptr++ = 'v'; break;
case '\f': *ptr++ = '\\'; *ptr++ = 'f'; break;
case '\\': *ptr++ = '\\'; *ptr++ = '\\'; break;
case '\'': *ptr++ = '\\'; *ptr++ = '\''; break;
case '"' : *ptr++ = '\\'; *ptr++ = '"'; break;
default:

View file

@ -34,6 +34,8 @@
#include <Foundation/NSString.h>
#include <gnustep/base/o_map.h>
#include <Foundation/NSException.h>
#include <Foundation/NSPortCoder.h>
#include <Foundation/NSDistantObject.h>
#include <Foundation/NSZone.h>
#include <limits.h>
@ -513,16 +515,45 @@ static BOOL double_release_check_enabled = NO;
return self;
}
- (Class) classForArchiver
{
return [self classForCoder];
}
- (Class) classForCoder
{
return [self class];
}
- (Class) classForPortCoder
{
return [self classForCoder];
}
- (id) replacementObjectForArchiver: (NSCoder*)anArchiver
{
return [self replacementObjectForCoder: (NSCoder*)anArchiver];
}
- (id) replacementObjectForCoder: (NSCoder*)anEncoder
{
return self;
}
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
{
if ([aCoder isBycopy]) {
return self;
}
else if ([self isKindOfClass: [NSDistantObject class]]) {
return self;
}
else {
return [NSDistantObject proxyWithLocal: self
connection: [aCoder connection]];
}
}
/* NSObject protocol */
@ -746,6 +777,26 @@ static BOOL double_release_check_enabled = NO;
@end
@implementation NSObject (GNUstep)
/*
* GNUstep extensions to the OpenStep standard.
*/
+ (id) newWithCoder: (NSCoder*)coder inZone: (NSZone*)zone
{
id obj;
obj = [self allocWithZone: zone];
if (obj) {
obj = [obj initWithCoder: coder];
}
return obj;
}
@end
@implementation NSObject (NEXTSTEP)
@ -860,17 +911,6 @@ static BOOL double_release_check_enabled = NO;
withObject:anotherObject];
}
- perform: (SEL)sel withObject: anObject
{
return [self performSelector:sel withObject:anObject];
}
- perform: (SEL)sel withObject: anObject withObject: anotherObject
{
return [self performSelector:sel withObject:anObject
withObject:anotherObject];
}
@end

View file

@ -475,38 +475,3 @@ static BOOL debug_connected_coder = NO;
@end
@implementation NSObject (NSPortCoder)
/* By default, Object's encode themselves as proxies across Connection's */
- (Class) classForPortCoder
{
return [self classForCoder];
}
static inline BOOL class_is_kind_of (Class self, Class aClassObject)
{
Class class;
for (class = self; class!=Nil; class = class_get_super_class(class))
if (class==aClassObject)
return YES;
return NO;
}
- replacementObjectForPortCoder: (NSPortCoder*)aRmc
{
if ([aRmc isBycopy]) {
return self;
}
else if (class_is_kind_of(object_get_class(self->isa),
[NSDistantObject class])) {
return self;
}
else {
return [NSDistantObject proxyWithLocal: self
connection: [aRmc connection]];
}
}
@end