2001-12-17 14:31:42 +00:00
|
|
|
/** NSNumber - Object encapsulation of numbers
|
1995-04-03 20:49:14 +00:00
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
Copyright (C) 1993, 1994, 1996, 2000 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
|
2000-03-23 18:57:43 +00:00
|
|
|
Rewrite: Richard Frith-Macdonald <rfm@gnu.org>
|
|
|
|
Date: Mar 2000
|
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.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSNumber class reference</title>
|
|
|
|
$Date$ $Revision$
|
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>
|
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>
|
2000-03-23 18:57:43 +00:00
|
|
|
#include <Foundation/NSPortCoder.h>
|
2000-10-31 11:05:23 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
2000-03-18 07:56:43 +00:00
|
|
|
|
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];
|
|
|
|
|
|
|
|
/*
|
2000-03-23 18:57:43 +00:00
|
|
|
* Cache info for each number class.
|
|
|
|
* In a multi-threaded system we may waste some memory in order to get speed.
|
2000-03-19 20:57:09 +00:00
|
|
|
*/
|
|
|
|
GSNumberInfo*
|
|
|
|
GSNumberInfoFromObject(NSNumber *o)
|
|
|
|
{
|
|
|
|
Class c;
|
|
|
|
GSNumberInfo *info;
|
|
|
|
|
2000-10-31 11:05:23 +00:00
|
|
|
if (o == nil)
|
2000-11-03 10:11:56 +00:00
|
|
|
return 0;
|
2000-10-31 16:17:33 +00:00
|
|
|
c = GSObjCClass(o);
|
2000-03-19 20:57:09 +00:00
|
|
|
info = (GSNumberInfo*)NSMapGet (numberMap, (void*)c);
|
|
|
|
if (info == 0)
|
|
|
|
{
|
2000-03-23 18:57:43 +00:00
|
|
|
const char *t = [o objCType];
|
|
|
|
int order = -1;
|
|
|
|
|
|
|
|
if (strlen(t) != 1)
|
|
|
|
{
|
|
|
|
NSLog(@"Invalid return value (%s) from [%@ objCType]", t, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (*t)
|
|
|
|
{
|
|
|
|
case 'c': order = 1; break;
|
|
|
|
case 'C': order = 2; break;
|
|
|
|
case 's': order = 3; break;
|
|
|
|
case 'S': order = 4; break;
|
|
|
|
case 'i': order = 5; break;
|
|
|
|
case 'I': order = 6; break;
|
|
|
|
case 'l': order = 7; break;
|
|
|
|
case 'L': order = 8; break;
|
|
|
|
case 'q': order = 9; break;
|
|
|
|
case 'Q': order = 10; break;
|
|
|
|
case 'f': order = 11; break;
|
|
|
|
case 'd': order = 12; break;
|
|
|
|
default:
|
|
|
|
NSLog(@"Invalid return value (%s) from [%@ objCType]", t, c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-10-10 19:47:54 +00:00
|
|
|
info = (GSNumberInfo*)NSZoneMalloc(NSDefaultMallocZone(),
|
|
|
|
(sizeof(GSNumberInfo)));
|
2000-03-23 18:57:43 +00:00
|
|
|
info->typeLevel = order;
|
|
|
|
|
|
|
|
info->getValue = (void (*)(NSNumber*, SEL, void*))
|
|
|
|
[o methodForSelector: @selector(getValue:)];
|
2000-03-19 20:57:09 +00:00
|
|
|
|
|
|
|
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);
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfo *info;
|
|
|
|
CREATE_AUTORELEASE_POOL(pool);
|
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];
|
2000-03-23 18:57:43 +00:00
|
|
|
info = GSNumberInfoFromObject(AUTORELEASE([boolNumberClass alloc]));
|
|
|
|
/*
|
|
|
|
* Set the typeLevel for a boolean to be '0'
|
|
|
|
*/
|
|
|
|
info->typeLevel = 0;
|
1999-06-14 09:07:52 +00:00
|
|
|
charNumberClass = [NSCharNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([charNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
uCharNumberClass = [NSUCharNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([uCharNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
shortNumberClass = [NSShortNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([shortNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
uShortNumberClass = [NSUShortNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([uShortNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
intNumberClass = [NSIntNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([intNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
uIntNumberClass = [NSUIntNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([uIntNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
longNumberClass = [NSLongNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([longNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
uLongNumberClass = [NSULongNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([uLongNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
longLongNumberClass = [NSLongLongNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([longLongNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
uLongLongNumberClass = [NSULongLongNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([uLongLongNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
floatNumberClass = [NSFloatNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([floatNumberClass alloc]));
|
1999-06-14 09:07:52 +00:00
|
|
|
doubleNumberClass = [NSDoubleNumber class];
|
2000-03-23 18:57:43 +00:00
|
|
|
GSNumberInfoFromObject(AUTORELEASE([doubleNumberClass alloc]));
|
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];
|
|
|
|
}
|
2000-03-23 18:57:43 +00:00
|
|
|
RELEASE(pool);
|
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-08-07 22:00:31 +00:00
|
|
|
+ (NSNumber*) numberWithChar: (signed 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-08-07 22:00:31 +00:00
|
|
|
+ (NSNumber*) numberWithInt: (signed 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-08-07 22:00:31 +00:00
|
|
|
+ (NSNumber*) numberWithLong: (signed 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-08-07 22:00:31 +00:00
|
|
|
+ (NSNumber*) numberWithLongLong: (signed 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-08-07 22:00:31 +00:00
|
|
|
+ (NSNumber*) numberWithShort: (signed 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-23 18:57:43 +00:00
|
|
|
/*
|
|
|
|
* A moderately sane default init method - a zero value integer.
|
|
|
|
*/
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
return [self initWithInt: 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-08-07 22:00:31 +00:00
|
|
|
- (id) initWithChar: (signed 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-08-07 22:00:31 +00:00
|
|
|
- (id) initWithInt: (signed 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-08-07 22:00:31 +00:00
|
|
|
- (id) initWithLong: (signed 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-08-07 22:00:31 +00:00
|
|
|
- (id) initWithLongLong: (signed 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-08-07 22:00:31 +00:00
|
|
|
- (id) initWithShort: (signed 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
|
|
|
}
|
|
|
|
|
1999-06-14 09:07:52 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1998-03-12 14:21:20 +00:00
|
|
|
{
|
2000-03-23 18:57:43 +00:00
|
|
|
if (NSShouldRetainWithZone(self, zone))
|
|
|
|
return RETAIN(self);
|
|
|
|
else
|
|
|
|
return NSCopyObject(self, 0, zone);
|
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
|
|
|
}
|
|
|
|
|
2002-08-20 10:22:05 +00:00
|
|
|
/**
|
|
|
|
* <p>
|
|
|
|
* Produces a string representation of the number. For a boolean
|
|
|
|
* this will be either 'true' or 'false'. For other numbers the
|
|
|
|
* format is produced using the initWithFormat:locale:... method
|
|
|
|
* of NSString, and the format depends on the type of number as
|
|
|
|
* follows -
|
|
|
|
* </p>
|
|
|
|
* <deflist>
|
|
|
|
* <term>char</term>
|
|
|
|
* <desc>%i</desc>
|
|
|
|
* <term> short</term>
|
|
|
|
* <desc>%hi</desc>
|
|
|
|
* <term> int</term>
|
|
|
|
* <desc>%i</desc>
|
|
|
|
* <term> long</term>
|
|
|
|
* <desc>%li</desc>
|
|
|
|
* <term> long long</term>
|
|
|
|
* <desc>%li</desc>
|
|
|
|
* <term> unsigned char</term>
|
|
|
|
* <desc>%u</desc>
|
|
|
|
* <term> unsigned short</term>
|
|
|
|
* <desc>%hu</desc>
|
|
|
|
* <term> unsigned int</term>
|
|
|
|
* <desc>%u</desc>
|
|
|
|
* <term> unsigned long</term>
|
|
|
|
* <desc>%lu</desc>
|
|
|
|
* <term> unsigned long long</term>
|
|
|
|
* <desc>%lu</desc>
|
|
|
|
* <term> float</term>
|
|
|
|
* <desc>%0.7g</desc>
|
|
|
|
* <term> double</term>
|
|
|
|
* <desc>%0.16g</desc>
|
|
|
|
* </deflist>
|
|
|
|
*/
|
1998-02-05 22:06:20 +00:00
|
|
|
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
|
|
|
{
|
2001-11-12 13:01:09 +00:00
|
|
|
NSString *result = nil;
|
|
|
|
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
{
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"descriptionWithLocale: for abstract NSNumber"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
2002-08-14 07:36:25 +00:00
|
|
|
return [self boolValue] ? @"YES" : @"NO";
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 1:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%i" locale: locale,
|
2001-11-12 12:09:40 +00:00
|
|
|
(int)[self charValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 2:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%u" locale: locale,
|
2001-11-12 12:09:40 +00:00
|
|
|
(unsigned int)[self unsignedCharValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 3:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%hi" locale: locale,
|
|
|
|
[self shortValue]];
|
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 4:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%hu" locale: locale,
|
|
|
|
[self unsignedShortValue]];
|
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 5:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%i" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self intValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 6:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%u" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self unsignedIntValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 7:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%li" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self longValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 8:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%lu" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self unsignedLongValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 9:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%lli" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self longLongValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 10:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%llu" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self unsignedLongLongValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 11:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%0.7g" locale: locale,
|
2001-11-12 12:09:40 +00:00
|
|
|
(double)[self floatValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
case 12:
|
2001-11-12 13:01:09 +00:00
|
|
|
result = [[NSString alloc] initWithFormat: @"%0.16g" locale: locale,
|
2000-03-23 18:57:43 +00:00
|
|
|
[self doubleValue]];
|
2001-11-12 13:01:09 +00:00
|
|
|
break;
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for description"];
|
|
|
|
}
|
|
|
|
}
|
2001-11-12 13:01:09 +00:00
|
|
|
return AUTORELEASE(result);
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get boolValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (signed char) charValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get charValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get doubleValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get floatValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (signed int) intValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get intValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (signed long long) longLongValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get longLongValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (signed long) longValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get longValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return 0;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (signed short) shortValue
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get shortValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get unsignedCharrValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get unsignedIntValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get unsignedLongLongValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get unsignedLongValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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
|
|
|
{
|
2000-10-31 16:17:33 +00:00
|
|
|
if (GSObjCClass(self) == abstractClass)
|
2000-03-23 18:57:43 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: @"get unsignedShortValue from abstract NSNumber"];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSNumberInfo *info = GSNumberInfoFromObject(self);
|
|
|
|
|
|
|
|
switch (info->typeLevel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BOOL oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed char oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
unsigned char oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed short oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
unsigned short oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed int oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
unsigned int oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
unsigned long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
signed long long oData;
|
2000-03-23 18:57:43 +00:00
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
unsigned long long oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
float oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
double oData;
|
|
|
|
|
|
|
|
(*(info->getValue))(self, @selector(getValue:), &oData);
|
|
|
|
return oData;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"unknown number type value for get"];
|
|
|
|
}
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
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-08-09 14:40:14 +00:00
|
|
|
double otherValue;
|
|
|
|
double myValue;
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
if (other == self)
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
|
|
|
return NSOrderedSame;
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
else if (other == nil)
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
2000-08-07 22:00:31 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"nil argument for compare:"];
|
2000-03-19 20:57:09 +00:00
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2000-08-09 14:40:14 +00:00
|
|
|
myValue = [self doubleValue];
|
|
|
|
otherValue = [other doubleValue];
|
2000-08-07 22:00:31 +00:00
|
|
|
|
2000-08-09 14:40:14 +00:00
|
|
|
if (myValue == otherValue)
|
|
|
|
{
|
|
|
|
return NSOrderedSame;
|
|
|
|
}
|
|
|
|
else if (myValue < otherValue)
|
|
|
|
{
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NSOrderedDescending;
|
2000-03-19 20:57:09 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2000-08-07 22:00:31 +00:00
|
|
|
- (BOOL) isEqual: (id)o
|
1999-06-14 09:59:59 +00:00
|
|
|
{
|
2000-03-19 21:04:02 +00:00
|
|
|
if (o == self)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
else if (o == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2000-10-31 16:17:33 +00:00
|
|
|
else if (GSObjCIsInstance(o) == YES
|
|
|
|
&& GSObjCIsKindOf(GSObjCClass(o), abstractClass))
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
|
|
|
return [self isEqualToNumber: (NSNumber*)o];
|
|
|
|
}
|
2000-08-07 22:00:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
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-08-07 22:00:31 +00:00
|
|
|
else if (o == nil)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else if ([self compare: o] == NSOrderedSame)
|
2000-03-19 20:57:09 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
1999-06-14 09:07:52 +00:00
|
|
|
return NO;
|
1998-02-05 22:06:20 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
/*
|
|
|
|
* NSCoding
|
|
|
|
*/
|
|
|
|
|
2000-10-16 12:35:42 +00:00
|
|
|
- (Class) classForCoder
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-10-16 12:35:42 +00:00
|
|
|
return abstractClass;
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder
|
1995-04-03 20:49:14 +00:00
|
|
|
{
|
2000-03-23 18:57:43 +00:00
|
|
|
if ([aCoder isByref] == NO)
|
|
|
|
return self;
|
|
|
|
return [super replacementObjectForPortCoder: aCoder];
|
1995-04-03 20:49:14 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)coder
|
2000-03-19 21:40:06 +00:00
|
|
|
{
|
2000-10-16 12:35:42 +00:00
|
|
|
const char *t = [self objCType];
|
|
|
|
|
2001-05-11 15:23:24 +00:00
|
|
|
[coder encodeValueOfObjCType: @encode(signed char) at: t];
|
2000-10-16 12:35:42 +00:00
|
|
|
[coder encodeValueOfObjCType: t at: [self pointerValue]];
|
2000-03-19 21:40:06 +00:00
|
|
|
}
|
|
|
|
|
2000-03-23 18:57:43 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)coder
|
2000-03-18 07:56:43 +00:00
|
|
|
{
|
2000-10-16 12:35:42 +00:00
|
|
|
char t[2];
|
|
|
|
union {
|
|
|
|
signed char c;
|
|
|
|
unsigned char C;
|
|
|
|
signed short s;
|
|
|
|
unsigned short S;
|
|
|
|
signed int i;
|
|
|
|
unsigned int I;
|
|
|
|
signed long l;
|
|
|
|
unsigned long L;
|
|
|
|
signed long long q;
|
|
|
|
unsigned long long Q;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
} data;
|
|
|
|
|
2001-05-11 15:23:24 +00:00
|
|
|
[coder decodeValueOfObjCType: @encode(signed char) at: t];
|
2000-10-16 12:35:42 +00:00
|
|
|
t[1] = '\0';
|
|
|
|
[coder decodeValueOfObjCType: t at: &data];
|
|
|
|
switch (*t)
|
|
|
|
{
|
|
|
|
case 'c': self = [self initWithChar: data.c]; break;
|
|
|
|
case 'C': self = [self initWithUnsignedChar: data.C]; break;
|
|
|
|
case 's': self = [self initWithShort: data.s]; break;
|
|
|
|
case 'S': self = [self initWithUnsignedShort: data.S]; break;
|
|
|
|
case 'i': self = [self initWithInt: data.i]; break;
|
|
|
|
case 'I': self = [self initWithUnsignedInt: data.I]; break;
|
|
|
|
case 'l': self = [self initWithLong: data.l]; break;
|
|
|
|
case 'L': self = [self initWithUnsignedLong: data.L]; break;
|
|
|
|
case 'q': self = [self initWithLongLong: data.q]; break;
|
|
|
|
case 'Q': self = [self initWithUnsignedLongLong: data.Q]; break;
|
|
|
|
case 'f': self = [self initWithFloat: data.f]; break;
|
|
|
|
case 'd': self = [self initWithDouble: data.d]; break;
|
|
|
|
default:
|
|
|
|
[self dealloc];
|
|
|
|
self = nil;
|
|
|
|
NSLog(@"Attempt to decode number with unknown ObjC type");
|
|
|
|
}
|
2000-03-23 18:57:43 +00:00
|
|
|
return self;
|
2000-03-18 07:56:43 +00:00
|
|
|
}
|
1996-02-22 16:02:02 +00:00
|
|
|
@end
|