mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Update for MacOS-X and garbage collection.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4402 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8138b3d5b7
commit
f8063937b5
6 changed files with 407 additions and 317 deletions
|
@ -1,3 +1,11 @@
|
|||
Mon Jun 14 10:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSConcreteValue.m: Update for MacOS-X and for GC
|
||||
* Source/NSCTemplateValue.m: Update for MacOS-X and for GC
|
||||
* Source/NSNumber.m: Update for MacOS-X and for GC
|
||||
* Source/NSConcreteNumber.m: Update for MacOS-X and for GC
|
||||
* Source/include/NSValue.m: Update for MacOS-X and for GC
|
||||
|
||||
Sat Jun 12 15:50:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSConcreteValue.m: Implemented [hash and isEqualToValue
|
||||
|
|
|
@ -41,7 +41,10 @@
|
|||
+ (NSValue*) valueWithSize: (NSSize)size;
|
||||
|
||||
#ifndef STRICT_OPENSTEP
|
||||
+ valueFromString: (NSString *)string;
|
||||
+ (NSValue*) valueWithBytes: (const void*)value objCType: (const char*)type;
|
||||
+ (NSValue*) valueFromString: (NSString*)string;
|
||||
/* Designated initializer for all concrete subclasses */
|
||||
- (id) initWithBytes: (const void*)value objCType: (const char*)type;
|
||||
- (BOOL) isEqualToValue: (NSValue*)other;
|
||||
#endif
|
||||
|
||||
|
@ -75,19 +78,19 @@
|
|||
+ (NSNumber*) numberWithUnsignedLongLong: (unsigned long long)value;
|
||||
+ (NSNumber*) numberWithUnsignedShort: (unsigned short)value;
|
||||
|
||||
- (id)initWithBool:(BOOL)value;
|
||||
- (id)initWithChar:(char)value;
|
||||
- (id)initWithDouble:(double)value;
|
||||
- (id)initWithFloat:(float)value;
|
||||
- (id)initWithInt:(int)value;
|
||||
- (id)initWithLong:(long)value;
|
||||
- (id)initWithLongLong:(long long)value;
|
||||
- (id)initWithShort:(short)value;
|
||||
- (id)initWithUnsignedChar:(unsigned char)value;
|
||||
- (id)initWithUnsignedInt:(unsigned int)value;
|
||||
- (id)initWithUnsignedLong:(unsigned long)value;
|
||||
- (id)initWithUnsignedLongLong:(unsigned long long)value;
|
||||
- (id)initWithUnsignedShort:(unsigned short)value;
|
||||
- (id)initWithBool: (BOOL)value;
|
||||
- (id)initWithChar: (char)value;
|
||||
- (id)initWithDouble: (double)value;
|
||||
- (id)initWithFloat: (float)value;
|
||||
- (id)initWithInt: (int)value;
|
||||
- (id)initWithLong: (long)value;
|
||||
- (id)initWithLongLong: (long long)value;
|
||||
- (id)initWithShort: (short)value;
|
||||
- (id)initWithUnsignedChar: (unsigned char)value;
|
||||
- (id)initWithUnsignedInt: (unsigned int)value;
|
||||
- (id)initWithUnsignedLong: (unsigned long)value;
|
||||
- (id)initWithUnsignedLongLong: (unsigned long long)value;
|
||||
- (id)initWithUnsignedShort: (unsigned short)value;
|
||||
|
||||
// Accessing Data
|
||||
|
||||
|
@ -114,15 +117,15 @@
|
|||
|
||||
@end
|
||||
|
||||
/* Note: These methods are not in the OpenStep spec, but they may make
|
||||
#ifndef NO_GNUSTEP
|
||||
/* Note: This method is not in the OpenStep spec, but they makes
|
||||
subclassing easier. */
|
||||
@interface NSValue (Subclassing)
|
||||
|
||||
/* Used by value:withObjCType: to determine the concrete subclass to alloc */
|
||||
+ (Class)valueClassWithObjCType:(const char *)type;
|
||||
/* Used by value: withObjCType: to determine the concrete subclass to alloc */
|
||||
+ (Class)valueClassWithObjCType: (const char *)type;
|
||||
|
||||
/* Designated initializer for all concrete subclasses */
|
||||
- initValue:(const void *)value withObjCType:(const char *)type;
|
||||
@end
|
||||
#endif
|
||||
|
||||
#endif /* __NSValue_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -58,8 +58,8 @@
|
|||
|
||||
// Allocating and Initializing
|
||||
|
||||
- (id) initValue: (const void *)value
|
||||
withObjCType: (const char *)type
|
||||
- (id) initWithBytes: (const void *)value
|
||||
objCType: (const char *)type
|
||||
{
|
||||
typedef _dt = data;
|
||||
self = [super init];
|
||||
|
@ -198,17 +198,20 @@
|
|||
// NSCoding
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
const char *type;
|
||||
[super encodeWithCoder: coder];
|
||||
type = [self objCType];
|
||||
[coder encodeValueOfObjCType: @encode(char *) at: &type];
|
||||
[coder encodeValueOfObjCType: type at: &data];
|
||||
#if TYPE_ORDER == 0
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Attempt to encode a non-retained object"];
|
||||
#elif TYPE_ORDER == 2
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Attempt to encode a pointer to void object"];
|
||||
#else
|
||||
[coder encodeValueOfObjCType: @encode(TYPE_NAME) at: &data];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[NSException raise: NSInconsistentArchiveException
|
||||
format: @"Cannot unarchive class - Need NSValueDecoder."];
|
||||
[coder decodeValueOfObjCType: @encode(TYPE_NAME) at: &data];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,143 +135,152 @@
|
|||
@implementation NumberTemplate (Private)
|
||||
- (int)_nextOrder
|
||||
{
|
||||
return NEXT_ORDER;
|
||||
return NEXT_ORDER;
|
||||
}
|
||||
- (NSComparisonResult) _promotedCompare: (NSNumber*)other
|
||||
{
|
||||
NEXT_CTYPE v0, v1;
|
||||
NEXT_CTYPE v0, v1;
|
||||
|
||||
v0 = [self NEXT_METHOD];
|
||||
v1 = [other NEXT_METHOD];
|
||||
v0 = [self NEXT_METHOD];
|
||||
v1 = [other NEXT_METHOD];
|
||||
|
||||
if (v0 == v1)
|
||||
return NSOrderedSame;
|
||||
else
|
||||
return (v0 < v1) ? NSOrderedAscending : NSOrderedDescending;
|
||||
if (v0 == v1)
|
||||
return NSOrderedSame;
|
||||
else
|
||||
return (v0 < v1) ? NSOrderedAscending : NSOrderedDescending;
|
||||
}
|
||||
- (int)_typeOrder
|
||||
{
|
||||
return TYPE_ORDER;
|
||||
return TYPE_ORDER;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NumberTemplate
|
||||
|
||||
- initValue:(const void *)value withObjCType:(const char *)type;
|
||||
- (id)initWithBytes: (const void *)value objCType: (const char *)type
|
||||
{
|
||||
typedef _dt = data;
|
||||
self = [super init];
|
||||
data = *(_dt *)value;
|
||||
return self;
|
||||
typedef _dt = data;
|
||||
self = [super init];
|
||||
data = *(_dt *)value;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)boolValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (char)charValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (double)doubleValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (float)floatValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (int)intValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (long long)longLongValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (long)longValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (short)shortValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned char)unsignedCharValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned int)unsignedIntValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned long long)unsignedLongLongValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned long)unsignedLongValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned short)unsignedShortValue
|
||||
{
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)compare:(NSNumber *)other
|
||||
- (NSComparisonResult)compare: (NSNumber *)other
|
||||
{
|
||||
int o = [self _typeOrder];
|
||||
int o = [self _typeOrder];
|
||||
|
||||
if (o == [other _typeOrder] || o >= [other _nextOrder]) {
|
||||
typedef _dt = data;
|
||||
_dt other_data = [other TYPE_METHOD];
|
||||
|
||||
if (data == other_data)
|
||||
return NSOrderedSame;
|
||||
else
|
||||
return (data < other_data) ?
|
||||
NSOrderedAscending : NSOrderedDescending;
|
||||
if (o == [other _typeOrder] || o >= [other _nextOrder])
|
||||
{
|
||||
typedef _dt = data;
|
||||
_dt other_data = [other TYPE_METHOD];
|
||||
|
||||
if (data == other_data)
|
||||
return NSOrderedSame;
|
||||
else
|
||||
return (data < other_data) ? NSOrderedAscending : NSOrderedDescending;
|
||||
}
|
||||
o = [self _nextOrder];
|
||||
if (o <= [other _typeOrder]) {
|
||||
NSComparisonResult r = [other compare: self];
|
||||
if (r == NSOrderedAscending) {
|
||||
return NSOrderedDescending;
|
||||
o = [self _nextOrder];
|
||||
if (o <= [other _typeOrder])
|
||||
{
|
||||
NSComparisonResult r = [other compare: self];
|
||||
|
||||
if (r == NSOrderedAscending)
|
||||
{
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if (r == NSOrderedDescending) {
|
||||
return NSOrderedAscending;
|
||||
if (r == NSOrderedDescending)
|
||||
{
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
return r;
|
||||
return r;
|
||||
}
|
||||
if (o >= [other _nextOrder]) {
|
||||
return [self _promotedCompare: other];
|
||||
if (o >= [other _nextOrder])
|
||||
{
|
||||
return [self _promotedCompare: other];
|
||||
}
|
||||
else {
|
||||
NSComparisonResult r = [other _promotedCompare: self];
|
||||
if (r == NSOrderedAscending) {
|
||||
return NSOrderedDescending;
|
||||
else
|
||||
{
|
||||
NSComparisonResult r = [other _promotedCompare: self];
|
||||
|
||||
if (r == NSOrderedAscending)
|
||||
{
|
||||
return NSOrderedDescending;
|
||||
}
|
||||
if (r == NSOrderedDescending) {
|
||||
return NSOrderedAscending;
|
||||
if (r == NSOrderedDescending)
|
||||
{
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
return r;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/* Because of the rule that two numbers which are the same according to
|
||||
* [-isEqual:] must generate the same hash, we must generate the hash
|
||||
* [-isEqual: ] must generate the same hash, we must generate the hash
|
||||
* from the most general representation of the number.
|
||||
*/
|
||||
- (unsigned) hash
|
||||
|
@ -292,9 +301,9 @@
|
|||
|
||||
- (BOOL) isEqualToNumber: (NSNumber*)o
|
||||
{
|
||||
if ([self compare: o] == NSOrderedSame)
|
||||
return YES;
|
||||
return NO;
|
||||
if ([self compare: o] == NSOrderedSame)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: o
|
||||
|
@ -308,21 +317,22 @@
|
|||
- (NSString *)descriptionWithLocale: (NSDictionary*)locale
|
||||
{
|
||||
#if TYPE_ORDER == 0
|
||||
return (data) ? @"YES" : @"NO";
|
||||
return (data) ? @"YES" : @"NO";
|
||||
#else
|
||||
return [NSString stringWithFormat:TYPE_FORMAT, data];
|
||||
return [NSString stringWithFormat: TYPE_FORMAT, data];
|
||||
#endif
|
||||
}
|
||||
|
||||
// Override these from NSValue
|
||||
- (void)getValue:(void *)value
|
||||
- (void)getValue: (void *)value
|
||||
{
|
||||
if (!value) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Cannot copy value into NULL pointer"];
|
||||
/* NOT REACHED */
|
||||
if (!value)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Cannot copy value into NULL pointer"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
memcpy( value, &data, objc_sizeof_type([self objCType]) );
|
||||
memcpy( value, &data, objc_sizeof_type([self objCType]) );
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
|
@ -332,7 +342,7 @@
|
|||
}
|
||||
|
||||
// NSCoding
|
||||
- classForCoder
|
||||
- (Class)classForCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
@ -347,13 +357,13 @@
|
|||
- (void) encodeWithCoder: coder
|
||||
{
|
||||
const char *type = [self objCType];
|
||||
[coder encodeValueOfObjCType: type at: &data withName: @"NSNumber value"];
|
||||
[coder encodeValueOfObjCType: type at: &data];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: coder
|
||||
{
|
||||
const char *type = [self objCType];
|
||||
[coder decodeValueOfObjCType: type at: &data withName: NULL];
|
||||
[coder decodeValueOfObjCType: type at: &data];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,47 +35,19 @@
|
|||
methods here (like pointValue) even though most likely, other concrete
|
||||
subclasses were created to handle these types */
|
||||
|
||||
#define NS_RAISE_MALLOC \
|
||||
[NSException raise: NSMallocException \
|
||||
format: @"No memory left to allocate"]
|
||||
|
||||
#define NS_CHECK_MALLOC(ptr) \
|
||||
if (!ptr) {NS_RAISE_MALLOC;}
|
||||
|
||||
@implementation NSConcreteValue
|
||||
|
||||
// NSCopying
|
||||
- (id) deepen
|
||||
{
|
||||
void *old_ptr;
|
||||
char *old_typ;
|
||||
int size;
|
||||
|
||||
size = objc_sizeof_type(objctype);
|
||||
old_ptr = data;
|
||||
data = (void *)NSZoneMalloc(fastZone(self), size);
|
||||
NS_CHECK_MALLOC(data)
|
||||
memcpy(data, old_ptr, size);
|
||||
|
||||
old_typ = objctype;
|
||||
objctype = (char *)NSZoneMalloc(fastZone(self), strlen(old_typ)+1);
|
||||
NS_CHECK_MALLOC(objctype)
|
||||
strcpy(objctype, old_typ);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
- (id) initValue: (const void *)value
|
||||
withObjCType: (const char *)type
|
||||
- (id) initWithBytes: (const void *)value
|
||||
objCType: (const char *)type
|
||||
{
|
||||
int size;
|
||||
|
||||
if (!value || !type)
|
||||
{
|
||||
NSLog(@"Tried to create NSValue with NULL value or NULL type");
|
||||
[self release];
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -87,16 +59,14 @@
|
|||
if (size <= 0)
|
||||
{
|
||||
NSLog(@"Tried to create NSValue with invalid Objective-C type");
|
||||
[self release];
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
data = (void *)NSZoneMalloc(fastZone(self), size);
|
||||
NS_CHECK_MALLOC(data)
|
||||
memcpy(data, value, size);
|
||||
|
||||
objctype = (char *)NSZoneMalloc(fastZone(self), strlen(type)+1);
|
||||
NS_CHECK_MALLOC(objctype)
|
||||
strcpy(objctype, type);
|
||||
return self;
|
||||
}
|
||||
|
@ -183,8 +153,8 @@
|
|||
|
||||
- (NSString *) description
|
||||
{
|
||||
int size;
|
||||
NSData *rep;
|
||||
unsigned size;
|
||||
NSData *rep;
|
||||
|
||||
size = objc_sizeof_type(objctype);
|
||||
rep = [NSData dataWithBytes: data length: size];
|
||||
|
@ -194,17 +164,27 @@
|
|||
// NSCoding
|
||||
- (void) encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[super encodeWithCoder: coder];
|
||||
// FIXME: Do we need to check for encoding void, void * or will
|
||||
// NSCoder do this for us?
|
||||
[coder encodeValueOfObjCType: @encode(char *) at: &objctype];
|
||||
[coder encodeValueOfObjCType: objctype at: &data];
|
||||
unsigned size;
|
||||
|
||||
size = strlen(objctype)+1;
|
||||
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||
[coder encodeArrayOfObjCType: @encode(char) count: size at: objctype];
|
||||
size = objc_sizeof_type(objctype);
|
||||
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||
[coder encodeArrayOfObjCType: @encode(unsigned char) count: size at: data];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[NSException raise: NSInconsistentArchiveException
|
||||
format: @"Cannot unarchive class - Need NSValueDecoder."];
|
||||
unsigned size;
|
||||
|
||||
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||
objctype = (void *)NSZoneMalloc(fastZone(self), size);
|
||||
[coder decodeArrayOfObjCType: @encode(char) count: size at: objctype];
|
||||
[coder decodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||
data = (void *)NSZoneMalloc(fastZone(self), size);
|
||||
[coder decodeArrayOfObjCType: @encode(unsigned char) count: size at: data];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,142 +31,208 @@
|
|||
|
||||
@implementation NSNumber
|
||||
|
||||
static Class abstractClass;
|
||||
static Class boolNumberClass;
|
||||
static Class charNumberClass;
|
||||
static Class uCharNumberClass;
|
||||
static Class shortNumberClass;
|
||||
static Class uShortNumberClass;
|
||||
static Class intNumberClass;
|
||||
static Class uIntNumberClass;
|
||||
static Class longNumberClass;
|
||||
static Class uLongNumberClass;
|
||||
static Class longLongNumberClass;
|
||||
static Class uLongLongNumberClass;
|
||||
static Class floatNumberClass;
|
||||
static Class doubleNumberClass;
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSNumber class])
|
||||
{
|
||||
abstractClass = self;
|
||||
|
||||
boolNumberClass = [NSBoolNumber class];
|
||||
charNumberClass = [NSCharNumber class];
|
||||
uCharNumberClass = [NSUCharNumber class];
|
||||
shortNumberClass = [NSShortNumber class];
|
||||
uShortNumberClass = [NSUShortNumber class];
|
||||
intNumberClass = [NSIntNumber class];
|
||||
uIntNumberClass = [NSUIntNumber class];
|
||||
longNumberClass = [NSLongNumber class];
|
||||
uLongNumberClass = [NSULongNumber class];
|
||||
longLongNumberClass = [NSLongLongNumber class];
|
||||
uLongLongNumberClass = [NSULongLongNumber class];
|
||||
floatNumberClass = [NSFloatNumber class];
|
||||
doubleNumberClass = [NSDoubleNumber class];
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns the concrete class associated with the type encoding. Note
|
||||
that we don't allow NSNumber to instantiate any class but its own
|
||||
concrete subclasses (see check at end of method) */
|
||||
+ (Class)valueClassWithObjCType:(const char *)type
|
||||
+ (Class)valueClassWithObjCType: (const char *)type
|
||||
{
|
||||
Class theClass = Nil;
|
||||
Class theClass = Nil;
|
||||
|
||||
switch (*type) {
|
||||
case _C_CHR:
|
||||
theClass = [NSCharNumber class];
|
||||
break;
|
||||
case _C_UCHR:
|
||||
theClass = [NSUCharNumber class];
|
||||
break;
|
||||
case _C_SHT:
|
||||
theClass = [NSShortNumber class];
|
||||
break;
|
||||
case _C_USHT:
|
||||
theClass = [NSUShortNumber class];
|
||||
break;
|
||||
case _C_INT:
|
||||
theClass = [NSIntNumber class];
|
||||
break;
|
||||
case _C_UINT:
|
||||
theClass = [NSUIntNumber class];
|
||||
break;
|
||||
case _C_LNG:
|
||||
theClass = [NSLongNumber class];
|
||||
break;
|
||||
case _C_ULNG:
|
||||
theClass = [NSULongNumber class];
|
||||
break;
|
||||
case 'q':
|
||||
theClass = [NSLongLongNumber class];
|
||||
break;
|
||||
case 'Q':
|
||||
theClass = [NSULongLongNumber class];
|
||||
break;
|
||||
case _C_FLT:
|
||||
theClass = [NSFloatNumber class];
|
||||
break;
|
||||
case _C_DBL:
|
||||
theClass = [NSDoubleNumber class];
|
||||
break;
|
||||
default:
|
||||
switch (*type)
|
||||
{
|
||||
case _C_CHR: return charNumberClass;
|
||||
case _C_UCHR: return uCharNumberClass;
|
||||
case _C_SHT: return shortNumberClass;
|
||||
case _C_USHT: return uShortNumberClass;
|
||||
case _C_INT: return intNumberClass;
|
||||
case _C_UINT: return uIntNumberClass;
|
||||
case _C_LNG: return longNumberClass;
|
||||
case _C_ULNG: return uLongNumberClass;
|
||||
#ifdef _C_LNGLNG
|
||||
case _C_LNGLNG:
|
||||
#else
|
||||
case 'q':
|
||||
#endif
|
||||
return longLongNumberClass;
|
||||
#ifdef _C_ULNGLNG
|
||||
case _C_ULNGLNG:
|
||||
#else
|
||||
case 'Q':
|
||||
#endif
|
||||
return uLongLongNumberClass;
|
||||
case _C_FLT: return floatNumberClass;
|
||||
case _C_DBL: return doubleNumberClass;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (theClass == Nil && self == [NSNumber class]) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Invalid number type"];
|
||||
if (theClass == Nil && self == abstractClass)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Invalid number type"];
|
||||
/* NOT REACHED */
|
||||
} else if (theClass == Nil)
|
||||
theClass = [super valueClassWithObjCType:type];
|
||||
}
|
||||
else if (theClass == Nil)
|
||||
theClass = [super valueClassWithObjCType: type];
|
||||
|
||||
return theClass;
|
||||
return theClass;
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithBool:(BOOL)value
|
||||
+ (NSNumber *)numberWithBool: (BOOL)value
|
||||
{
|
||||
return [[[NSBoolNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [boolNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithChar:(char)value
|
||||
+ (NSNumber *)numberWithChar: (char)value
|
||||
{
|
||||
return [[[NSCharNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [charNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithDouble:(double)value
|
||||
+ (NSNumber *)numberWithDouble: (double)value
|
||||
{
|
||||
return [[[NSDoubleNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [doubleNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithFloat:(float)value
|
||||
+ (NSNumber *)numberWithFloat: (float)value
|
||||
{
|
||||
return [[[NSFloatNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [floatNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithInt:(int)value
|
||||
+ (NSNumber *)numberWithInt: (int)value
|
||||
{
|
||||
return [[[NSIntNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [intNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithLong:(long)value
|
||||
+ (NSNumber *)numberWithLong: (long)value
|
||||
{
|
||||
return [[[NSLongNumber alloc] initValue:&value withObjCType:NULL] autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [longNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithLongLong:(long long)value
|
||||
+ (NSNumber *)numberWithLongLong: (long long)value
|
||||
{
|
||||
return [[[NSLongLongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [longLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithShort:(short)value
|
||||
+ (NSNumber *)numberWithShort: (short)value
|
||||
{
|
||||
return [[[NSShortNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [shortNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value
|
||||
+ (NSNumber *)numberWithUnsignedChar: (unsigned char)value
|
||||
{
|
||||
return [[[NSUCharNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [uCharNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value
|
||||
+ (NSNumber *)numberWithUnsignedInt: (unsigned int)value
|
||||
{
|
||||
return [[[NSUIntNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [uIntNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value
|
||||
+ (NSNumber *)numberWithUnsignedLong: (unsigned long)value
|
||||
{
|
||||
return [[[NSULongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [uLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value
|
||||
+ (NSNumber *)numberWithUnsignedLongLong: (unsigned long long)value
|
||||
{
|
||||
return [[[NSULongLongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [uLongLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value
|
||||
+ (NSNumber *)numberWithUnsignedShort: (unsigned short)value
|
||||
{
|
||||
return [[[NSUShortNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
NSNumber *theObj;
|
||||
|
||||
theObj = [uShortNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
theObj = [theObj initWithBytes: &value objCType: NULL];
|
||||
return AUTORELEASE(theObj);
|
||||
}
|
||||
|
||||
+ valueFromString: (NSString *)string
|
||||
+ (NSValue*)valueFromString: (NSString *)string
|
||||
{
|
||||
/* FIXME: implement this better */
|
||||
const char *str;
|
||||
|
@ -182,223 +248,243 @@
|
|||
return [NSNumber numberWithInt: 0];
|
||||
}
|
||||
|
||||
- (id)initWithBool:(BOOL)value
|
||||
- (id)initWithBool: (BOOL)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSBoolNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [boolNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithChar:(char)value
|
||||
- (id)initWithChar: (char)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSCharNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [charNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithDouble:(double)value
|
||||
- (id)initWithDouble: (double)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSDoubleNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [doubleNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithFloat:(float)value
|
||||
- (id)initWithFloat: (float)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSFloatNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [floatNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithInt:(int)value
|
||||
- (id)initWithInt: (int)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSIntNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [intNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithLong:(long)value
|
||||
- (id)initWithLong: (long)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSLongNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [longNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithLongLong:(long long)value
|
||||
- (id)initWithLongLong: (long long)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSLongLongNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [longLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithShort:(short)value
|
||||
- (id)initWithShort: (short)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSShortNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [shortNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnsignedChar:(unsigned char)value
|
||||
- (id)initWithUnsignedChar: (unsigned char)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSUCharNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [uCharNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnsignedInt:(unsigned int)value
|
||||
- (id)initWithUnsignedInt: (unsigned int)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSUIntNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [uIntNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnsignedLong:(unsigned long)value
|
||||
- (id)initWithUnsignedLong: (unsigned long)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSULongNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [uLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnsignedLongLong:(unsigned long long)value
|
||||
- (id)initWithUnsignedLongLong: (unsigned long long)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSULongLongNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [uLongLongNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithUnsignedShort:(unsigned short)value
|
||||
- (id)initWithUnsignedShort: (unsigned short)value
|
||||
{
|
||||
[self dealloc];
|
||||
return self=[[NSUShortNumber alloc] initValue:&value withObjCType:NULL];
|
||||
RELEASE(self);
|
||||
self = [uShortNumberClass allocWithZone: NSDefaultMallocZone()];
|
||||
self = [self initWithBytes: &value objCType: NULL];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) copy
|
||||
{
|
||||
return [self retain];
|
||||
return RETAIN(self);
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone*)zone
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
if (NSShouldRetainWithZone(self, zone)) {
|
||||
return [self retain];
|
||||
}
|
||||
else {
|
||||
return NSCopyObject(self, 0, zone);
|
||||
}
|
||||
return RETAIN(self);
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
return [self descriptionWithLocale: nil];
|
||||
return [self descriptionWithLocale: nil];
|
||||
}
|
||||
|
||||
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
/* All the rest of these methods must be implemented by a subclass */
|
||||
- (BOOL)boolValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (char)charValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (double)doubleValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (float)floatValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)intValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (long long)longLongValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (long)longValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (short)shortValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (NSString *)stringValue
|
||||
{
|
||||
return [self descriptionWithLocale: nil];
|
||||
return [self descriptionWithLocale: nil];
|
||||
}
|
||||
|
||||
- (unsigned char)unsignedCharValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned int)unsignedIntValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned long long)unsignedLongLongValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned long)unsignedLongValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned short)unsignedShortValue
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)compare:(NSNumber *)otherNumber
|
||||
- (NSComparisonResult)compare: (NSNumber *)otherNumber
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return 0;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToNumber:(NSNumber *)otherNumber
|
||||
- (BOOL)isEqualToNumber: (NSNumber *)otherNumber
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return NO;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
// NSCoding (done by subclasses)
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
- (void)encodeWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[super encodeWithCoder:coder];
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder
|
||||
- (id)initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
[NSException raise:NSInconsistentArchiveException
|
||||
format:@"Cannot unarchive from NSNumber class - Need NSValueDecoder."];
|
||||
return self;
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue