From fdaeeb38daf0ba3a0373b53a9d3430664836733b Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Wed, 16 Sep 2020 02:37:04 +0200 Subject: [PATCH] Switch ERlvExceptionCheck to a C++0x enum + minor code review/cleanup (no functional changes) --- indra/newview/llviewermessage.cpp | 2 +- indra/newview/rlvactions.cpp | 14 ++++++------ indra/newview/rlvdefines.h | 8 +++---- indra/newview/rlvhandler.cpp | 38 ++++++++++++++----------------- indra/newview/rlvhandler.h | 14 +++++++++++- indra/newview/rlvhelper.h | 15 ------------ 6 files changed, 42 insertions(+), 49 deletions(-) diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp index 0ec1ea0210..1631adbc1c 100644 --- a/indra/newview/llviewermessage.cpp +++ b/indra/newview/llviewermessage.cpp @@ -6665,7 +6665,7 @@ void handle_lure(const uuid_vec_t& ids) if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) { const LLRelationship* pBuddyInfo = LLAvatarTracker::instance().getBuddyInfo(idAgent); - if ( (!gRlvHandler.isException(RLV_BHVR_TPLURE, idAgent, RLV_CHECK_PERMISSIVE)) && + if ( (!gRlvHandler.isException(RLV_BHVR_TPLURE, idAgent, ERlvExceptionCheck::Permissive)) && ((!pBuddyInfo) || (!pBuddyInfo->isOnline()) || (!pBuddyInfo->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION))) ) { RlvUtil::notifyBlocked(RlvStringKeys::Blocked::TeleportOffer); diff --git a/indra/newview/rlvactions.cpp b/indra/newview/rlvactions.cpp index 671b2a8414..1728717cce 100644 --- a/indra/newview/rlvactions.cpp +++ b/indra/newview/rlvactions.cpp @@ -454,7 +454,7 @@ bool RlvActions::canShowHoverText(const LLViewerObject *pObj) !( (rlvHandler.hasBehaviour(RLV_BHVR_SHOWHOVERTEXTALL)) || ( (rlvHandler.hasBehaviour(RLV_BHVR_SHOWHOVERTEXTWORLD)) && (!pObj->isHUDAttachment()) ) || ( (rlvHandler.hasBehaviour(RLV_BHVR_SHOWHOVERTEXTHUD)) && (pObj->isHUDAttachment()) ) || - (rlvHandler.isException(RLV_BHVR_SHOWHOVERTEXT, pObj->getID(), RLV_CHECK_PERMISSIVE)) ) ); + (rlvHandler.isException(RLV_BHVR_SHOWHOVERTEXT, pObj->getID(), ERlvExceptionCheck::Permissive)) ) ); } // Handles: @touchall, @touchthis, @touchworld, @touchattach, @touchattachself, @touchattachother, @touchhud, @touchme and @fartouch @@ -501,28 +501,28 @@ bool RlvActions::canTouch(const LLViewerObject* pObj, const LLVector3& posOffset bool fCanTouch = (idRoot.notNull()) && ( (pObj->isHUDAttachment()) || (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHALL)) ) && - ( (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHTHIS)) || (!rlvHandler.isException(RLV_BHVR_TOUCHTHIS, idRoot, RLV_CHECK_PERMISSIVE)) ); + ( (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHTHIS)) || (!rlvHandler.isException(RLV_BHVR_TOUCHTHIS, idRoot, ERlvExceptionCheck::Permissive)) ); if (fCanTouch) { if ( (!pObj->isAttachment()) || (!pObj->permYouOwner()) ) { // Rezzed or attachment worn by other - test for (1.c), (2.d), (2.e) and (1/2.h) fCanTouch = - ( (!pObj->isAttachment()) ? (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHWORLD)) || (rlvHandler.isException(RLV_BHVR_TOUCHWORLD, idRoot, RLV_CHECK_PERMISSIVE)) - : ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACH)) && (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACHOTHER))) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, RLV_CHECK_PERMISSIVE)) ) && + ( (!pObj->isAttachment()) ? (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHWORLD)) || (rlvHandler.isException(RLV_BHVR_TOUCHWORLD, idRoot, ERlvExceptionCheck::Permissive)) + : ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACH)) && (!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACHOTHER))) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, ERlvExceptionCheck::Permissive)) ) && ( (!rlvHandler.hasBehaviour(RLV_BHVR_FARTOUCH)) || (dist_vec_squared(gAgent.getPositionGlobal(), pObj->getPositionGlobal() + LLVector3d(posOffset)) <= s_nFartouchDist * s_nFartouchDist) ); } else if (!pObj->isHUDAttachment()) { // Regular attachment worn by this avie - test for (3.d), (3.e) and (3.h) fCanTouch = - ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACH)) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, RLV_CHECK_PERMISSIVE))) && - ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACHSELF)) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, RLV_CHECK_PERMISSIVE))); + ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACH)) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, ERlvExceptionCheck::Permissive))) && + ((!rlvHandler.hasBehaviour(RLV_BHVR_TOUCHATTACHSELF)) || (rlvHandler.isException(RLV_BHVR_TOUCHATTACH, idRoot, ERlvExceptionCheck::Permissive))); } else { // HUD attachment - test for (4.g) - fCanTouch = (!hasBehaviour(RLV_BHVR_TOUCHHUD)) || (rlvHandler.isException(RLV_BHVR_TOUCHHUD, idRoot, RLV_CHECK_PERMISSIVE)); + fCanTouch = (!hasBehaviour(RLV_BHVR_TOUCHHUD)) || (rlvHandler.isException(RLV_BHVR_TOUCHHUD, idRoot, ERlvExceptionCheck::Permissive)); } } // Post-check for (1/2/3/4i) diff --git a/indra/newview/rlvdefines.h b/indra/newview/rlvdefines.h index 355eb4f977..bf1a0e0835 100644 --- a/indra/newview/rlvdefines.h +++ b/indra/newview/rlvdefines.h @@ -327,11 +327,11 @@ enum ERlvCmdRet { }; #define RLV_RET_SUCCEEDED(eCmdRet) (((eCmdRet) & RLV_RET_SUCCESS) == RLV_RET_SUCCESS) -enum ERlvExceptionCheck +enum class ERlvExceptionCheck { - RLV_CHECK_PERMISSIVE, // Exception can be set by any object - RLV_CHECK_STRICT, // Exception must be set by all objects holding the restriction - RLV_CHECK_DEFAULT // Permissive or strict will be determined by currently enforced restrictions + Permissive, // Exception can be set by any object + Strict, // Exception must be set by all objects holding the restriction + Default, // Permissive or strict will be determined by currently enforced restrictions }; enum ERlvLockMask diff --git a/indra/newview/rlvhandler.cpp b/indra/newview/rlvhandler.cpp index 0fce3168fa..fa73b1d527 100644 --- a/indra/newview/rlvhandler.cpp +++ b/indra/newview/rlvhandler.cpp @@ -257,35 +257,34 @@ bool RlvHandler::ownsBehaviour(const LLUUID& idObj, ERlvBehaviour eBhvr) const // Behaviour exception handling // -// Checked: 2009-10-04 (RLVa-1.0.4a) | Modified: RLVa-1.0.4a void RlvHandler::addException(const LLUUID& idObj, ERlvBehaviour eBhvr, const RlvExceptionOption& varOption) { - m_Exceptions.insert(std::pair(eBhvr, RlvException(idObj, eBhvr, varOption))); + m_Exceptions.insert(std::make_pair(eBhvr, RlvException(idObj, eBhvr, varOption))); } -// Checked: 2009-10-04 (RLVa-1.0.4c) | Modified: RLVa-1.0.4c -bool RlvHandler::isException(ERlvBehaviour eBhvr, const RlvExceptionOption& varOption, ERlvExceptionCheck typeCheck) const +bool RlvHandler::isException(ERlvBehaviour eBhvr, const RlvExceptionOption& varOption, ERlvExceptionCheck eCheckType) const { // We need to "strict check" exceptions only if: the restriction is actually in place *and* (isPermissive(eBhvr) == FALSE) - if (RLV_CHECK_DEFAULT == typeCheck) - typeCheck = ( (hasBehaviour(eBhvr)) && (!isPermissive(eBhvr)) ) ? RLV_CHECK_STRICT : RLV_CHECK_PERMISSIVE; + if (ERlvExceptionCheck::Default == eCheckType) + eCheckType = ( (hasBehaviour(eBhvr)) && (!isPermissive(eBhvr)) ) ? ERlvExceptionCheck::Strict : ERlvExceptionCheck::Permissive; uuid_vec_t objList; - if (RLV_CHECK_STRICT == typeCheck) + if (ERlvExceptionCheck::Strict == eCheckType) { // If we're "strict checking" then we need the UUID of every object that currently has 'eBhvr' restricted - for (rlv_object_map_t::const_iterator itObj = m_Objects.begin(); itObj != m_Objects.end(); ++itObj) - if (itObj->second.hasBehaviour(eBhvr, !hasBehaviour(RLV_BHVR_PERMISSIVE))) - objList.push_back(itObj->first); + for (const auto& objEntry : m_Objects) + { + if (objEntry.second.hasBehaviour(eBhvr, !hasBehaviour(RLV_BHVR_PERMISSIVE))) + objList.push_back(objEntry.first); + } } - for (rlv_exception_map_t::const_iterator itException = m_Exceptions.lower_bound(eBhvr), - endException = m_Exceptions.upper_bound(eBhvr); itException != endException; ++itException) + for (rlv_exception_map_t::const_iterator itException = m_Exceptions.lower_bound(eBhvr), endException = m_Exceptions.upper_bound(eBhvr); itException != endException; ++itException) { if (itException->second.varOption == varOption) { // For permissive checks we just return on the very first match - if (RLV_CHECK_PERMISSIVE == typeCheck) + if (ERlvExceptionCheck::Permissive == eCheckType) return true; // For strict checks we don't return until the list is empty (every object with 'eBhvr' restricted also contains the exception) @@ -299,19 +298,16 @@ bool RlvHandler::isException(ERlvBehaviour eBhvr, const RlvExceptionOption& varO return false; } -// Checked: 2009-10-04 (RLVa-1.0.4a) | Modified: RLVa-1.0.4a bool RlvHandler::isPermissive(ERlvBehaviour eBhvr) const { - return (RlvBehaviourDictionary::instance().getHasStrict(eBhvr)) - ? !((hasBehaviour(RLV_BHVR_PERMISSIVE)) || (isException(RLV_BHVR_PERMISSIVE, eBhvr, RLV_CHECK_PERMISSIVE))) + return (RlvBehaviourDictionary::instance().getHasStrict(eBhvr)) + ? !((hasBehaviour(RLV_BHVR_PERMISSIVE)) || (isException(RLV_BHVR_PERMISSIVE, eBhvr, ERlvExceptionCheck::Permissive))) : true; } -// Checked: 2009-10-04 (RLVa-1.0.4a) | Modified: RLVa-1.0.4a void RlvHandler::removeException(const LLUUID& idObj, ERlvBehaviour eBhvr, const RlvExceptionOption& varOption) { - for (rlv_exception_map_t::iterator itException = m_Exceptions.lower_bound(eBhvr), - endException = m_Exceptions.upper_bound(eBhvr); itException != endException; ++itException) + for (rlv_exception_map_t::iterator itException = m_Exceptions.lower_bound(eBhvr), endException = m_Exceptions.upper_bound(eBhvr); itException != endException; ++itException) { if ( (itException->second.idObject == idObj) && (itException->second.varOption == varOption) ) { @@ -1746,9 +1742,9 @@ ERlvCmdRet RlvBehaviourGenericHandler::onCommand(const Rlv return RLV_RET_FAILED_OPTION; if (RLV_TYPE_ADD == rlvCmd.getParamType()) - gRlvHandler.addException(rlvCmd.getObjectID(), rlvCmd.getBehaviourType(), idException); + RlvHandler::instance().addException(rlvCmd.getObjectID(), rlvCmd.getBehaviourType(), idException); else - gRlvHandler.removeException(rlvCmd.getObjectID(), rlvCmd.getBehaviourType(), idException); + RlvHandler::instance().removeException(rlvCmd.getObjectID(), rlvCmd.getBehaviourType(), idException); fRefCount = true; return RLV_RET_SUCCESS; diff --git a/indra/newview/rlvhandler.h b/indra/newview/rlvhandler.h index 32eda85137..c5b20de417 100644 --- a/indra/newview/rlvhandler.h +++ b/indra/newview/rlvhandler.h @@ -77,7 +77,7 @@ public: // Returns TRUE if the specified behaviour has an added exception bool hasException(ERlvBehaviour eBhvr) const; // Returns TRUE if the specified option was added as an exception for the specified behaviour - bool isException(ERlvBehaviour eBhvr, const RlvExceptionOption& varOption, ERlvExceptionCheck typeCheck = RLV_CHECK_DEFAULT) const; + bool isException(ERlvBehaviour eBhvr, const RlvExceptionOption& varOption, ERlvExceptionCheck eCheckType = ERlvExceptionCheck::Default) const; // Returns TRUE if the specified behaviour should behave "permissive" (rather than "strict"/"secure") bool isPermissive(ERlvBehaviour eBhvr) const; @@ -235,6 +235,18 @@ public: typedef std::map rlv_object_map_t; typedef std::tuple rlv_blocked_object_t; typedef std::list rlv_blocked_object_list_t; + + struct RlvException + { + public: + LLUUID idObject; // UUID of the object that added the exception + ERlvBehaviour eBehaviour; // Behaviour the exception applies to + RlvExceptionOption varOption; // Exception data (type is dependent on eBehaviour) + + RlvException(const LLUUID& idObj, ERlvBehaviour eBhvr, const RlvExceptionOption& option) : idObject(idObj), eBehaviour(eBhvr), varOption(option) {} + private: + RlvException(); + }; typedef std::multimap rlv_exception_map_t; protected: rlv_object_map_t m_Objects; // Map of objects that have active restrictions (idObj -> RlvObject) diff --git a/indra/newview/rlvhelper.h b/indra/newview/rlvhelper.h index cbe79ec57a..b83d29cc13 100644 --- a/indra/newview/rlvhelper.h +++ b/indra/newview/rlvhelper.h @@ -622,21 +622,6 @@ protected: boost::signals2::connection m_ConnCommand; }; -// ============================================================================ -// RlvException -// - -struct RlvException -{ -public: - LLUUID idObject; // UUID of the object that added the exception - ERlvBehaviour eBehaviour; // Behaviour the exception applies to - RlvExceptionOption varOption; // Exception data (type is dependent on eBehaviour) - - RlvException(const LLUUID& idObj, ERlvBehaviour eBhvr, const RlvExceptionOption& option) : idObject(idObj), eBehaviour(eBhvr), varOption(option) {} -private: - RlvException(); -}; // ============================================================================ // Various helper classes/timers/functors