New class.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2811 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1998-06-16 13:52:57 +00:00
parent 1f47d54799
commit f8e6d9b280
6 changed files with 212 additions and 5 deletions

View file

@ -1,4 +1,9 @@
Fri May 29 10:16:09 1998 Adam Fedor <fedor@ultra.doc.com>
Tue Jun 16 09:48:18 1998 Adam Fedor <fedor@doc.com>
* src/NSProtocolChecker.m, src/include/NSProtocolChecker.h: New files.
(from Mike Kienenberger <mkienenb@arsc.edu>)
Fri May 29 10:16:09 1998 Adam Fedor <fedor@doc.com>
* doc/news.tmpl.texi: Fixed typo.
* doc/readme.tmpl.texi: Likewise. (patch from doko@cs.tu-berlin.de

View file

@ -0,0 +1,54 @@
/* Interface for NSMethodSignature for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: Mike Kienenberger
Date: Jun 1998
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
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE
#define __NSProtocolChecker_h_GNUSTEP_BASE_INCLUDE
#import <Foundation/NSObject.h>
@class Protocol;
@interface NSProtocolChecker : NSObject
{
Protocol *myProtocol;
NSObject *myTarget;
}
// Creating a checker
+ (id) protocolCheckerWithTarget: (NSObject *)anObject
protocol: (Protocol *)aProtocol;
- (id) initWithTarget: (NSObject *)anObject protocol: (Protocol *)aProtocol;
// Reimplemented NSObject methods
- (void)forwardInvocation: (NSInvocation *)anInvocation;
- (struct objc_method_description *) methodDescriptionForSelector: (SEL)aSelector;
// Getting information
- (Protocol *) protocol;
- (NSObject *) target;
@end
#endif

View file

@ -61,7 +61,8 @@ FILE_AUTHORS = \
"Luke Howard" \
"Yoo C. Chung" \
"Richard Frith-Macdonald" \
"Stevo Crvenkovski"
"Stevo Crvenkovski" \
"Mike Kienenberger"
# The GNU source files
@ -349,6 +350,7 @@ NSPipe.m \
NSPort.m \
NSPortCoder.m \
NSProcessInfo.m \
NSProtocolChecker.m \
NSProxy.m \
NSRange.m \
NSRunLoop.m \
@ -439,6 +441,7 @@ Foundation/NSPathUtilities.h \
Foundation/NSPort.h \
Foundation/NSPortCoder.h \
Foundation/NSProcessInfo.h \
Foundation/NSProtocolChecker.h \
Foundation/NSProxy.h \
Foundation/NSRange.h \
Foundation/NSRunLoop.h \

View file

@ -147,7 +147,7 @@ static BOOL debug_memory_stream = NO;
size: capacity
eofPosition: 0
prefix: p
position: i];
position: 0];
}
- initWithCapacity: (unsigned)capacity
@ -157,7 +157,7 @@ static BOOL debug_memory_stream = NO;
size: capacity
eofPosition: 0
prefix: 0
position: i];
position: 0];
}
- initWithData: (id)anObject

145
Source/NSProtocolChecker.m Normal file
View file

@ -0,0 +1,145 @@
/* Interface for NSMethodSignature for GNUStep
Copyright (C) 1995 Free Software Foundation, Inc.
Written by: Mike Kienenberger
Date: Jun 1998
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
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#import <Foundation/NSProtocolChecker.h>
#import <Foundation/NSException.h>
#import <Foundation/NSInvocation.h>
#import <Foundation/NSMethodSignature.h>
@implementation NSProtocolChecker
// Allocates and initializes an NSProtocolChecker instance that will
// forward any messages in the aProtocol protocol to anObject, its
// target. Thus, the checker can be vended in lieu of anObject to
// restrict the messages that can be sent to anObject. Returns the
// new instance.
+ (id)protocolCheckerWithTarget:(NSObject *)anObject
protocol:(Protocol *)aProtocol
{
return [[[NSProtocolChecker alloc] initWithTarget:anObject
protocol:aProtocol] autorelease];
}
// Forwards any message to the delegate if the method is declared in
// the checker's protocol; otherwise raises an NSInvalidArgumentException.
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
unsigned int length;
void *buffer;
if ((struct objc_method_description *)NULL
!= [self methodDescriptionForSelector:[anInvocation selector]])
[[NSException exceptionWithName:NSInvalidArgumentException
reason:@"Method not declared in current protocol"
userInfo:nil]
raise];
[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)
{
((id)buffer) = self;
[anInvocation setReturnValue: buffer];
}
}
return;
}
- (id)init
{
myProtocol = nil;
myTarget = 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 anObject is
// allowed to be freed or dereferenced by clients, the free method
// should be included in aProtocol. Returns the new instance.
- (id)initWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol
{
[super init];
//if (nil != myProtocol)
// [myProtocol autorelease];
myProtocol = aProtocol;
//if (nil != myProtocol)
// [myProtocol retain];
if (nil != myTarget)
[myTarget autorelease];
myTarget = anObject;
if (nil != myTarget)
[myTarget retain];
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
// given message should be forwarded to its delegate, or the protocol
// checker should raise an NSInvalidArgumentException.
- (Protocol *)protocol
{
if (nil == myProtocol)
[[NSException exceptionWithName:NSInvalidArgumentException
reason:@"No protocol specified"
userInfo:nil]
raise];
return myProtocol;
}
// Returns the target of the NSProtocolChecker.
- (NSObject *)target
{
return myTarget;
}
@end

View file

@ -73,7 +73,7 @@ void gnustep_base_thread_callback()
autorelease];
#endif
entered_multi_threaded_state = NO;
objc_set_thread_callback(gnustep_base_thread_callback());
objc_set_thread_callback(gnustep_base_thread_callback);
}
}