00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00064 @implementation CPObject
00065 {
00066 Class isa;
00067 }
00068
00069 + (void)load
00070 {
00071 }
00072
00073 + (void)initialize
00074 {
00075
00076 }
00077
00082 + (id)new
00083 {
00084 return [[self alloc] init];
00085 }
00086
00090 + (id)alloc
00091 {
00092
00093 return class_createInstance(self);
00094 }
00095
00096 + (id)allocWithCoder:(CPCoder)aCoder
00097 {
00098 return [self alloc];
00099 }
00100
00105 - (id)init
00106 {
00107 return self;
00108 }
00109
00114 - (id)copy
00115 {
00116 return self;
00117 }
00118
00123 - (id)mutableCopy
00124 {
00125 return [self copy];
00126 }
00127
00131 - (void)dealloc
00132 {
00133 }
00134
00135
00139 + (Class)class
00140 {
00141 return self;
00142 }
00143
00147 - (Class)class
00148 {
00149 return isa;
00150 }
00151
00155 + (Class)superclass
00156 {
00157 return super_class;
00158 }
00159
00164 + (BOOL)isSubclassOfClass:(Class)aClass
00165 {
00166 var theClass = self;
00167
00168 for(; theClass; theClass = theClass.super_class)
00169 if(theClass === aClass)
00170 return YES;
00171
00172 return NO;
00173 }
00174
00179 - (BOOL)isKindOfClass:(Class)aClass
00180 {
00181 return [isa isSubclassOfClass:aClass];
00182 }
00183
00184 + (BOOL)isKindOfClass:(Class)aClass
00185 {
00186 return [self isSubclassOfClass:aClass];
00187 }
00188
00193 - (BOOL)isMemberOfClass:(Class)aClass
00194 {
00195 return self.isa === aClass;
00196 }
00197
00198 + (BOOL)isMemberOfClass:(Class)aClass
00199 {
00200 return self === aClass;
00201 }
00202
00207 - (BOOL)isProxy
00208 {
00209 return NO;
00210 }
00211
00212
00218 + (BOOL)instancesRespondToSelector:(SEL)aSelector
00219 {
00220 return !!class_getInstanceMethod(self, aSelector);
00221 }
00222
00228 - (BOOL)respondsToSelector:(SEL)aSelector
00229 {
00230
00231 return !!class_getInstanceMethod(isa, aSelector);
00232 }
00233
00234
00235
00241 - (IMP)methodForSelector:(SEL)aSelector
00242 {
00243 return class_getMethodImplementation(isa, aSelector);
00244 }
00245
00251 + (IMP)instanceMethodForSelector:(SEL)aSelector
00252 {
00253 return class_getMethodImplementation(self, aSelector);
00254 }
00255
00261 - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector
00262 {
00263
00264 return nil;
00265 }
00266
00267
00271 - (CPString)description
00272 {
00273 return "<" + class_getName(isa) + " 0x" + [CPString stringWithHash:[self UID]] + ">";
00274 }
00275
00276 + (CPString)description
00277 {
00278 return class_getName(isa);
00279 }
00280
00281
00287 - (id)performSelector:(SEL)aSelector
00288 {
00289 return objj_msgSend(self, aSelector);
00290 }
00291
00298 - (id)performSelector:(SEL)aSelector withObject:(id)anObject
00299 {
00300 return objj_msgSend(self, aSelector, anObject);
00301 }
00302
00310 - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
00311 {
00312 return objj_msgSend(self, aSelector, anObject, anotherObject);
00313 }
00314
00315
00322 - (void)forwardInvocation:(CPInvocation)anInvocation
00323 {
00324 [self doesNotRecognizeSelector:[anInvocation selector]];
00325 }
00326
00331
00332 - (void)forward:(SEL)aSelector :(marg_list)args
00333 {
00334 var signature = [self methodSignatureForSelector:aSelector];
00335
00336 if (signature)
00337 {
00338 invocation = [CPInvocation invocationWithMethodSignature:signature];
00339
00340 [invocation setTarget:self];
00341 [invocation setSelector:aSelector];
00342
00343 var index = 2,
00344 count = args.length;
00345
00346 for (; index < count; ++index)
00347 [invocation setArgument:args[index] atIndex:index];
00348
00349 [self forwardInvocation:invocation];
00350
00351 return [invocation returnValue];
00352 }
00353
00354 [self doesNotRecognizeSelector:aSelector];
00355 }
00356
00357
00363 - (void)doesNotRecognizeSelector:(SEL)aSelector
00364 {
00365 [CPException raise:CPInvalidArgumentException reason:
00366 (class_isMetaClass(isa) ? "+" : "-") + " [" + [self className] + " " + aSelector + "] unrecognized selector sent to " +
00367 (class_isMetaClass(isa) ? "class" : "instance") + " 0x" + [CPString stringWithHash:[self UID]]];
00368 }
00369
00370
00379 - (id)awakeAfterUsingCoder:(CPCoder)aCoder
00380 {
00381 return self;
00382 }
00383
00388 - (Class)classForKeyedArchiver
00389 {
00390 return [self classForCoder];
00391 }
00392
00397 - (Class)classForCoder
00398 {
00399 return [self class];
00400 }
00401
00407 - (id)replacementObjectForArchiver:(CPArchiver)anArchiver
00408 {
00409 return [self replacementObjectForCoder:anArchiver];
00410 }
00411
00417 - (id)replacementObjectForKeyedArchiver:(CPKeyedArchiver)anArchiver
00418 {
00419 return [self replacementObjectForCoder:anArchiver];
00420 }
00421
00427 - (id)replacementObjectForCoder:(CPCoder)aCoder
00428 {
00429 return self;
00430 }
00431
00436 + (id)setVersion:(int)aVersion
00437 {
00438 version = aVersion;
00439
00440 return self;
00441 }
00442
00446 + (int)version
00447 {
00448 return version;
00449 }
00450
00451
00455 - (CPString)className
00456 {
00457 return isa.name;
00458 }
00459
00460
00465 - (id)autorelease
00466 {
00467 return self;
00468 }
00469
00473 - (unsigned)hash
00474 {
00475 return [self UID];
00476 }
00477
00478 - (CPString)UID
00479 {
00480 if (typeof self._UID === "undefined")
00481 self._UID = objj_generateObjectUID();
00482
00483 return _UID + "";
00484 }
00485
00490 - (BOOL)isEqual:(id)anObject
00491 {
00492 return self === anObject || [self UID] === [anObject UID];
00493 }
00494
00499 - (id)retain
00500 {
00501 return self;
00502 }
00503
00507 - (void)release
00508 {
00509 }
00510
00514 - (id)self
00515 {
00516 return self;
00517 }
00518
00522 - (Class)superclass
00523 {
00524 return isa.super_class;
00525 }
00526
00527 @end
00528
00529
00530
00531 objj_class.prototype.toString = objj_object.prototype.toString = function()
00532 {
00533 if (this.isa && class_getInstanceMethod(this.isa, "description") != NULL)
00534 return [this description]
00535 else
00536 return String(this) + " (-description not implemented)";
00537 }