Implemented keyed decoding for this classes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18491 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2004-01-27 21:51:33 +00:00
parent 358b54ac77
commit dea07f458d
8 changed files with 299 additions and 183 deletions

View file

@ -1,3 +1,14 @@
2004-01-27 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSArray.m:
* Source/NSArray.m:
* Source/GSSet.m:
* Source/NSSet.m:
* Source/GSDictionary.m:
* Source/NSDictionary.m:
* Source/NSString.m:
Implemented keyed decoding in [initWithCoder:].
2004-01-27 Richard Frith-Macdonald <rfm@gnu.org> 2004-01-27 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Foundation/NSKeyedArchiver.h: Expose internals a bit. * Headers/Foundation/NSKeyedArchiver.h: Expose internals a bit.

View file

@ -32,6 +32,8 @@
#include "Foundation/NSPortCoder.h" #include "Foundation/NSPortCoder.h"
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
#include "Foundation/NSValue.h" #include "Foundation/NSValue.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
static SEL eqSel; static SEL eqSel;
static SEL oaiSel; static SEL oaiSel;
@ -178,6 +180,15 @@ static Class GSInlineArrayClass;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
[self initWithArray: array];
}
else
{
[aCoder decodeValueOfObjCType: @encode(unsigned) [aCoder decodeValueOfObjCType: @encode(unsigned)
at: &_count]; at: &_count];
if (_count > 0) if (_count > 0)
@ -192,6 +203,7 @@ static Class GSInlineArrayClass;
count: _count count: _count
at: _contents_array]; at: _contents_array];
} }
}
return self; return self;
} }
@ -462,6 +474,15 @@ static Class GSInlineArrayClass;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
[self initWithArray: array];
}
else
{
unsigned count; unsigned count;
[aCoder decodeValueOfObjCType: @encode(unsigned) [aCoder decodeValueOfObjCType: @encode(unsigned)
@ -478,6 +499,7 @@ static Class GSInlineArrayClass;
at: _contents_array]; at: _contents_array];
_count = count; _count = count;
} }
}
return self; return self;
} }
@ -988,6 +1010,15 @@ static Class GSInlineArrayClass;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
return array;
}
else
{
GSInlineArray *a; GSInlineArray *a;
unsigned c; unsigned c;
@ -1002,6 +1033,7 @@ static Class GSInlineArrayClass;
} }
a->_count = c; a->_count = c;
return a; return a;
}
} }
- (id) initWithObjects: (id*)objects count: (unsigned)count - (id) initWithObjects: (id*)objects count: (unsigned)count

View file

@ -30,6 +30,8 @@
#include "Foundation/NSException.h" #include "Foundation/NSException.h"
#include "Foundation/NSPortCoder.h" #include "Foundation/NSPortCoder.h"
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
#include "GNUstepBase/GSObjCRuntime.h" #include "GNUstepBase/GSObjCRuntime.h"
@ -125,6 +127,17 @@ static SEL objSel;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *keys = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.keys"];
NSArray *objects = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
self = [self initWithObjects: objects forKeys: keys];
}
else
{
unsigned count; unsigned count;
id key; id key;
id value; id value;
@ -142,6 +155,7 @@ static SEL objSel;
(*imp)(aCoder, sel, type, &value); (*imp)(aCoder, sel, type, &value);
GSIMapAddPairNoRetain(&map, (GSIMapKey)key, (GSIMapVal)value); GSIMapAddPairNoRetain(&map, (GSIMapKey)key, (GSIMapVal)value);
} }
}
return self; return self;
} }

View file

@ -33,6 +33,8 @@
#include "Foundation/NSPortCoder.h" #include "Foundation/NSPortCoder.h"
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
#include "Foundation/NSObjCRuntime.h" #include "Foundation/NSObjCRuntime.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
#define GSI_MAP_HAS_VALUE 0 #define GSI_MAP_HAS_VALUE 0
#define GSI_MAP_KTYPES GSUNION_OBJ #define GSI_MAP_KTYPES GSUNION_OBJ
@ -187,6 +189,15 @@ static Class mutableSetClass;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
return [self initWithArray: array];
}
else
{
unsigned count; unsigned count;
id value; id value;
SEL sel = @selector(decodeValueOfObjCType:at:); SEL sel = @selector(decodeValueOfObjCType:at:);
@ -203,6 +214,7 @@ static Class mutableSetClass;
} }
return self; return self;
}
} }
/* Designated initialiser */ /* Designated initialiser */

