Re: Need Help With Creating NSMutableNumber Class
Re: Need Help With Creating NSMutableNumber Class
- Subject: Re: Need Help With Creating NSMutableNumber Class
- From: Chase <email@hidden>
- Date: Mon, 11 Jul 2005 06:56:57 -0500
Okay, here's what I've got. Everything seems to be working, but
still I'm not convinced that the "+numberWithWhatever:" methods are
doing what they're supposed to do in terms of setting up the
autorelase of the returned object.
Please, look this over and help me get it exactly right. Once we've
got it picture-perfect, it'll be a nice little snippet for anyone to
use. :)
Thanks.
- Chase
// FULL CODE FOR NSMutableNumber REPLACEMENT BELOW...
#import <Foundation/Foundation.h>
@interface XXXMutableNumber : NSObject {
NSNumber * _number;
}
- (void)setBoolValue:(BOOL)value;
- (void)setCharValue:(char)value;
- (void)setDoubleValue:(double)value;
- (void)setFloatValue:(float)value;
- (void)setIntValue:(int)value;
- (void)setLongValue:(long)value;
- (void)setLongLongValue:(long long)value;
- (void)setShortValue:(short)value;
- (void)setUnsignedCharValue:(unsigned char)value;
- (void)setUnsignedIntValue:(unsigned int)value;
- (void)setUnsignedLongValue:(unsigned long)value;
- (void)setUnsignedLongLongValue:(unsigned long long)value;
- (void)setUnsignedShortValue:(unsigned short)value;
@end
@implementation XXXMutableNumber
+ (XXXMutableNumber *)numberWithBool:(BOOL)value {
return [[[XXXMutableNumber alloc] initWithBool:value] autorelease];
}
+ (XXXMutableNumber *)numberWithChar:(char)value {
return [[[XXXMutableNumber alloc] initWithChar:value] autorelease];
}
+ (XXXMutableNumber *)numberWithDouble:(double)value {
return [[[XXXMutableNumber alloc] initWithDouble:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithFloat:(float)value {
return [[[XXXMutableNumber alloc] initWithFloat:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithInt:(int)value {
return [[[XXXMutableNumber alloc] initWithInt:value] autorelease];
}
+ (XXXMutableNumber *)numberWithLong:(long)value {
return [[[XXXMutableNumber alloc] initWithLong:value] autorelease];
}
+ (XXXMutableNumber *)numberWithLongLong:(long long)value {
return [[[XXXMutableNumber alloc] initWithLongLong:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithShort:(short)value {
return [[[XXXMutableNumber alloc] initWithShort:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithUnsignedChar:(unsigned char)value {
return [[[XXXMutableNumber alloc] initWithUnsignedChar:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithUnsignedInt:(unsigned int)value {
return [[[XXXMutableNumber alloc] initWithUnsignedInt:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithUnsignedLong:(unsigned long)value {
return [[[XXXMutableNumber alloc] initWithUnsignedLong:value]
autorelease];
}
+ (XXXMutableNumber *)numberWithUnsignedLongLong:(unsigned long long)
value {
return [[[XXXMutableNumber alloc]
initWithUnsignedLongLong:value] autorelease];
}
+ (XXXMutableNumber *)numberWithUnsignedShort:(unsigned short)value {
return [[[XXXMutableNumber alloc] initWithUnsignedShort:value]
autorelease];
}
- (id)initWithBool:(BOOL)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithBool:value];
}
return self;
}
- (id)initWithChar:(char)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithChar:value];
}
return self;
}
- (id)initWithDouble:(double)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithDouble:value];
}
return self;
}
- (id)initWithFloat:(float)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithFloat:value];
}
return self;
}
- (id)initWithInt:(int)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithInt:value];
}
return self;
}
- (id)initWithLong:(long)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithLong:value];
}
return self;
}
- (id)initWithLongLong:(long long)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithLongLong:value];
}
return self;
}
- (id)initWithShort:(short)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithShort:value];
}
return self;
}
- (id)initWithUnsignedChar:(unsigned char)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithUnsignedChar:value];
}
return self;
}
- (id)initWithUnsignedInt:(unsigned int)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithUnsignedInt:value];
}
return self;
}
- (id)initWithUnsignedLong:(unsigned long)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithUnsignedLong:value];
}
return self;
}
- (id)initWithUnsignedLongLong:(unsigned long long)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithUnsignedLongLong:value];
}
return self;
}
- (id)initWithUnsignedShort:(unsigned short)value {
self = [super init];
if (self) {
_number = [[NSNumber alloc] initWithUnsignedShort:value];
}
return self;
}
- (void)setBoolValue:(BOOL)value {
[_number release];
_number = [[NSNumber alloc] initWithBool:value];
}
- (void)setCharValue:(char)value {
[_number release];
_number = [[NSNumber alloc] initWithChar:value];
}
- (void)setDoubleValue:(double)value {
[_number release];
_number = [[NSNumber alloc] initWithDouble:value];
}
- (void)setFloatValue:(float)value {
[_number release];
_number = [[NSNumber alloc] initWithFloat:value];
}
- (void)setIntValue:(int)value {
[_number release];
_number = [[NSNumber alloc] initWithInt:value];
}
- (void)setLongValue:(long)value {
[_number release];
_number = [[NSNumber alloc] initWithLong:value];
}
- (void)setLongLongValue:(long long)value {
[_number release];
_number = [[NSNumber alloc] initWithLongLong:value];
}
- (void)setShortValue:(short)value {
[_number release];
_number = [[NSNumber alloc] initWithShort:value];
}
- (void)setUnsignedCharValue:(unsigned char)value {
[_number release];
_number = [[NSNumber alloc] initWithUnsignedChar:value];
}
- (void)setUnsignedIntValue:(unsigned int)value {
[_number release];
_number = [[NSNumber alloc] initWithUnsignedInt:value];
}
- (void)setUnsignedLongValue:(unsigned long)value {
[_number release];
_number = [[NSNumber alloc] initWithUnsignedLong:value];
}
- (void)setUnsignedLongLongValue:(unsigned long long)value {
[_number release];
_number = [[NSNumber alloc] initWithUnsignedLongLong:value];
}
- (void)setUnsignedShortValue:(unsigned short)value {
[_number release];
_number = [[NSNumber alloc] initWithUnsignedShort:value];
}
- (BOOL)boolValue {
return [_number boolValue];
}
- (char)charValue {
return [_number charValue];
}
- (NSDecimal)decimalValue {
return [_number decimalValue];
}
- (NSString *)descriptionWithLocale:(NSDictionary *)aLocale {
return [_number descriptionWithLocale:aLocale];
}
- (double)doubleValue {
return [_number doubleValue];
}
- (float)floatValue {
return [_number floatValue];
}
- (int)intValue {
return [_number intValue];
}
- (long)longValue {
return [_number longValue];
}
- (long long)longLongValue {
return [_number longLongValue];
}
- (short)shortValue {
return [_number shortValue];
}
- (NSString *)stringValue {
return [_number stringValue];
}
- (unsigned char)unsignedCharValue {
return [_number unsignedCharValue];
}
- (unsigned int)unsignedIntValue {
return [_number unsignedIntValue];
}
- (unsigned long)unsignedLongValue {
return [_number unsignedLongValue];
}
- (unsigned long long)unsignedLongLongValue {
return [_number unsignedLongLongValue];
}
- (unsigned short)unsignedShortValue {
return [_number unsignedShortValue];
}
- (NSComparisonResult)compare:(NSNumber *)aNumber {
return [_number compare:aNumber];
}
- (BOOL)isEqualToNumber:(NSNumber *)aNumber {
return [_number isEqualToNumber:aNumber];
}
- (void)dealloc {
[_number release];
//NSZoneFree(private, [self zone]); // THIS WAS IN AN APPLE-
PROVIDED EXAMPLE.
// NOT SURE WHAT IT WAS
SUPPOSED TO DO.
// DO I NEED IT?
[super dealloc];
}
@end
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden