00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPObjJRuntime.j"
00025
00026
00027 var __placeholder = new Number(),
00028 _CPNumberHashes = { };
00029
00040 @implementation CPNumber : CPObject
00041
00042 + (id)alloc
00043 {
00044 return __placeholder;
00045 }
00046
00047 + (id)numberWithBool:(BOOL)aBoolean
00048 {
00049 return aBoolean;
00050 }
00051
00052 + (id)numberWithChar:(char)aChar
00053 {
00054 if (aChar.charCodeAt)
00055 return aChar.charCodeAt(0);
00056
00057 return aChar;
00058 }
00059
00060 + (id)numberWithDouble:(double)aDouble
00061 {
00062 return aDouble;
00063 }
00064
00065 + (id)numberWithFloat:(float)aFloat
00066 {
00067 return aFloat;
00068 }
00069
00070 + (id)numberWithInt:(int)anInt
00071 {
00072 return anInt;
00073 }
00074
00075 + (id)numberWithLong:(long)aLong
00076 {
00077 return aLong;
00078 }
00079
00080 + (id)numberWithLongLong:(long long)aLongLong
00081 {
00082 return aLongLong;
00083 }
00084
00085 + (id)numberWithShort:(short)aShort
00086 {
00087 return aShort;
00088 }
00089
00090 + (id)numberWithUnsignedChar:(unsigned char)aChar
00091 {
00092 if (aChar.charCodeAt)
00093 return aChar.charCodeAt(0);
00094
00095 return aChar;
00096 }
00097
00098 + (id)numberWithUnsignedInt:(unsigned)anUnsignedInt
00099 {
00100 return anUnsignedInt;
00101 }
00102
00103 + (id)numberWithUnsignedLong:(unsigned long)anUnsignedLong
00104 {
00105 return anUnsignedLong;
00106 }
00107
00108
00109
00110
00111
00112
00113 + (id)numberWithUnsignedShort:(unsigned short)anUnsignedShort
00114 {
00115 return anUnsignedShort;
00116 }
00117
00118 - (id)initWithBool:(BOOL)aBoolean
00119 {
00120 return aBoolean;
00121 }
00122
00123 - (id)initWithChar:(char)aChar
00124 {
00125 if (aChar.charCodeAt)
00126 return aChar.charCodeAt(0);
00127
00128 return aChar;
00129 }
00130
00131 - (id)initWithDouble:(double)aDouble
00132 {
00133 return aDouble;
00134 }
00135
00136 - (id)initWithFloat:(float)aFloat
00137 {
00138 return aFloat;
00139 }
00140
00141 - (id)initWithInt:(int)anInt
00142 {
00143 return anInt;
00144 }
00145
00146 - (id)initWithLong:(long)aLong
00147 {
00148 return aLong;
00149 }
00150
00151 - (id)initWithLongLong:(long long)aLongLong
00152 {
00153 return aLongLong;
00154 }
00155
00156 - (id)initWithShort:(short)aShort
00157 {
00158 return aShort;
00159 }
00160
00161 - (id)initWithUnsignedChar:(unsigned char)aChar
00162 {
00163 if (aChar.charCodeAt)
00164 return aChar.charCodeAt(0);
00165
00166 return aChar;
00167 }
00168
00169 - (id)initWithUnsignedInt:(unsigned)anUnsignedInt
00170 {
00171 return anUnsignedInt;
00172 }
00173
00174 - (id)initWithUnsignedLong:(unsigned long)anUnsignedLong
00175 {
00176 return anUnsignedLong;
00177 }
00178
00179
00180
00181
00182
00183
00184 - (id)initWithUnsignedShort:(unsigned short)anUnsignedShort
00185 {
00186 return anUnsignedShort;
00187 }
00188
00189 - (CPString)hash
00190 {
00191 if (!_CPNumberHashes[self])
00192 _CPNumberHashes[self] = _objj_generateObjectHash();
00193
00194 return _CPNumberHashes[self];
00195 }
00196
00197 - (BOOL)boolValue
00198 {
00199
00200 return self ? true : false;
00201 }
00202
00203 - (char)charValue
00204 {
00205 return String.fromCharCode(self);
00206 }
00207
00208
00209
00210
00211 - (CPDecimal)decimalValue
00212 {
00213 objj_throw_exception("decimalValue: NOT YET IMPLEMENTED");
00214 }
00215
00216 - (CPString)descriptionWithLocale:(CPDictionary)aDictionary
00217 {
00218 if (!aDictionary) return toString();
00219
00220 objj_throw_exception("descriptionWithLocale: NOT YET IMPLEMENTED");
00221 }
00222
00223 - (CPString)description
00224 {
00225 return [self descriptionWithLocale:nil];
00226 }
00227
00228 - (double)doubleValue
00229 {
00230 if (typeof self == "boolean") return self ? 1 : 0;
00231 return self;
00232 }
00233
00234 - (float)floatValue
00235 {
00236 if (typeof self == "boolean") return self ? 1 : 0;
00237 return self;
00238 }
00239
00240 - (int)intValue
00241 {
00242 if (typeof self == "boolean") return self ? 1 : 0;
00243 return self;
00244 }
00245
00246 - (long long)longLongValue
00247 {
00248 if (typeof self == "boolean") return self ? 1 : 0;
00249 return self;
00250 }
00251
00252 - (long)longValue
00253 {
00254 if (typeof self == "boolean") return self ? 1 : 0;
00255 return self;
00256 }
00257
00258 - (short)shortValue
00259 {
00260 if (typeof self == "boolean") return self ? 1 : 0;
00261 return self;
00262 }
00263
00264 - (CPString)stringValue
00265 {
00266 return toString();
00267 }
00268
00269 - (unsigned char)unsignedCharValue
00270 {
00271 return String.fromCharCode(self);
00272 }
00273
00274 - (unsigned int)unsignedIntValue
00275 {
00276 if (typeof self == "boolean") return self ? 1 : 0;
00277 return self;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286 - (unsigned long)unsignedLongValue
00287 {
00288 if (typeof self == "boolean") return self ? 1 : 0;
00289 return self;
00290 }
00291
00292 - (unsigned short)unsignedShortValue
00293 {
00294 if (typeof self == "boolean") return self ? 1 : 0;
00295 return self;
00296 }
00297
00298 - (CPComparisonResult)compare:(CPNumber)aNumber
00299 {
00300 if (self > aNumber) return CPOrderedDescending;
00301 else if (self < aNumber) return CPOrderedAscending;
00302
00303 return CPOrderedSame;
00304 }
00305
00306 - (BOOL)isEqualToNumber:(CPNumber)aNumber
00307 {
00308 return self == aNumber;
00309 }
00310
00311 @end
00312
00313 @implementation CPNumber (CPCoding)
00314
00315 - (id)initWithCoder:(CPCoder)aCoder
00316 {
00317 return [aCoder decodeNumber];
00318 }
00319
00320 - (void)encodeWithCoder:(CPCoder)aCoder
00321 {
00322 [aCoder encodeNumber:self forKey:@"self"];
00323 }
00324
00325 @end
00326
00327 Number.prototype.isa = CPNumber;
00328 Boolean.prototype.isa = CPNumber;
00329 [CPNumber initialize];