mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-19 03:51:38 +00:00
Patched from mail.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@597 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
febfce5a16
commit
cddc14d2b4
6 changed files with 95 additions and 42 deletions
|
@ -90,14 +90,17 @@
|
||||||
// NSCoding
|
// NSCoding
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
const char *type;
|
||||||
[super encodeWithCoder:coder];
|
[super encodeWithCoder:coder];
|
||||||
[coder encodeValueOfObjCType:[self objCType] at:&data];
|
type = [self objCType];
|
||||||
|
[coder encodeValueOfObjCType:@encode(char *) at:&type];
|
||||||
|
[coder encodeValueOfObjCType:type at:&data];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)coder
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
self = [super initWithCoder:coder];
|
[NSException raise:NSInconsistentArchiveException
|
||||||
[coder decodeValueOfObjCType:[self objCType] at:&data];
|
format:@"Cannot unarchive class - Need NSValueDecoder."];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,14 +195,18 @@
|
||||||
// NSCoding
|
// NSCoding
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
const char *type;
|
||||||
[super encodeWithCoder:coder];
|
[super encodeWithCoder:coder];
|
||||||
[coder encodeValueOfObjCType:[self objCType] at:&data];
|
type = [self objCType];
|
||||||
|
[coder encodeValueOfObjCType:@encode(char *) at:&type];
|
||||||
|
[coder encodeValueOfObjCType:type at:&data];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)coder
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
// This should raise an exception - Use NSValueDecoder to decode NSNumber
|
||||||
self = [super initWithCoder:coder];
|
self = [super initWithCoder:coder];
|
||||||
[coder decodeValueOfObjCType:[self objCType] at:&data];
|
//[coder decodeValueOfObjCType:[self objCType] at:&data];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,18 +141,19 @@
|
||||||
// NSCoding
|
// NSCoding
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
|
const char *type;
|
||||||
[super encodeWithCoder:coder];
|
[super encodeWithCoder:coder];
|
||||||
// FIXME: Do we need to check for encoding void, void * or will
|
// FIXME: Do we need to check for encoding void, void * or will
|
||||||
// NSCoder do this for us?
|
// NSCoder do this for us?
|
||||||
[coder encodeObject:objctype];
|
type = [objctype cString];
|
||||||
[coder encodeValueOfObjCType:[objctype cString] at:&data];
|
[coder encodeValueOfObjCType:@encode(char *) at:&type];
|
||||||
|
[coder encodeValueOfObjCType:type at:&data];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)coder
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
self = [super initWithCoder:coder];
|
[NSException raise:NSInconsistentArchiveException
|
||||||
objctype = [[coder decodeObject] retain];
|
format:@"Cannot unarchive class - Need NSValueDecoder."];
|
||||||
[coder decodeValueOfObjCType:[objctype cString] at:&data];
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,100 +168,95 @@
|
||||||
/* All the rest of these methods must be implemented by a subclass */
|
/* All the rest of these methods must be implemented by a subclass */
|
||||||
- (BOOL)boolValue
|
- (BOOL)boolValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (char)charValue
|
- (char)charValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)doubleValue
|
- (double)doubleValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float)floatValue
|
- (float)floatValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)intValue
|
- (int)intValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long long)longLongValue
|
- (long long)longLongValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (long)longValue
|
- (long)longValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (short)shortValue
|
- (short)shortValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)stringValue
|
- (NSString *)stringValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned char)unsignedCharValue
|
- (unsigned char)unsignedCharValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned int)unsignedIntValue
|
- (unsigned int)unsignedIntValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned long long)unsignedLongLongValue
|
- (unsigned long long)unsignedLongLongValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned long)unsignedLongValue
|
- (unsigned long)unsignedLongValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned short)unsignedShortValue
|
- (unsigned short)unsignedShortValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSComparisonResult)compare:(NSNumber *)otherNumber
|
- (NSComparisonResult)compare:(NSNumber *)otherNumber
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSCoding (done by subclasses)
|
// NSCoding (done by subclasses)
|
||||||
- classForCoder
|
|
||||||
{
|
|
||||||
return [self class];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
[super encodeWithCoder:coder];
|
[super encodeWithCoder:coder];
|
||||||
|
@ -269,7 +264,8 @@
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)coder
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
self = [super initWithCoder:coder];
|
[NSException raise:NSInconsistentArchiveException
|
||||||
|
format:@"Cannot unarchive from NSNumber class - Need NSValueDecoder."];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,58 @@
|
||||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <objects/stdobjects.h>
|
||||||
#include <Foundation/NSConcreteValue.h>
|
#include <Foundation/NSConcreteValue.h>
|
||||||
#include <Foundation/NSCoder.h>
|
#include <Foundation/NSCoder.h>
|
||||||
|
|
||||||
|
/* NSValueDecoder is a Class whose only purpose is to decode coded NSValue
|
||||||
|
objects. The only method(s) that should ever be called are +newWithCoder:
|
||||||
|
or -initWithCoder:. Should disallow any other method calls... */
|
||||||
|
@interface NSValueDecoder : NSValue
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSValueDecoder
|
||||||
|
|
||||||
|
- initValue:(const void *)value
|
||||||
|
withObjCType:(const char *)type
|
||||||
|
{
|
||||||
|
[self shouldNotImplement:_cmd];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id) newWithCoder: (NSCoder *)coder
|
||||||
|
{
|
||||||
|
char *type;
|
||||||
|
void *data;
|
||||||
|
id new_value;
|
||||||
|
|
||||||
|
[coder decodeValueOfObjCType:@encode(char *) at:&type];
|
||||||
|
[coder decodeValueOfObjCType:type at:&data];
|
||||||
|
/* Call NSNumber's implementation of this method, because NSValueDecoder
|
||||||
|
also stores NSNumber types */
|
||||||
|
new_value = [[NSNumber valueClassWithObjCType:type]
|
||||||
|
allocWithZone:[coder objectZone]];
|
||||||
|
[new_value initValue:data withObjCType:type];
|
||||||
|
OBJC_FREE(data);
|
||||||
|
OBJC_FREE(type);
|
||||||
|
return new_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Are you convinced that +newWithCoder is a better idea? Otherwise we
|
||||||
|
have to release ourselves and return a new instance of the correct
|
||||||
|
object. We hope that the calling method knows this and has nested the
|
||||||
|
alloc and init calls or knows that the object has been replaced. */
|
||||||
|
- (id) initWithCoder: (NSCoder *)coder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder:coder];
|
||||||
|
[self autorelease];
|
||||||
|
return [NSValueDecoder newWithCoder:coder];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation NSValue
|
@implementation NSValue
|
||||||
|
|
||||||
// NSCopying
|
// NSCopying
|
||||||
|
@ -111,50 +160,50 @@
|
||||||
/* All the rest of these methods must be implemented by a subclass */
|
/* All the rest of these methods must be implemented by a subclass */
|
||||||
- (void)getValue:(void *)value
|
- (void)getValue:(void *)value
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (const char *)objCType
|
- (const char *)objCType
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Is this an error or an exception???
|
// FIXME: Is this an error or an exception???
|
||||||
- (id)nonretainedObjectValue
|
- (id)nonretainedObjectValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void *)pointerValue
|
- (void *)pointerValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect)rectValue
|
- (NSRect)rectValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return NSMakeRect(0,0,0,0);
|
return NSMakeRect(0,0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSSize)sizeValue
|
- (NSSize)sizeValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return NSMakeSize(0,0);
|
return NSMakeSize(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSPoint)pointValue
|
- (NSPoint)pointValue
|
||||||
{
|
{
|
||||||
[self doesNotRecognizeSelector:_cmd];
|
[self subclassResponsibility:_cmd];
|
||||||
return NSMakePoint(0,0);
|
return NSMakePoint(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSCoding (done by subclasses)
|
// NSCoding (done by subclasses)
|
||||||
- classForCoder
|
- classForCoder
|
||||||
{
|
{
|
||||||
return [self class];
|
return [NSValueDecoder class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
|
|
|
@ -98,11 +98,11 @@ static BOOL debug_textcoder = NO;
|
||||||
indentation, "", name, (unsigned)*(unsigned char*)d];
|
indentation, "", name, (unsigned)*(unsigned char*)d];
|
||||||
break;
|
break;
|
||||||
case _C_FLT:
|
case _C_FLT:
|
||||||
[stream writeFormat:"%*s<%s> (float) = %f\n",
|
[stream writeFormat:"%*s<%s> (float) = %g\n",
|
||||||
indentation, "", name, *(float*)d];
|
indentation, "", name, *(float*)d];
|
||||||
break;
|
break;
|
||||||
case _C_DBL:
|
case _C_DBL:
|
||||||
[stream writeFormat:"%*s<%s> (double) = %f\n",
|
[stream writeFormat:"%*s<%s> (double) = %g\n",
|
||||||
indentation, "", name, *(double*)d];
|
indentation, "", name, *(double*)d];
|
||||||
break;
|
break;
|
||||||
case _C_CHARPTR:
|
case _C_CHARPTR:
|
||||||
|
@ -198,7 +198,7 @@ if (debug_textcoder) \
|
||||||
DECODE_DEBUG(float, f);
|
DECODE_DEBUG(float, f);
|
||||||
break;
|
break;
|
||||||
case _C_DBL:
|
case _C_DBL:
|
||||||
if ([stream readFormat:DECODER_FORMAT(double,f),
|
if ([stream readFormat:DECODER_FORMAT(double,lf),
|
||||||
&tmpname, (double*)d] != 2)
|
&tmpname, (double*)d] != 2)
|
||||||
DECODE_ERROR(double);
|
DECODE_ERROR(double);
|
||||||
DECODE_DEBUG(double, f);
|
DECODE_DEBUG(double, f);
|
||||||
|
|
Loading…
Reference in a new issue