Skip to content

Commit

Permalink
Merge pull request H-uru#1505 from dgelessus/fix_plkey_ordering
Browse files Browse the repository at this point in the history
Fix ordering operators for `plKey`
  • Loading branch information
Hoikas authored Oct 15, 2023
2 parents e6a0a55 + 7d7e49e commit ca80c0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Sources/Plasma/NucleusLib/pnKeyedObject/plKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class plKey
bool operator==(const plKeyData* rhs) const { return fKeyData == rhs; }
bool operator!=(const plKey& rhs) const { return !(*this == rhs); }
bool operator!=(const plKeyData* rhs) const { return !(*this == rhs); }
// Ordering operators for stdlib containers, etc. that rely on < (std::less) by default
bool operator<(const plKey& rhs) const { return fKeyData < rhs.fKeyData; }
bool operator>(const plKey& rhs) const { return fKeyData > rhs.fKeyData; }
bool operator<=(const plKey& rhs) const { return fKeyData <= rhs.fKeyData; }
bool operator>=(const plKey& rhs) const { return fKeyData >= rhs.fKeyData; }

plKeyData* operator->() const;
plKeyData& operator*() const;
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ void plKeyImp::INotifySelf(hsKeyedObject* ko)
// GetNumReceivers() should always be 1 for a refMsg.
for (int k = 0; k < refMsg->GetNumReceivers(); k++)
{
if (&(*refMsg->GetReceiver(k)) == (plKeyData*)this)
if (refMsg->GetReceiver(k) == this)
{
ref->SetNotified(j);
ref->SatisfyPending(refMsg);
Expand Down Expand Up @@ -612,7 +612,7 @@ void plKeyImp::IRelease(plKeyImp* iTargetKey)
plMessage* rcvMsg = iTargetKey->GetNotifyCreated(i);
for (int j = 0; j < rcvMsg->GetNumReceivers(); j++)
{
if (&(*rcvMsg->GetReceiver(j)) == (plKeyData*)this)
if (rcvMsg->GetReceiver(j) == this)
{
isActive = iTargetKey->IsActiveRef(iTarg = (hsSsize_t)i);
break;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plResManager.h"

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKey.h"
#include "pnKeyedObject/plKeyImp.h"

plResManager* IGetResMgr() { return (plResManager*)hsgResMgr::ResMgr(); }

Expand Down Expand Up @@ -438,7 +438,7 @@ plKey plKeyFinder::IFindSceneNodeKey(plRegistryPageNode* page) const
{
if (keyList->fKeys.size() == 1)
{
return plKey::Make((plKeyData*)keyList->fKeys[0]);
return plKey::Make(keyList->fKeys[0]);
}
}

Expand All @@ -453,7 +453,7 @@ plKey plKeyFinder::IFindSceneNodeKey(plRegistryPageNode* page) const
keyList = page->IGetKeyList(CLASS_INDEX_SCOPED(plSceneNode));
if (keyList && keyList->fKeys.size() == 1)
{
retVal = plKey::Make((plKeyData*)keyList->fKeys[0]);
retVal = plKey::Make(keyList->fKeys[0]);
}
// If we just loaded up all the keys for this page, then we
// may have a bunch of keys with a refcount of 0. For any of
Expand Down

0 comments on commit ca80c0d

Please sign in to comment.