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