ObjXMPP  Diff

Differences From Artifact [f678339c69]:

To Artifact [3c26c3b049]:


20
21
22
23
24
25
26

27
28
29
30
31
32
33
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif


#import <ObjFW/OFDataArray.h>

#import "XMPPMulticastDelegate.h"

@implementation XMPPMulticastDelegate
- init
{







>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#import <ObjFW/ObjFW.h>
#import <ObjFW/OFDataArray.h>

#import "XMPPMulticastDelegate.h"

@implementation XMPPMulticastDelegate
- init
{
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	size_t i, count = [_delegates count];

	for (i = 0; i < count; i++) {
		if (items[i] != delegate)
			continue;

		[_delegates removeItemAtIndex: i];

		if (i <= _handlerIndex)
			_handlerIndex--;

		return;
	}
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	size_t count = [_delegates count];
	id *items = [_delegates items];

	BOOL handled = NO;

	for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) {
		id responder = items[_handlerIndex];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);

		/*
		 * Update count and items, since the handler might have changed
		 * them.
		 */
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	size_t count = [_delegates count];
	id *items = [_delegates items];

	BOOL handled = NO;

	for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) {
		id responder = items[_handlerIndex];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);

		/*
		 * Update count and items, since the handler might have changed
		 * them.
		 */
		count = [_delegates count];
		items = [_delegates items];
	}

	return handled;
}
@end







<
<
<
<







|
|
>


|
|








<
<
<
<
<
<
<









|
|
>


|
|








<
<
<
<
<
<
<





62
63
64
65
66
67
68




69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114







115
116
117
118
119
	size_t i, count = [_delegates count];

	for (i = 0; i < count; i++) {
		if (items[i] != delegate)
			continue;

		[_delegates removeItemAtIndex: i];




		return;
	}
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object
{
	OFDataArray *currentDelegates = [_delegates copy];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	BOOL handled = NO;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object);







	}

	return handled;
}

- (BOOL)broadcastSelector: (SEL)selector
	       withObject: (id)object1
	       withObject: (id)object2
{
	OFDataArray *currentDelegates = [_delegates copy];
	id *items = [currentDelegates items];
	size_t i, count = [currentDelegates count];
	BOOL handled = NO;

	for (i = 0; i < count; i++) {
		id responder = items[i];

		if (![responder respondsToSelector: selector])
			continue;

		BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
		    [responder methodForSelector: selector];

		handled |= imp(responder, selector, object1, object2);







	}

	return handled;
}
@end