2001-12-17 14:31:42 +00:00
|
|
|
/** Implementation for GNU Objective-C version of NSProxy
|
1997-09-01 21:59:51 +00:00
|
|
|
Copyright (C) 1997 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
Created: August 1997
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSProxy class reference</title>
|
|
|
|
$Date$ $Revision$
|
1997-09-01 21:59:51 +00:00
|
|
|
*/
|
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
2001-05-31 22:39:16 +00:00
|
|
|
#include <base/preface.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
#include <Foundation/NSInvocation.h>
|
|
|
|
#include <Foundation/NSProxy.h>
|
|
|
|
#include <Foundation/NSMethodSignature.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSException.h>
|
2000-10-31 16:17:33 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1997-10-30 19:37:24 +00:00
|
|
|
#include "limits.h"
|
1997-09-01 21:59:51 +00:00
|
|
|
|
2001-08-03 20:43:40 +00:00
|
|
|
#ifndef NeXT_RUNTIME
|
2001-05-12 06:25:46 +00:00
|
|
|
extern BOOL __objc_responds_to(id, SEL);
|
2001-08-03 20:43:40 +00:00
|
|
|
#endif
|
1997-09-01 21:59:51 +00:00
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* The NSProxy class provides a basic implementation of a class whose
|
|
|
|
* instances are used to <em>stand in</em> for other objects.<br />
|
|
|
|
* The class provides the most basic methods of NSObject, and expects
|
|
|
|
* messages for other methods to be forwarded to the <em>real</em>
|
|
|
|
* object represented by the proxy. You must subclass NSProxy to
|
|
|
|
* implement -forwardInvocation: to these <em>real</em> objects.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
@implementation NSProxy
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns an NSProxy instance in the default zone.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (id) alloc
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return [self allocWithZone: NSDefaultMallocZone()];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Allocates and returns an NSProxy instance in the specified zone z.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
NSProxy* ob = (NSProxy*) NSAllocateObject(self, 0, z);
|
|
|
|
return ob;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the receiver
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
+ (id) autorelease
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the receiver
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (Class) class
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns a string describing the receiver.
|
|
|
|
*/
|
2001-05-12 06:25:46 +00:00
|
|
|
+ (NSString*) description
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
return [NSString stringWithFormat: @"<%s>", object_get_class_name(self)];
|
1998-12-18 17:05:44 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns NO ... the NSProxy class cannot be an instance of any class.
|
|
|
|
*/
|
|
|
|
+ (BOOL) isKindOfClass: (Class)aClass
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns YES if aClass is identical to the receiver, NO otherwise.
|
|
|
|
*/
|
|
|
|
+ (BOOL) isMemberOfClass: (Class)aClass
|
|
|
|
{
|
|
|
|
return(self == aClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A dummy method ...
|
|
|
|
*/
|
2001-05-12 06:25:46 +00:00
|
|
|
+ (void) load
|
1998-12-18 17:05:44 +00:00
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
/* Do nothing */
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the method signature for the specified selector.
|
|
|
|
*/
|
2001-05-12 06:25:46 +00:00
|
|
|
+ (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
struct objc_method *mth;
|
|
|
|
|
|
|
|
if (aSelector == 0)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
mth = class_get_class_method(GSObjCClass(self), aSelector);
|
|
|
|
if (mth != 0)
|
|
|
|
{
|
|
|
|
const char *types = mth->method_types;
|
|
|
|
|
|
|
|
if (types != 0)
|
|
|
|
{
|
|
|
|
return [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* A dummy method to ensure that the class can safely be held in containers.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (void) release
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
/* Do nothing */
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns YES if the receiver responds to aSelector, NO otherwise.
|
|
|
|
*/
|
2001-05-12 06:25:46 +00:00
|
|
|
+ (BOOL) respondsToSelector: (SEL)aSelector
|
|
|
|
{
|
|
|
|
if (__objc_responds_to(self, aSelector))
|
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the receiver.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
+ (id) retain
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the maximum unsigned integer value.
|
|
|
|
*/
|
|
|
|
+ (unsigned int) retainCount
|
|
|
|
{
|
|
|
|
return UINT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the superclass of the receiver
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
+ (Class) superclass
|
|
|
|
{
|
|
|
|
return class_get_super_class (self);
|
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Adds the receiver to the current autorelease pool and returns self.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) autorelease
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2000-10-24 11:58:25 +00:00
|
|
|
#if GS_WITH_GC == 0
|
|
|
|
[NSAutoreleasePool addObject: self];
|
|
|
|
#endif
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the class of the receiver.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (Class) class
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return object_get_class(self);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Calls the -forwardInvocation: method to determine if the 'real' object
|
|
|
|
* referred to by the proxy conforms to aProtocol. Returns the result.<br />
|
|
|
|
* NB. The default operation of -forwardInvocation: is to raise an exception.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) conformsToProtocol: (Protocol*)aProtocol
|
|
|
|
{
|
2002-08-19 10:26:07 +00:00
|
|
|
NSMethodSignature *sig;
|
|
|
|
NSInvocation *inv;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
sig = [self methodSignatureForSelector: _cmd];
|
|
|
|
inv = [NSInvocation invocationWithMethodSignature: sig];
|
|
|
|
[inv setSelector: _cmd];
|
|
|
|
[inv setArgument: &aProtocol atIndex: 2];
|
|
|
|
[self forwardInvocation: inv];
|
|
|
|
[inv getReturnValue: &ret];
|
|
|
|
return ret;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Frees the memory used by the receiver.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
NSDeallocateObject((NSObject*)self);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns a text descrioption of the receiver.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (NSString*) description
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return [NSString stringWithFormat: @"<%s %lx>",
|
|
|
|
object_get_class_name(self), (unsigned long)self];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Calls the -forwardInvocation: method and returns the result.
|
|
|
|
*/
|
2000-10-24 11:58:25 +00:00
|
|
|
- (retval_t) forward:(SEL)aSel :(arglist_t)argFrame
|
|
|
|
{
|
|
|
|
NSInvocation *inv;
|
|
|
|
|
|
|
|
inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame
|
2001-05-12 06:25:46 +00:00
|
|
|
selector: aSel]);
|
|
|
|
[self forwardInvocation: inv];
|
2000-10-24 11:58:25 +00:00
|
|
|
return [inv returnFrame: argFrame];
|
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/** <override-subclass />
|
|
|
|
* Raises an NSInvalidArgumentException
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"NSProxy should not implement '%s'",
|
1997-09-01 21:59:51 +00:00
|
|
|
sel_get_name(_cmd)];
|
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the address of the receiver ... so it can be stored in a dictionary.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (unsigned int) hash
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return (unsigned int)self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/** <init /> <override-subclass />
|
|
|
|
* Initialises the receiver and returns the resulting instance.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) init
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"subclass %s should override %s", object_get_class_name(self),
|
|
|
|
sel_get_name(_cmd)];
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Tests for pointer equality with anObject
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (BOOL) isEqual: (id)anObject
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return (self == anObject);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Calls the -forwardInvocation: method to determine if the 'real' object
|
|
|
|
* referred to by the proxy is an instance of the specified class.
|
|
|
|
* Returns the result.<br />
|
|
|
|
* NB. The default operation of -forwardInvocation: is to raise an exception.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) isKindOfClass: (Class)aClass
|
|
|
|
{
|
2002-08-19 10:26:07 +00:00
|
|
|
NSMethodSignature *sig;
|
|
|
|
NSInvocation *inv;
|
|
|
|
BOOL ret;
|
1997-09-01 21:59:51 +00:00
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
sig = [self methodSignatureForSelector: _cmd];
|
|
|
|
inv = [NSInvocation invocationWithMethodSignature: sig];
|
|
|
|
[inv setSelector: _cmd];
|
|
|
|
[inv setArgument: &aClass atIndex: 2];
|
|
|
|
[self forwardInvocation: inv];
|
|
|
|
[inv getReturnValue: &ret];
|
|
|
|
return ret;
|
1999-07-28 15:04:40 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Calls the -forwardInvocation: method to determine if the 'real' object
|
|
|
|
* referred to by the proxy is an instance of the specified class.
|
|
|
|
* Returns the result.<br />
|
|
|
|
* NB. The default operation of -forwardInvocation: is to raise an exception.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) isMemberOfClass: (Class)aClass
|
|
|
|
{
|
2002-08-19 10:26:07 +00:00
|
|
|
NSMethodSignature *sig;
|
|
|
|
NSInvocation *inv;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
sig = [self methodSignatureForSelector: _cmd];
|
|
|
|
inv = [NSInvocation invocationWithMethodSignature: sig];
|
|
|
|
[inv setSelector: _cmd];
|
|
|
|
[inv setArgument: &aClass atIndex: 2];
|
|
|
|
[self forwardInvocation: inv];
|
|
|
|
[inv getReturnValue: &ret];
|
|
|
|
return ret;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns YES
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) isProxy
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return YES;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) notImplemented: (SEL)aSel
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"NSProxy notImplemented %s", sel_get_name(aSel)];
|
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
2001-05-12 06:25:46 +00:00
|
|
|
* If we respond to the method directly, create and return a method
|
|
|
|
* signature. Otherwise raise an exception.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
struct objc_method *mth;
|
|
|
|
|
|
|
|
if (aSelector == 0)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
mth = class_get_instance_method(GSObjCClass(self), aSelector);
|
|
|
|
if (mth != 0)
|
|
|
|
{
|
|
|
|
const char *types = mth->method_types;
|
|
|
|
|
|
|
|
if (types != 0)
|
|
|
|
{
|
|
|
|
return [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
}
|
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException format:
|
2001-05-12 06:25:46 +00:00
|
|
|
@"NSProxy should not implement 'methodSignatureForSelector:'"];
|
1998-12-18 17:05:44 +00:00
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) performSelector: (SEL)aSelector
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
IMP msg = objc_msg_lookup(self, aSelector);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"invalid selector passed to %s",
|
1997-09-01 21:59:51 +00:00
|
|
|
sel_get_name(_cmd)];
|
1998-12-18 17:05:44 +00:00
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
return (*msg)(self, aSelector);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) performSelector: (SEL)aSelector
|
|
|
|
withObject: (id)anObject
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
IMP msg = objc_msg_lookup(self, aSelector);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"invalid selector passed to %s",
|
1997-09-01 21:59:51 +00:00
|
|
|
sel_get_name(_cmd)];
|
1998-12-18 17:05:44 +00:00
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
return (*msg)(self, aSelector, anObject);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) performSelector: (SEL)aSelector
|
|
|
|
withObject: (id)anObject
|
|
|
|
withObject: (id)anotherObject
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
IMP msg = objc_msg_lookup(self, aSelector);
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1998-12-18 17:05:44 +00:00
|
|
|
if (!msg)
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"invalid selector passed to %s",
|
1997-09-01 21:59:51 +00:00
|
|
|
sel_get_name(_cmd)];
|
1998-12-18 17:05:44 +00:00
|
|
|
return nil;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
1998-12-18 17:05:44 +00:00
|
|
|
return (*msg)(self, aSelector, anObject, anotherObject);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Decrement the retain count for the receiver ... deallocate if it would
|
|
|
|
* become negative.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (void) release
|
|
|
|
{
|
2000-10-24 11:58:25 +00:00
|
|
|
#if GS_WITH_GC == 0
|
2002-08-19 10:26:07 +00:00
|
|
|
if (_retain_count == 0)
|
1998-12-18 17:05:44 +00:00
|
|
|
{
|
|
|
|
[self dealloc];
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
2002-08-19 10:26:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_retain_count--;
|
|
|
|
}
|
2000-10-24 11:58:25 +00:00
|
|
|
#endif
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
2001-05-12 06:25:46 +00:00
|
|
|
* If we respond to the method directly, return YES, otherwise
|
|
|
|
* forward this request to the object we are acting as a proxy for.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (BOOL) respondsToSelector: (SEL)aSelector
|
|
|
|
{
|
2001-05-12 06:25:46 +00:00
|
|
|
if (aSelector == 0)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if (__objc_responds_to(self, aSelector))
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSMethodSignature *sig;
|
|
|
|
NSInvocation *inv;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
sig = [self methodSignatureForSelector: _cmd];
|
|
|
|
inv = [NSInvocation invocationWithMethodSignature: sig];
|
|
|
|
[inv setSelector: _cmd];
|
|
|
|
[inv setArgument: &aSelector atIndex: 2];
|
|
|
|
[self forwardInvocation: inv];
|
|
|
|
[inv getReturnValue: &ret];
|
|
|
|
return ret;
|
|
|
|
}
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Increment the retain count for the receiver.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) retain
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
2000-10-24 11:58:25 +00:00
|
|
|
#if GS_WITH_GC == 0
|
1998-12-18 17:05:44 +00:00
|
|
|
_retain_count++;
|
2000-10-24 11:58:25 +00:00
|
|
|
#endif
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Return the retain count for the receiver.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (unsigned int) retainCount
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return _retain_count + 1;
|
1997-10-28 14:34:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the receiver.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) self
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return self;
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the superclass of the receivers class.
|
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
- (Class) superclass
|
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return object_get_super_class(self);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 10:26:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the zone in which the receiver was allocated.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (NSZone*) zone
|
1997-09-01 21:59:51 +00:00
|
|
|
{
|
1998-12-18 17:05:44 +00:00
|
|
|
return NSZoneFromPointer(self);
|
1997-09-01 21:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|