00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00063 @implementation CPObject
00064 {
00065 Class isa;
00066 }
00067
00068 + (void)load
00069 {
00070 }
00071
00072 + (void)initialize
00073 {
00074
00075 }
00076
00081 + (id)new
00082 {
00083 return [[self alloc] init];
00084 }
00085
00089 + (id)alloc
00090 {
00091
00092 return class_createInstance(self);
00093 }
00094
00095 + (id)allocWithCoder:(CPCoder)aCoder
00096 {
00097 return [self alloc];
00098 }
00099
00104 - (id)init
00105 {
00106 return self;
00107 }
00108
00113 - (id)copy
00114 {
00115 return self;
00116 }
00117
00122 - (id)mutableCopy
00123 {
00124 return [self copy];
00125 }
00126
00130 - (void)dealloc
00131 {
00132 }
00133
00134
00138 + (Class)class
00139 {
00140 return self;
00141 }
00142
00146 - (Class)class
00147 {
00148 return isa;
00149 }
00150
00154 + (Class)superclass
00155 {
00156 return super_class;
00157 }
00158
00163 + (BOOL)isSubclassOfClass:(Class)aClass
00164 {
00165 var theClass = self;
00166
00167 for(; theClass; theClass = theClass.super_class)
00168 if(theClass === aClass)
00169 return YES;
00170
00171 return NO;
00172 }
00173
00178 - (BOOL)isKindOfClass:(Class)aClass
00179 {
00180 return [isa isSubclassOfClass:aClass];
00181 }
00182
00183 + (BOOL)isKindOfClass:(Class)aClass
00184 {
00185 return [self isSubclassOfClass:aClass];
00186 }
00187
00192 - (BOOL)isMemberOfClass:(Class)aClass
00193 {
00194 return self.isa === aClass;
00195 }
00196
00197 + (BOOL)isMemberOfClass:(Class)aClass
00198 {
00199 return self === aClass;
00200 }
00201
00206 - (BOOL)isProxy
00207 {
00208 return NO;
00209 }
00210
00211
00217 + (BOOL)instancesRespondToSelector:(SEL)aSelector
00218 {
00219 return !!class_getInstanceMethod(self, aSelector);
00220 }
00221
00227 - (BOOL)respondsToSelector:(SEL)aSelector
00228 {
00229 return !!class_getInstanceMethod(isa, aSelector);
00230 }
00231
00232
00233
00239 - (IMP)methodForSelector:(SEL)aSelector
00240 {
00241 return class_getMethodImplementation(isa, aSelector);
00242 }
00243
00249 + (IMP)instanceMethodForSelector:(SEL)aSelector
00250 {
00251 return class_getMethodImplementation(self, aSelector);
00252 }
00253
00259 - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector
00260 {
00261
00262 return nil;
00263 }
00264
00265
00269 - (CPString)description
00270 {
00271 return "<" + isa.name + " 0x" + [CPString stringWithHash:[self hash]] + ">";
00272 }
00273
00274
00280 - (id)performSelector:(SEL)aSelector
00281 {
00282 return objj_msgSend(self, aSelector);
00283 }
00284
00291 - (id)performSelector:(SEL)aSelector withObject:(id)anObject
00292 {
00293 return objj_msgSend(self, aSelector, anObject);
00294 }
00295
00303 - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
00304 {
00305 return objj_msgSend(self, aSelector, anObject, anotherObject);
00306 }
00307
00308
00315 - (void)forwardInvocation:(CPInvocation)anInvocation
00316 {
00317 [self doesNotRecognizeSelector:[anInvocation selector]];
00318 }
00319
00324 - (void)forward:(SEL)aSelector :(marg_list)args
00325 {
00326 var signature = [self methodSignatureForSelector:aSelector];
00327
00328 if (signature)
00329 {
00330 invocation = [CPInvocation invocationWithMethodSignature:signature];
00331
00332 [invocation setTarget:self];
00333 [invocation setSelector:aSelector];
00334
00335 var index = 2,
00336 count = args.length;
00337
00338 for (; index < count; ++index)
00339 [invocation setArgument:args[index] atIndex:index];
00340
00341 [self forwardInvocation:invocation];
00342
00343 return [invocation returnValue];
00344 }
00345
00346 [self doesNotRecognizeSelector:aSelector];
00347 }
00348
00349
00355 - (void)doesNotRecognizeSelector:(SEL)aSelector
00356 {
00357 [CPException raise:CPInvalidArgumentException reason:
00358 (class_isMetaClass(isa) ? "+" : "-") + " [" + [self className] + " " + aSelector + "] unrecognized selector sent to " +
00359 (class_isMetaClass(isa) ? "class" : "instance") + " 0x" + [CPString stringWithHash:[self hash]]];
00360 }
00361
00362
00371 - (id)awakeAfterUsingCoder:(CPCoder)aCoder
00372 {
00373 return self;
00374 }
00375
00380 - (Class)classForKeyedArchiver
00381 {
00382 return [self classForCoder];
00383 }
00384
00389 - (Class)classForCoder
00390 {
00391 return [self class];
00392 }
00393
00399 - (id)replacementObjectForArchiver:(CPArchiver)anArchiver
00400 {
00401 return [self replacementObjectForCoder:anArchiver];
00402 }
00403
00409 - (id)replacementObjectForKeyedArchiver:(CPKeyedArchiver)anArchiver
00410 {
00411 return [self replacementObjectForCoder:anArchiver];
00412 }
00413
00419 - (id)replacementObjectForCoder:(CPCoder)aCoder
00420 {
00421 return self;
00422 }
00423
00428 + (id)setVersion:(int)aVersion
00429 {
00430 version = aVersion;
00431
00432 return self;
00433 }
00434
00438 + (int)version
00439 {
00440 return version;
00441 }
00442
00443
00447 - (CPString)className
00448 {
00449 return isa.name;
00450 }
00451
00452
00457 - (id)autorelease
00458 {
00459 return self;
00460 }
00461
00465 - (unsigned)hash
00466 {
00467 return [self UID];
00468 }
00469
00470 - (unsigned)UID
00471 {
00472 if (typeof self.__address === "undefined")
00473 self.__address = _objj_generateObjectHash();
00474
00475 return __address;
00476 }
00477
00482 - (BOOL)isEqual:(id)anObject
00483 {
00484 return self === anObject || [self hash] === [anObject hash];
00485 }
00486
00491 - (id)retain
00492 {
00493 return self;
00494 }
00495
00499 - (void)release
00500 {
00501 }
00502
00506 - (id)self
00507 {
00508 return self;
00509 }
00510
00514 - (Class)superclass
00515 {
00516 return isa.super_class;
00517 }
00518
00519 @end
00520
00521
00522
00523 objj_object.prototype.toString = function()
00524 {
00525 if (this.isa && class_getInstanceMethod(this.isa, "description") != NULL)
00526 return [this description]
00527 else
00528 return String(this) + " (-description not implemented)";
00529 }