@@ -17,10 +17,12 @@ #import "OFExceptions.h" #import "macros.h" #define RETURN_AS(t) \ switch (type) { \ + case OF_NUMBER_BOOL: \ + return (t)value.bool_; \ case OF_NUMBER_CHAR: \ return (t)value.char_; \ case OF_NUMBER_SHORT: \ return (t)value.short_; \ case OF_NUMBER_INT: \ @@ -72,10 +74,13 @@ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE(o, n) \ switch (type) { \ + case OF_NUMBER_BOOL: \ + return [OFNumber numberWithBool: \ + value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ value.char_ o [n charValue]]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: \ @@ -152,10 +157,13 @@ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE2(o, n) \ switch (type) { \ + case OF_NUMBER_BOOL: \ + return [OFNumber numberWithBool: \ + value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ value.char_ o [n charValue]]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: \ @@ -230,10 +238,12 @@ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } #define CALCULATE3(o) \ switch (type) { \ + case OF_NUMBER_BOOL: \ + return [OFNumber numberWithBool: value.bool_ o]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: value.char_ o]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: value.short_ o]; \ case OF_NUMBER_INT: \ @@ -288,10 +298,15 @@ default: \ @throw [OFInvalidFormatException newWithClass: isa]; \ } @implementation OFNumber ++ numberWithBool: (BOOL)bool_ +{ + return [[[self alloc] initWithBool: bool_] autorelease]; +} + + numberWithChar: (char)char_ { return [[[self alloc] initWithChar: char_] autorelease]; } @@ -418,10 +433,20 @@ - init { @throw [OFNotImplementedException newWithClass: isa selector: _cmd]; } + +- initWithBool: (BOOL)bool_ +{ + self = [super init]; + + value.bool_ = bool_; + type = OF_NUMBER_BOOL; + + return self; +} - initWithChar: (char)char_ { self = [super init]; @@ -673,10 +698,15 @@ - (enum of_number_type)type { return type; } + +- (BOOL)boolValue +{ + RETURN_AS(BOOL) +} - (char)charValue { RETURN_AS(char) }