/** Implementation of NSProtocolChecker for GNUStep Copyright (C) 1995 Free Software Foundation, Inc. Original by: Mike Kienenberger Date: Jun 1998 Written: Richard Frith-Macdonald Date: April 2004 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 Lesser 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
NSProtocolChecker
instance with the protocol and the object as
* arguments-
NSInvalidArgumentException
.
*/
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
const char *type;
if ([self _protocolTypeForSelector: [anInvocation selector]] == NULL)
{
if (GSObjCIsInstance(_myTarget))
{
[NSException raise: NSInvalidArgumentException
format: @"<%s -%@> not declared",
protocol_getName(_myProtocol),
NSStringFromSelector([anInvocation selector])];
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"<%s +%@> not declared",
protocol_getName(_myProtocol),
NSStringFromSelector([anInvocation selector])];
}
}
[anInvocation invokeWithTarget: _myTarget];
/*
* If the method returns 'self' (ie the target object) replace the
* returned value with the protocol checker.
*/
type = [[anInvocation methodSignature] methodReturnType];
if (GSSelectorTypesMatch(type, @encode(id)))
{
id buf;
[anInvocation getReturnValue: &buf];
if (buf == _myTarget)
{
buf = self;
[anInvocation setReturnValue: &buf];
}
}
}
- (id) init
{
self = [self initWithTarget: nil protocol: nil];
return self;
}
/**
* Initializes a newly allocated NSProtocolChecker instance that will
* forward any messages in the aProtocol protocol to anObject, its
* delegate. Thus, the checker can be vended in lieu of anObject to
* restrict the messages that can be sent to anObject. If any method
* in the protocol returns anObject, the checker will replace the returned
* value with itself rather than the target object.