mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +00:00
Rewrite NSProtocolChecker stuff ... seemed largely broken
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19180 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d8012f989f
commit
96c253eee4
4 changed files with 52 additions and 70 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2004-04-25 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSProtocolChecker.m: Rewrite ... appeared almost totally
|
||||||
|
non-functional.
|
||||||
|
|
||||||
2004-04-23 David Ayers <d.ayers@inode.at>
|
2004-04-23 David Ayers <d.ayers@inode.at>
|
||||||
|
|
||||||
* Source/Additions/GSLock.m ([GSLazyLock -init])
|
* Source/Additions/GSLock.m ([GSLazyLock -init])
|
||||||
|
|
|
@ -38,12 +38,13 @@
|
||||||
|
|
||||||
+ (id) protocolCheckerWithTarget: (NSObject*)anObject
|
+ (id) protocolCheckerWithTarget: (NSObject*)anObject
|
||||||
protocol: (Protocol*)aProtocol;
|
protocol: (Protocol*)aProtocol;
|
||||||
- (id) initWithTarget: (NSObject *)anObject protocol: (Protocol *)aProtocol;
|
|
||||||
|
- (id) initWithTarget: (NSObject*)anObject
|
||||||
|
protocol: (Protocol*)aProtocol;
|
||||||
|
|
||||||
// Reimplemented NSObject methods
|
// Reimplemented NSObject methods
|
||||||
|
|
||||||
- (void) forwardInvocation: (NSInvocation*)anInvocation;
|
- (void) forwardInvocation: (NSInvocation*)anInvocation;
|
||||||
- (struct objc_method_description *) methodDescriptionForSelector: (SEL)aSelector;
|
|
||||||
|
|
||||||
// Getting information
|
// Getting information
|
||||||
- (Protocol*) protocol;
|
- (Protocol*) protocol;
|
||||||
|
|
|
@ -564,7 +564,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is consitent with MacOSX - just return NO for an invalid path. */
|
/* This is consitent with MacOSX - just return NO for an invalid path. */
|
||||||
if (path == nil)
|
if ([path length] == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
|
@ -719,7 +719,7 @@ static NSFileManager* defaultManager = nil;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is consitent with MacOSX - just return NO for an invalid path. */
|
/* This is consitent with MacOSX - just return NO for an invalid path. */
|
||||||
if (path == nil)
|
if ([path length] == 0)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
#if defined(__MINGW__)
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
Written by: Mike Kienenberger
|
Written by: Mike Kienenberger
|
||||||
Date: Jun 1998
|
Date: Jun 1998
|
||||||
|
Rewrite: Richard Frith-Macdonald
|
||||||
|
Date: April 2004
|
||||||
|
|
||||||
This file is part of the GNUstep Base Library.
|
This file is part of the GNUstep Base Library.
|
||||||
|
|
||||||
|
@ -33,14 +35,13 @@
|
||||||
|
|
||||||
@implementation NSProtocolChecker
|
@implementation NSProtocolChecker
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Allocates and initializes an NSProtocolChecker instance that will
|
* Allocates and initializes an NSProtocolChecker instance that will
|
||||||
* forward any messages in the aProtocol protocol to anObject, its
|
* forward any messages in the aProtocol protocol to anObject, its
|
||||||
* target. Thus, the checker can be vended in lieu of anObject to
|
* target. Thus, the checker can be vended in lieu of anObject to
|
||||||
* restrict the messages that can be sent to anObject. Returns the
|
* restrict the messages that can be sent to anObject. Returns the
|
||||||
* new instance.
|
* new instance.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+ (id) protocolCheckerWithTarget: (NSObject*)anObject
|
+ (id) protocolCheckerWithTarget: (NSObject*)anObject
|
||||||
protocol: (Protocol*)aProtocol
|
protocol: (Protocol*)aProtocol
|
||||||
{
|
{
|
||||||
|
@ -48,51 +49,42 @@
|
||||||
protocol: aProtocol]);
|
protocol: aProtocol]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
DESTROY(_myTarget);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Forwards any message to the delegate if the method is declared in
|
* Forwards any message to the delegate if the method is declared in
|
||||||
* the checker's protocol; otherwise raises an NSInvalidArgumentException.
|
* the checker's protocol; otherwise raises an NSInvalidArgumentException.
|
||||||
*/
|
*/
|
||||||
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
||||||
{
|
{
|
||||||
unsigned int length;
|
if (GSObjCIsInstance(_myTarget)
|
||||||
void *buffer;
|
&& ![_myProtocol descriptionForInstanceMethod: [anInvocation selector]])
|
||||||
|
{
|
||||||
if ((struct objc_method_description *)NULL
|
[NSException raise: NSInvalidArgumentException
|
||||||
!= [self methodDescriptionForSelector: [anInvocation selector]])
|
format: @"<%s -%@> not declared",
|
||||||
[[NSException exceptionWithName: NSInvalidArgumentException
|
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||||
reason: @"Method not declared in current protocol"
|
}
|
||||||
userInfo: nil] raise];
|
else if (![_myProtocol descriptionForClassMethod: [anInvocation selector]])
|
||||||
|
{
|
||||||
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"<%s +%@> not declared",
|
||||||
|
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||||
|
}
|
||||||
|
|
||||||
[anInvocation invokeWithTarget: _myTarget];
|
[anInvocation invokeWithTarget: _myTarget];
|
||||||
|
|
||||||
length = [[anInvocation methodSignature] methodReturnLength];
|
|
||||||
buffer = (void *)malloc(length);
|
|
||||||
[anInvocation getReturnValue: buffer];
|
|
||||||
|
|
||||||
if (0 == strcmp([[anInvocation methodSignature] methodReturnType],
|
|
||||||
[[anInvocation methodSignatureForSelector:
|
|
||||||
@selector(init: )] methodReturnType]) )
|
|
||||||
{
|
|
||||||
if (((id)buffer) == _myTarget)
|
|
||||||
{
|
|
||||||
buffer = self;
|
|
||||||
[anInvocation setReturnValue: buffer];
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
_myProtocol = nil;
|
self = [self initWithTarget: nil protocol: nil];
|
||||||
_myTarget = nil;
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Initializes a newly allocated NSProtocolChecker instance that will
|
* Initializes a newly allocated NSProtocolChecker instance that will
|
||||||
* forward any messages in the aProtocol protocol to anObject, its
|
* forward any messages in the aProtocol protocol to anObject, its
|
||||||
* delegate. Thus, the checker can be vended in lieu of anObject to
|
* delegate. Thus, the checker can be vended in lieu of anObject to
|
||||||
|
@ -102,41 +94,25 @@
|
||||||
*/
|
*/
|
||||||
- (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol
|
- (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol
|
||||||
{
|
{
|
||||||
[super init];
|
self = [super init];
|
||||||
|
if (self != nil)
|
||||||
|
{
|
||||||
_myProtocol = aProtocol;
|
_myProtocol = aProtocol;
|
||||||
|
|
||||||
ASSIGN(_myTarget, anObject);
|
ASSIGN(_myTarget, anObject);
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns an Objective C description for a method in the checker's
|
|
||||||
* protocol, or NULL if aSelector isn't declared as an instance method
|
|
||||||
* in the protocol.
|
|
||||||
*/
|
|
||||||
- (struct objc_method_description*) methodDescriptionForSelector: (SEL)aSelector
|
|
||||||
{
|
|
||||||
return [_myProtocol descriptionForInstanceMethod: aSelector];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns the protocol object the checker uses to verify whether a
|
* Returns the protocol object the checker uses to verify whether a
|
||||||
* given message should be forwarded to its delegate, or the protocol
|
* given message should be forwarded to its delegate.
|
||||||
* checker should raise an NSInvalidArgumentException.
|
|
||||||
*/
|
*/
|
||||||
- (Protocol*) protocol
|
- (Protocol*) protocol
|
||||||
{
|
{
|
||||||
if (nil == _myProtocol)
|
|
||||||
[[NSException exceptionWithName: NSInvalidArgumentException
|
|
||||||
reason: @"No protocol specified"
|
|
||||||
userInfo: nil] raise];
|
|
||||||
|
|
||||||
return _myProtocol;
|
return _myProtocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Returns the target of the NSProtocolChecker.
|
* Returns the target of the NSProtocolChecker.
|
||||||
*/
|
*/
|
||||||
- (NSObject*) target
|
- (NSObject*) target
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue