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>
|
|
|
|
#include <Foundation/NSConcreteNumber.h>
|
|
|
|
#include <Foundation/NSCoder.h>
|
1995-04-03 20:49:14 +00:00
|
|
|
|
|
|
|
@implementation NSNumber
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
+ (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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) */
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (Class)valueClassWithObjCType: (const char *)type
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
theClass = [super valueClassWithObjCType: type];
|
1995-04-03 20:49:14 +00:00
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
return theClass;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (NSNumber *)numberWithBool: (BOOL)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(boolNumberClass, 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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (NSNumber *)numberWithChar: (char)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(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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (NSNumber *)numberWithInt: (int)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(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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (NSNumber *)numberWithLong: (long)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(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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
+ (NSNumber *)numberWithShort: (short)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(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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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];
|
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id)initWithBool: (BOOL)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
self = (NSNumber*)NSAllocateObject(boolNumberClass, 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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id)initWithChar: (char)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id)initWithInt: (int)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id)initWithLong: (long)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id)initWithShort: (short)value
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:59:59 +00:00
|
|
|
NSDeallocateObject(self);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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);
|
|
|
|
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 */
|
|
|
|
- (BOOL)boolValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (char)charValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (double)doubleValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float)floatValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)intValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (long long)longLongValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (long)longValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (short)shortValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)stringValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
return [self descriptionWithLocale: nil];
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned char)unsignedCharValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int)unsignedIntValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned long long)unsignedLongLongValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned long)unsignedLongValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned short)unsignedShortValue
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (NSComparisonResult)compare: (NSNumber *)otherNumber
|
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
|
|
|
}
|
|
|
|
|
1998-02-05 22:06:20 +00:00
|
|
|
- (unsigned) hash
|
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return 0;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1999-06-14 09:59:59 +00:00
|
|
|
- (BOOL) isEqual: o
|
|
|
|
{
|
|
|
|
if (o != nil && fastIsInstance(o)
|
|
|
|
&& fastInstanceIsKindOfClass(o, abstractClass))
|
|
|
|
return [self isEqualToNumber: (NSNumber*)o];
|
|
|
|
else
|
|
|
|
return [super isEqual: o];
|
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (BOOL)isEqualToNumber: (NSNumber *)otherNumber
|
1998-02-05 22:06:20 +00:00
|
|
|
{
|
1999-06-14 09:07:52 +00:00
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
return NO;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
1995-04-03 20:49:14 +00:00
|
|
|
// NSCoding (done by subclasses)
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +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
|
|
|
}
|
|
|
|
|
1996-02-22 16:02:02 +00:00
|
|
|
@end
|