Return WeakPointer in avatarHashMap

This commit is contained in:
Atlante45 2015-01-29 15:50:59 -08:00
parent cb8e4f33bc
commit 9095eeeeb9
2 changed files with 7 additions and 9 deletions

View file

@ -51,26 +51,26 @@ void AvatarHashMap::processAvatarMixerDatagram(const QByteArray& datagram, const
} }
bool AvatarHashMap::containsAvatarWithDisplayName(const QString& displayName) { bool AvatarHashMap::containsAvatarWithDisplayName(const QString& displayName) {
return avatarWithDisplayName(displayName) == NULL ? false : true; return !avatarWithDisplayName(displayName).isNull();
} }
AvatarData* AvatarHashMap::avatarWithDisplayName(const QString& displayName) { AvatarWeakPointer AvatarHashMap::avatarWithDisplayName(const QString& displayName) {
foreach(const AvatarSharedPointer& sharedAvatar, _avatarHash) { foreach(const AvatarSharedPointer& sharedAvatar, _avatarHash) {
if (sharedAvatar->getDisplayName() == displayName) { if (sharedAvatar->getDisplayName() == displayName) {
// this is a match // this is a match
// check if this avatar should still be around // check if this avatar should still be around
if (!shouldKillAvatar(sharedAvatar)) { if (!shouldKillAvatar(sharedAvatar)) {
// we have a match, return the AvatarData // we have a match, return the AvatarData
return sharedAvatar.data(); return sharedAvatar;
} else { } else {
// we should remove this avatar, but we might not be on a thread that is allowed // we should remove this avatar, but we might not be on a thread that is allowed
// so we just return NULL to the caller // so we just return NULL to the caller
return NULL; return AvatarWeakPointer();
} }
} }
} }
return NULL; return AvatarWeakPointer();
} }
AvatarSharedPointer AvatarHashMap::newSharedAvatar() { AvatarSharedPointer AvatarHashMap::newSharedAvatar() {

View file

@ -30,20 +30,18 @@ class AvatarHashMap : public QObject, public Dependency {
SINGLETON_DEPENDENCY SINGLETON_DEPENDENCY
public: public:
AvatarHashMap();
const AvatarHash& getAvatarHash() { return _avatarHash; } const AvatarHash& getAvatarHash() { return _avatarHash; }
int size() const { return _avatarHash.size(); }
public slots: public slots:
void processAvatarMixerDatagram(const QByteArray& datagram, const QWeakPointer<Node>& mixerWeakPointer); void processAvatarMixerDatagram(const QByteArray& datagram, const QWeakPointer<Node>& mixerWeakPointer);
bool containsAvatarWithDisplayName(const QString& displayName); bool containsAvatarWithDisplayName(const QString& displayName);
AvatarData* avatarWithDisplayName(const QString& displayname); AvatarWeakPointer avatarWithDisplayName(const QString& displayname);
private slots: private slots:
void sessionUUIDChanged(const QUuid& sessionUUID, const QUuid& oldUUID); void sessionUUIDChanged(const QUuid& sessionUUID, const QUuid& oldUUID);
protected: protected:
AvatarHashMap();
virtual AvatarHash::iterator erase(const AvatarHash::iterator& iterator); virtual AvatarHash::iterator erase(const AvatarHash::iterator& iterator);
bool shouldKillAvatar(const AvatarSharedPointer& sharedAvatar); bool shouldKillAvatar(const AvatarSharedPointer& sharedAvatar);