1995-04-03 20:49:14 +00:00
|
|
|
/* NSNumber - Object encapsulation of numbers
|
|
|
|
|
1996-02-22 16:02:02 +00:00
|
|
|
Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
1995-04-03 20:49:14 +00:00
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
1996-02-22 16:02:02 +00:00
|
|
|
Created: Mar 1995
|
1995-04-03 20:49:14 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-03 20:49:14 +00:00
|
|
|
|
|
|
|
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
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1995-04-03 20:49:14 +00:00
|
|
|
*/
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
#include <string.h>
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
1998-12-20 21:27:47 +00:00
|
|
|
#include <base/preface.h>
|
1999-06-14 09:59:59 +00:00
|
|
|
#include <base/fast.x>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSString.h>
|
2000-03-19 20:57:09 +00:00
|
|
|
#include <Foundation/NSNotification.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSConcreteNumber.h>
|
2000-03-19 20:57:09 +00:00
|
|
|
#include <Foundation/NSMapTable.h>
|
|
|
|
#include <Foundation/NSThread.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSCoder.h>
|
1995-04-03 20:49:14 +00:00
|
|
|
|
2000-03-18 07:56:43 +00:00
|
|
|
@interface NSNumber (Private)
|
2000-03-19 21:40:06 +00:00
|
|
|
- (int) _typeNext;
|
2000-03-19 20:57:09 +00:00
|
|
|
- (int) _typeOrder;
|
2000-03-18 07:56:43 +00:00
|
|
|
@end
|
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
@implementation NSNumber
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
static NSMapTable *numberMap;
|
|
|
|
static BOOL multiThreaded = NO;
|
|
|
|
static NSNumber *boolN;
|
|
|
|
static NSNumber *boolY;
|
|
|
|
static NSNumber *smallIntegers[GS_SMALL * 2 + 1];
|
|
|
|
static unsigned int smallHashes[GS_SMALL * 2 + 1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cache info for each number class. The caches for all the standard types
|
|
|
|
* of number are built in the NSNumber +initialize method - which is protected
|
|
|
|
* by locks. Therafter, in a multi-threaded system we may waste some memory
|
|
|
|
* in order to get speed.
|
|
|
|
*/
|
|
|
|
GSNumberInfo*
|
|
|
|
GSNumberInfoFromObject(NSNumber *o)
|
|
|
|
{
|
|
|
|
Class c;
|
|
|
|
GSNumberInfo *info;
|
|
|
|
|
|
|
|
c = fastClass(o);
|
|
|
|
info = (GSNumberInfo*)NSMapGet (numberMap, (void*)c);
|
|
|
|
if (info == 0)
|
|
|
|
{
|
|
|
|
info = (GSNumberInfo*)objc_malloc(sizeof(GSNumberInfo));
|
2000-03-19 21:40:06 +00:00
|
|
|
info->typeNext = [o _typeNext];
|
2000-03-19 20:57:09 +00:00
|
|
|
info->typeOrder = [o _typeOrder];
|
|
|
|
info->compValue = (NSComparisonResult (*)(NSNumber*, SEL, NSNumber*))
|
|
|
|
[o methodForSelector: @selector(compare:)];
|
|
|
|
info->boolValue = (BOOL (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(boolValue)];
|
|
|
|
info->charValue = (char (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(charValue)];
|
|
|
|
info->unsignedCharValue = (unsigned char (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(unsignedCharValue)];
|
|
|
|
info->shortValue = (short (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(shortValue)];
|
|
|
|
info->unsignedShortValue = (unsigned short (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(unsignedShortValue)];
|
|
|
|
info->intValue = (int (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(intValue)];
|
|
|
|
info->unsignedIntValue = (unsigned int (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(unsignedIntValue)];
|
|
|
|
info->longValue = (long (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(longValue)];
|
|
|
|
info->unsignedLongValue = (unsigned long (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(unsignedLongValue)];
|
|
|
|
info->longLongValue = (long long (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(longLongValue)];
|
|
|
|
info->unsignedLongLongValue = (unsigned long long (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(unsignedLongLongValue)];
|
|
|
|
info->floatValue = (float (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(floatValue)];
|
|
|
|
info->doubleValue = (double (*)(NSNumber*, SEL))
|
|
|
|
[o methodForSelector: @selector(doubleValue)];
|
|
|
|
|
|
|
|
if (multiThreaded == YES)
|
|
|
|
{
|
|
|
|
NSMapTable *table;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory leak for efficiency - the old map table is never
|
|
|
|
* deallocated, so we don't have to do any locking.
|
|
|
|
*/
|
|
|
|
table = NSCopyMapTableWithZone(numberMap, NSDefaultMallocZone());
|
|
|
|
NSMapInsert(table, (void*)c, (void*)info);
|
|
|
|
numberMap = table;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSMapInsert(numberMap, (void*)c, (void*)info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
GSSmallHash(int n)
|
|
|
|
{
|
|
|
|
return smallHashes[n + GS_SMALL];
|
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
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;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (void) _becomeThreaded: (NSNotification*)notification
|
|
|
|
{
|
|
|
|
multiThreaded = YES;
|
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSNumber class])
|
|
|
|
{
|
2000-03-19 20:57:09 +00:00
|
|
|
BOOL boolean;
|
|
|
|
int integer;
|
|
|
|
unsigned (*hasher)(NSNumber*, SEL);
|
1999-06-14 09:07:52 +00:00
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
abstractClass = self;
|
|
|
|
hasher = (unsigned (*)(NSNumber*, SEL))
|
|
|
|
[self instanceMethodForSelector: @selector(hash)];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create cache for per-subclass method implementations etc.
|
|
|
|
*/
|
|
|
|
numberMap = NSCreateMapTable (NSNonOwnedPointerMapKeyCallBacks,
|
|
|
|
NSOwnedPointerMapValueCallBacks, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cache standard subclass info.
|
|
|
|
*/
|
1999-06-14 09:07:52 +00:00
|
|
|
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];
|
2000-03-19 20:57:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cache bool values.
|
|
|
|
*/
|
|
|
|
boolN = (NSNumber*)NSAllocateObject(boolNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
|
|
|
boolean = NO;
|
|
|
|
boolN = [boolN initWithBytes: &boolean objCType: NULL];
|
|
|
|
|
|
|
|
boolY = (NSNumber*)NSAllocateObject(boolNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
|
|
|
boolean = YES;
|
|
|
|
boolY = [boolY initWithBytes: &boolean objCType: NULL];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cache small integer values.
|
|
|
|
*/
|
|
|
|
for (integer = -GS_SMALL; integer <= GS_SMALL; integer++)
|
|
|
|
{
|
|
|
|
NSNumber *num;
|
|
|
|
|
|
|
|
num = (NSNumber*)NSAllocateObject(intNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
|
|
|
num = [num initWithBytes: &integer objCType: NULL];
|
|
|
|
smallIntegers[integer + GS_SMALL] = num;
|
|
|
|
smallHashes[integer + GS_SMALL] = (*hasher)(num, @selector(hash));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we know if we are multi-threaded so that if the caches
|
|
|
|
* need to grow, we do it by copying and replacing without deleting
|
|
|
|
* an old cache that may be in use by another thread.
|
|
|
|
*/
|
|
|
|
if ([NSThread isMultiThreaded])
|
|
|
|
{
|
|
|
|
[self _becomeThreaded: nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver: self
|
|
|
|
selector: @selector(_becomeThreaded:)
|
|
|
|
name: NSWillBecomeMultiThreadedNotification
|
|
|
|
object: nil];
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
/* 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) */
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (Class) valueClassWithObjCType: (const char*)type
|
1999-06-14 09:07:52 +00:00
|
|
|
{
|
|
|
|
Class theClass = Nil;
|
|
|
|
|
|
|
|
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:
|
1995-04-03 20:49:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
if (theClass == Nil && self == abstractClass)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"Invalid number type"];
|
1995-04-03 20:49:14 +00:00
|
|
|
/* NOT REACHED */
|
1999-06-14 09:07:52 +00:00
|
|
|
}
|
|
|
|
else if (theClass == Nil)
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
|
|
|
theClass = [super valueClassWithObjCType: type];
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return theClass;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithBool: (BOOL)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value == YES)
|
|
|
|
{
|
|
|
|
return boolY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return boolN;
|
|
|
|
}
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithChar: (char)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(charNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithDouble: (double)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(doubleNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithFloat: (float)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(floatNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithInt: (int)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(intNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithLong: (long)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(longNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithLongLong: (long long)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(longLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithShort: (short)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(shortNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithUnsignedChar: (unsigned char)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(uCharNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithUnsignedInt: (unsigned int)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(uIntNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithUnsignedLong: (unsigned long)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(uLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithUnsignedLongLong: (unsigned long long)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(uLongLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSNumber*) numberWithUnsignedShort: (unsigned short)value
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
NSNumber *theObj;
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return smallIntegers[value + GS_SMALL];
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
theObj = (NSNumber*)NSAllocateObject(uShortNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
theObj = [theObj initWithBytes: &value objCType: NULL];
|
|
|
|
return AUTORELEASE(theObj);
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
+ (NSValue*) valueFromString: (NSString*)string
|
1997-09-18 14:56:47 +00:00
|
|
|
{
|
|
|
|
/* FIXME: implement this better */
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
str = [string cString];
|
|
|
|
if (strchr(str, '.') >= 0 || strchr(str, 'e') >= 0
|
|
|
|
|| strchr(str, 'E') >= 0)
|
|
|
|
return [NSNumber numberWithDouble: atof(str)];
|
|
|
|
else if (strchr(str, '-') >= 0)
|
|
|
|
return [NSNumber numberWithInt: atoi(str)];
|
|
|
|
else
|
|
|
|
return [NSNumber numberWithUnsignedInt: atoi(str)];
|
|
|
|
return [NSNumber numberWithInt: 0];
|
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithBool: (BOOL)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value == YES)
|
|
|
|
{
|
|
|
|
self = boolY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self = boolN;
|
|
|
|
}
|
|
|
|
return RETAIN(self);
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithChar: (char)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(charNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithDouble: (double)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
self = (NSNumber*)NSAllocateObject(doubleNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithFloat: (float)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
self = (NSNumber*)NSAllocateObject(floatNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithInt: (int)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(intNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithLong: (long)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(longNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithLongLong: (long long)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(longLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithShort: (short)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL && value >= -GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(shortNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithUnsignedChar: (unsigned char)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(uCharNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithUnsignedInt: (unsigned int)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(uIntNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithUnsignedLong: (unsigned long)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(uLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithUnsignedLongLong: (unsigned long long)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(uLongLongNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithUnsignedShort: (unsigned short)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
2000-03-19 20:57:09 +00:00
|
|
|
if (value <= GS_SMALL)
|
|
|
|
{
|
|
|
|
return RETAIN(smallIntegers[value + GS_SMALL]);
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
self = (NSNumber*)NSAllocateObject(uShortNumberClass, 0,
|
|
|
|
NSDefaultMallocZone());
|
1999-06-14 09:07:52 +00:00
|
|
|
self = [self initWithBytes: &value objCType: NULL];
|
|
|
|
return self;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1998-03-12 14:21:20 +00:00
|
|
|
- (id) copy
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
return RETAIN(self);
|
1998-03-12 14:21:20 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1998-03-12 14:21:20 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
return RETAIN(self);
|
1998-03-12 14:21:20 +00:00
|
|
|
}
|
|
|
|
|
1998-02-05 22:06:20 +00:00
|
|
|
- (NSString*) description
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
return [self descriptionWithLocale: nil];
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return nil;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
/* All the rest of these methods must be implemented by a subclass */
|
2000-03-19 20:57:09 +00:00
|
|
|
- (BOOL) boolValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (char) charValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (double) doubleValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (float) floatValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (int) intValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (long long) longLongValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (long) longValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (short) shortValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (NSString*) stringValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
return [self descriptionWithLocale: nil];
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (unsigned char) unsignedCharValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (unsigned int) unsignedIntValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (unsigned long long) unsignedLongLongValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (unsigned long) unsignedLongValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (unsigned short) unsignedShortValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (NSComparisonResult) compare: (NSNumber*)other
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-03-19 20:57:09 +00:00
|
|
|
GSNumberInfo *otherInfo;
|
|
|
|
GSNumberInfo *myInfo;
|
|
|
|
double otherValue;
|
|
|
|
double myValue;
|
|
|
|
|
|
|
|
myInfo = GSNumberInfoFromObject(self);
|
|
|
|
otherInfo = GSNumberInfoFromObject(other);
|
|
|
|
myValue = (*(myInfo->doubleValue))(self, @selector(doubleValue));
|
|
|
|
otherValue = (*(otherInfo->doubleValue))(other, @selector(doubleValue));
|
|
|
|
|
|
|
|
if (myValue == otherValue)
|
|
|
|
{
|
|
|
|
return NSOrderedSame;
|
|
|
|
}
|
|
|
|
else if (myValue < otherValue)
|
|
|
|
{
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NSOrderedDescending;
|
|
|
|
}
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
/*
|
|
|
|
* Because of the rule that two numbers which are the same according to
|
|
|
|
* [-isEqual: ] must generate the same hash, we must generate the hash
|
|
|
|
* from the most general representation of the number.
|
|
|
|
* NB. Don't change this without changing the matching function in
|
|
|
|
* NSConcreteNumber.m
|
|
|
|
*/
|
1998-02-05 22:06:20 +00:00
|
|
|
- (unsigned) hash
|
|
|
|
{
|
2000-03-19 20:57:09 +00:00
|
|
|
union {
|
|
|
|
double d;
|
|
|
|
unsigned char c[sizeof(double)];
|
|
|
|
} val;
|
|
|
|
unsigned hash = 0;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
val.d = [self doubleValue];
|
|
|
|
for (i = 0; i < sizeof(double); i++)
|
|
|
|
{
|
|
|
|
hash += val.c[i];
|
|
|
|
}
|
|
|
|
return hash;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 09:59:59 +00:00
|
|
|
- (BOOL) isEqual: o
|
|
|
|
{
|
2000-03-19 21:04:02 +00:00
|
|
|
if (o == self)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
1999-06-14 09:59:59 +00:00
|
|
|
if (o != nil && fastIsInstance(o)
|
|
|
|
&& fastInstanceIsKindOfClass(o, abstractClass))
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
|
|
|
return [self isEqualToNumber: (NSNumber*)o];
|
|
|
|
}
|
|
|
|
return [super isEqual: o];
|
1999-06-14 09:59:59 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (BOOL) isEqualToNumber: (NSNumber*)o
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
2000-03-19 21:04:02 +00:00
|
|
|
if (o == self)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2000-03-19 20:57:09 +00:00
|
|
|
if ([self compare: o] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return NO;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
// NSCoding (done by subclasses)
|
2000-03-19 20:57:09 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)coder
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)coder
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return nil;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-19 21:40:06 +00:00
|
|
|
- (int) _typeNext
|
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
2000-03-19 20:57:09 +00:00
|
|
|
- (int) _typeOrder
|
2000-03-18 07:56:43 +00:00
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
1996-02-22 16:02:02 +00:00
|
|
|
@end
|