mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Completed rewrite with some testing.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19181 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
96c253eee4
commit
0b2f72a36f
5 changed files with 63 additions and 22 deletions
|
@ -61,20 +61,24 @@
|
|||
*/
|
||||
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
||||
{
|
||||
if (GSObjCIsInstance(_myTarget)
|
||||
&& ![_myProtocol descriptionForInstanceMethod: [anInvocation selector]])
|
||||
if (GSObjCIsInstance(_myTarget))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"<%s -%@> not declared",
|
||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||
if (![_myProtocol descriptionForInstanceMethod: [anInvocation selector]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"<%s -%@> not declared",
|
||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||
}
|
||||
}
|
||||
else if (![_myProtocol descriptionForClassMethod: [anInvocation selector]])
|
||||
else
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"<%s +%@> not declared",
|
||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||
if (![_myProtocol descriptionForClassMethod: [anInvocation selector]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"<%s +%@> not declared",
|
||||
[_myProtocol name], NSStringFromSelector([anInvocation selector])];
|
||||
}
|
||||
}
|
||||
|
||||
[anInvocation invokeWithTarget: _myTarget];
|
||||
}
|
||||
|
||||
|
@ -94,15 +98,25 @@
|
|||
*/
|
||||
- (id) initWithTarget: (NSObject*)anObject protocol: (Protocol*)aProtocol
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
_myProtocol = aProtocol;
|
||||
ASSIGN(_myTarget, anObject);
|
||||
}
|
||||
_myProtocol = aProtocol;
|
||||
ASSIGN(_myTarget, anObject);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (IMP) methodForSelector: (SEL)aSelector
|
||||
{
|
||||
return get_imp(GSObjCClass((id)self), aSelector);
|
||||
}
|
||||
|
||||
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
||||
{
|
||||
if (aSelector == _cmd || [self respondsToSelector: aSelector] == YES)
|
||||
{
|
||||
return [_myTarget methodSignatureForSelector: aSelector];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol object the checker uses to verify whether a
|
||||
* given message should be forwarded to its delegate.
|
||||
|
@ -112,6 +126,25 @@
|
|||
return _myProtocol;
|
||||
}
|
||||
|
||||
- (BOOL) respondsToSelector: (SEL)aSelector
|
||||
{
|
||||
if (GSObjCIsInstance(_myTarget))
|
||||
{
|
||||
if ([_myProtocol descriptionForInstanceMethod: aSelector])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([_myProtocol descriptionForClassMethod: aSelector])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target of the NSProtocolChecker.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue