Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -12,10 +12,11 @@ #include #import "OFObject.h" enum of_number_type { + OF_NUMBER_BOOL, OF_NUMBER_CHAR, OF_NUMBER_SHORT, OF_NUMBER_INT, OF_NUMBER_LONG, OF_NUMBER_UCHAR, @@ -45,10 +46,11 @@ * \brief Provides a way to store a number in an object. */ @interface OFNumber: OFObject { union { + BOOL bool_; char char_; short short_; int int_; long long_; unsigned char uchar; @@ -74,10 +76,16 @@ double double_; } value; enum of_number_type type; } +/** + * \param bool_ A BOOL which the OFNumber should contain + * \return A new autoreleased OFNumber + */ ++ numberWithBool: (BOOL)bool_; + /** * \param char_ A char which the OFNumber should contain * \return A new autoreleased OFNumber */ + numberWithChar: (char)char_; @@ -224,10 +232,18 @@ * \param double_ A double which the OFNumber should contain * \return A new autoreleased OFNumber */ + numberWithDouble: (double)double_; +/** + * Initializes an already allocated OFNumber with the specified BOOL. + * + * \param bool_ A BOOL which the OFNumber should contain + * \return An initialized OFNumber + */ +- initWithBool: (BOOL)bool_; + /** * Initializes an already allocated OFNumber with the specified char. * * \param char_ A char which the OFNumber should contain * \return An initialized OFNumber @@ -430,10 +446,15 @@ * \return An enum of type of_number_type indicating the type of contained * number of the OFNumber */ - (enum of_number_type)type; +/** + * \return The OFNumber as a BOOL + */ +- (BOOL)boolValue; + /** * \return The OFNumber as a char */ - (char)charValue; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -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) }