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