1994-11-04 16:29:24 +00:00
|
|
|
/* Implementation of Objective-C "collection of delegates" object
|
1996-01-24 14:11:55 +00:00
|
|
|
Copyright (C) 1993,1994, 1995, 1996 Free Software Foundation, Inc.
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
Written by: R. Andrew McCallum <mccallum@gnu.ai.mit.edu>
|
|
|
|
Date: May 1993
|
|
|
|
|
|
|
|
This file is part of the GNU Objective-C Collection 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <objects/DelegatePool.h>
|
1996-01-24 14:11:55 +00:00
|
|
|
#include <objects/NSString.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
@implementation DelegatePool
|
|
|
|
|
1995-03-12 19:46:34 +00:00
|
|
|
+ (void) initialize
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1995-03-12 19:46:34 +00:00
|
|
|
return;
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ alloc
|
|
|
|
{
|
|
|
|
return (id)class_create_instance(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ new
|
|
|
|
{
|
|
|
|
return [[self alloc] init];
|
|
|
|
}
|
|
|
|
|
1995-04-05 21:57:52 +00:00
|
|
|
/* This is the designated initializer for this class. */
|
1994-11-04 16:29:24 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
_list = [[Array alloc] init];
|
|
|
|
_send_behavior = SEND_TO_ALL;
|
1995-04-05 21:57:52 +00:00
|
|
|
_last_message_had_receivers = NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Archiving must mimic the above designated initializer */
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
- (void) encodeWithCoder: anEncoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1996-01-23 23:57:17 +00:00
|
|
|
[anEncoder encodeValueOfCType:@encode(unsigned char)
|
1994-11-04 16:29:24 +00:00
|
|
|
at:&_send_behavior
|
1996-01-24 03:33:21 +00:00
|
|
|
withName:@"DelegatePool Send Behavior"];
|
1994-11-04 16:29:24 +00:00
|
|
|
[anEncoder encodeObject:_list
|
1996-01-24 03:33:21 +00:00
|
|
|
withName:@"DelegatePool Collection of Delegates"];
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
|
1995-04-09 01:53:53 +00:00
|
|
|
+ newWithCoder: aDecoder
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1995-04-09 01:53:53 +00:00
|
|
|
/* xxx Should be:
|
|
|
|
DelegatePool *n = NSAllocateObject(self, 0, [aDecoder objectZone]); */
|
|
|
|
DelegatePool *n = (id) NSAllocateObject(self, 0, NS_NOZONE);
|
1996-01-23 23:57:17 +00:00
|
|
|
[aDecoder decodeValueOfCType:@encode(unsigned char)
|
1994-11-04 16:29:24 +00:00
|
|
|
at:&(n->_send_behavior)
|
|
|
|
withName:NULL];
|
|
|
|
[aDecoder decodeObjectAt:&(n->_list)
|
|
|
|
withName:NULL];
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- write: (TypedStream*)aStream
|
|
|
|
{
|
|
|
|
objc_write_type(aStream, @encode(unsigned char), &_send_behavior);
|
|
|
|
objc_write_object(aStream, _list);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- read: (TypedStream*)aStream
|
|
|
|
{
|
|
|
|
objc_write_type(aStream, @encode(unsigned char), &_send_behavior);
|
|
|
|
objc_read_object(aStream, &_list);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-03-12 19:46:34 +00:00
|
|
|
- (void) dealloc
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
1995-03-12 19:46:34 +00:00
|
|
|
[_list release];
|
1994-11-04 16:29:24 +00:00
|
|
|
#if NeXT_runtime
|
1995-03-12 19:46:34 +00:00
|
|
|
object_dispose((Object*)self);
|
1994-11-04 16:29:24 +00:00
|
|
|
#else
|
1995-03-12 19:46:34 +00:00
|
|
|
NSDeallocateObject((NSObject*)self);
|
1994-11-04 16:29:24 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MANIPULATING COLLECTION OF DELEGATES;
|
|
|
|
|
|
|
|
- delegatePoolAddObject: anObject
|
|
|
|
{
|
|
|
|
[_list addObject: anObject];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- delegatePoolAddObjectIfAbsent: anObject
|
|
|
|
{
|
|
|
|
[_list addObjectIfAbsent: anObject];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- delegatePoolRemoveObject: anObject
|
|
|
|
{
|
|
|
|
return [_list removeObject:anObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) delegatePoolIncludesObject: anObject
|
|
|
|
{
|
|
|
|
return [_list includesObject:anObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
- delegatePoolCollection
|
|
|
|
{
|
|
|
|
return _list;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned char) delegatePoolSendBehavior
|
|
|
|
{
|
|
|
|
return _send_behavior;
|
|
|
|
}
|
|
|
|
|
|
|
|
- delegatePoolSetSendBehavior: (unsigned char)b
|
|
|
|
{
|
|
|
|
_send_behavior = b;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1995-04-05 21:57:52 +00:00
|
|
|
- (BOOL) delegatePoolLastMessageHadReceivers
|
|
|
|
{
|
|
|
|
return _last_message_had_receivers;
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
// FOR PASSING ALL OTHER MESSAGES TO DELEGATES;
|
|
|
|
|
|
|
|
- forward: (SEL)aSel :(arglist_t)argFrame
|
|
|
|
{
|
|
|
|
void *ret = 0;
|
|
|
|
elt delegate;
|
|
|
|
|
1995-04-05 21:57:52 +00:00
|
|
|
_last_message_had_receivers = NO;
|
1994-11-04 16:29:24 +00:00
|
|
|
switch (_send_behavior)
|
|
|
|
{
|
|
|
|
case SEND_TO_ALL:
|
|
|
|
FOR_ARRAY(_list, delegate)
|
|
|
|
{
|
|
|
|
if ([delegate.id_u respondsTo:aSel])
|
1995-04-05 21:57:52 +00:00
|
|
|
{
|
|
|
|
ret = [delegate.id_u performv:aSel :argFrame];
|
|
|
|
_last_message_had_receivers = YES;
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
FOR_ARRAY_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEND_TO_FIRST_RESPONDER:
|
|
|
|
FOR_ARRAY(_list, delegate)
|
|
|
|
{
|
|
|
|
if ([delegate.id_u respondsTo:aSel])
|
1995-04-05 21:57:52 +00:00
|
|
|
{
|
|
|
|
_last_message_had_receivers = YES;
|
|
|
|
return [delegate.id_u performv:aSel :argFrame];
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
FOR_ARRAY_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEND_UNTIL_YES:
|
|
|
|
FOR_ARRAY(_list, delegate)
|
|
|
|
{
|
|
|
|
if ([delegate.id_u respondsTo:aSel])
|
1995-04-05 21:57:52 +00:00
|
|
|
{
|
|
|
|
_last_message_had_receivers = YES;
|
|
|
|
if ((ret = [delegate.id_u performv:aSel :argFrame]))
|
|
|
|
return ret;
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
FOR_ARRAY_END;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEND_UNTIL_NO:
|
|
|
|
FOR_ARRAY(_list, delegate)
|
|
|
|
{
|
|
|
|
if ([delegate.id_u respondsTo:aSel])
|
1995-04-05 21:57:52 +00:00
|
|
|
{
|
|
|
|
_last_message_had_receivers = YES;
|
|
|
|
if (!(ret = [delegate.id_u performv:aSel :argFrame]))
|
|
|
|
return ret;
|
|
|
|
}
|
1994-11-04 16:29:24 +00:00
|
|
|
}
|
|
|
|
FOR_ARRAY_END;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|