View file

@ -45,6 +45,8 @@
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
#include "Foundation/NSValue.h" #include "Foundation/NSValue.h"
#include "Foundation/NSNull.h" #include "Foundation/NSNull.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
#include "GNUstepBase/GSCategories.h" #include "GNUstepBase/GSCategories.h"
#include "GSPrivate.h" #include "GSPrivate.h"
@ -552,6 +554,15 @@ static SEL rlSel;
*/ */
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
[self initWithArray: array];
}
else
{
unsigned count; unsigned count;
[aCoder decodeValueOfObjCType: @encode(unsigned) [aCoder decodeValueOfObjCType: @encode(unsigned)
@ -576,6 +587,7 @@ static SEL rlSel;
{ {
self = [self initWithObjects: 0 count: 0]; self = [self initWithObjects: 0 count: 0];
} }
}
return self; return self;
} }

View file

@ -38,6 +38,8 @@
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
#include "Foundation/NSObjCRuntime.h" #include "Foundation/NSObjCRuntime.h"
#include "Foundation/NSValue.h" #include "Foundation/NSValue.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
#include "GNUstepBase/GSCategories.h" #include "GNUstepBase/GSCategories.h"
#include "GSPrivate.h" #include "GSPrivate.h"
@ -203,6 +205,17 @@ static SEL appSel;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSArray *keys = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.keys"];
NSArray *objects = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
self = [self initWithObjects: objects forKeys: keys];
}
else
{
unsigned count; unsigned count;
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count]; [aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
@ -223,7 +236,7 @@ static SEL appSel;
NSZoneFree(NSDefaultMallocZone(), keys); NSZoneFree(NSDefaultMallocZone(), keys);
NSZoneFree(NSDefaultMallocZone(), vals); NSZoneFree(NSDefaultMallocZone(), vals);
} }
}
return self; return self;
} }

View file

@ -33,6 +33,8 @@
#include "Foundation/NSException.h" #include "Foundation/NSException.h"
#include "Foundation/NSObjCRuntime.h" #include "Foundation/NSObjCRuntime.h"
#include "Foundation/NSDebug.h" #include "Foundation/NSDebug.h"
// For private method _decodeArrayOfObjectsForKey:
#include "Foundation/NSKeyedArchiver.h"
#include "GNUstepBase/GSCategories.h" #include "GNUstepBase/GSCategories.h"
@class GSSet; @class GSSet;
@ -150,7 +152,6 @@ static Class NSMutableSet_concrete_class;
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
unsigned count;
Class c; Class c;
c = GSObjCClass(self); c = GSObjCClass(self);
@ -167,6 +168,17 @@ static Class NSMutableSet_concrete_class;
return [self initWithCoder: aCoder]; return [self initWithCoder: aCoder];
} }
if ([aCoder allowsKeyedCoding])
{
NSArray *array = [(NSKeyedUnarchiver*)aCoder _decodeArrayOfObjectsForKey:
@"NS.objects"];
return [self initWithArray: array];
}
else
{
unsigned count;
[aCoder decodeValueOfObjCType: @encode(unsigned) at: &count]; [aCoder decodeValueOfObjCType: @encode(unsigned) at: &count];
if (count > 0) if (count > 0)
{ {
@ -186,6 +198,7 @@ static Class NSMutableSet_concrete_class;
#endif #endif
} }
return self; return self;
}
} }
/* <init /> /* <init />

View file

@ -3880,6 +3880,14 @@ handle_printf_atsign (FILE *stream,
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
if ([aCoder allowsKeyedCoding])
{
NSString *string = [aCoder decodeObjectForKey: @"NS.string"];
self = [self initWithString: string];
}
else
{
unsigned count; unsigned count;
[aCoder decodeValueOfObjCType: @encode(unsigned int) at: &count]; [aCoder decodeValueOfObjCType: @encode(unsigned int) at: &count];
@ -3952,6 +3960,7 @@ handle_printf_atsign (FILE *stream,
{ {
self = [self initWithCStringNoCopy: "" length: 0 freeWhenDone: NO]; self = [self initWithCStringNoCopy: "" length: 0 freeWhenDone: NO];
} }
}
return self; return self;
} }