PEGASUS: Use an Array instead of a List for NotificationReceivers

Fixes occasional crashes with the norad sub controls. CodeWarrior's iterators used indices unlike our List iterators, thus necessitating the change here.
This commit is contained in:
Matthew Hoops 2012-04-06 19:18:41 -04:00
parent b07d03dedf
commit a2454f6563
2 changed files with 15 additions and 14 deletions

View File

@ -38,8 +38,8 @@ Notification::Notification(const NotificationID id, NotificationManager *owner)
}
Notification::~Notification() {
for (ReceiverIterator it = _receivers.begin(); it != _receivers.end(); it++)
it->receiver->newNotification(NULL);
for (uint i = 0; i < _receivers.size(); i++)
_receivers[i].receiver->newNotification(NULL);
if (_owner)
_owner->removeNotification(this);
@ -49,9 +49,9 @@ Notification::~Notification() {
// Wherever mask is 0, leave existing bits untouched.
// Wherever mask is 1, set bit equivalent to flags.
void Notification::notifyMe(NotificationReceiver *receiver, NotificationFlags flags, NotificationFlags mask) {
for (ReceiverIterator it = _receivers.begin(); it != _receivers.end(); it++) {
if (it->receiver == receiver) {
it->mask = (it->mask & ~mask) | (flags & mask);
for (uint i = 0; i < _receivers.size(); i++) {
if (_receivers[i].receiver == receiver) {
_receivers[i].mask = (_receivers[i].mask & ~mask) | (flags & mask);
receiver->newNotification(this);
return;
}
@ -66,11 +66,11 @@ void Notification::notifyMe(NotificationReceiver *receiver, NotificationFlags fl
}
void Notification::cancelNotification(NotificationReceiver *receiver) {
for (ReceiverIterator it = _receivers.begin(); it != _receivers.end();) {
if (it->receiver == receiver)
it = _receivers.erase(it);
else
it++;
for (uint i = 0; i < _receivers.size(); i++) {
if (_receivers[i].receiver == receiver) {
_receivers.remove_at(i);
i--;
}
}
}
@ -82,9 +82,9 @@ void Notification::checkReceivers() {
NotificationFlags currentFlags = _currentFlags;
_currentFlags = kNoNotificationFlags;
for (ReceiverIterator it = _receivers.begin(); it != _receivers.end(); it++)
if (it->mask & currentFlags)
it->receiver->receiveNotification(this, currentFlags);
for (uint i = 0; i < _receivers.size(); i++)
if (_receivers[i].mask & currentFlags)
_receivers[i].receiver->receiveNotification(this, currentFlags);
}
// Receiver entries are equal if their receivers are equal.

View File

@ -26,6 +26,7 @@
#ifndef PEGASUS_NOTIFICATION_H
#define PEGASUS_NOTIFICATION_H
#include "common/array.h"
#include "common/list.h"
#include "pegasus/types.h"
@ -44,7 +45,7 @@ struct ReceiverEntry {
int operator==(const ReceiverEntry &entry1, const ReceiverEntry &entry2);
int operator!=(const ReceiverEntry &entry1, const ReceiverEntry &entry2);
typedef Common::List<ReceiverEntry> ReceiverList;
typedef Common::Array<ReceiverEntry> ReceiverList;
/*
A notification can have 32 flags associated with it, which can be user-defined.