diff options
author | Ujp8LfXBJ6wCPR <github@lillecarl.com> | 2020-02-08 20:29:18 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-21 15:21:39 +0100 |
commit | 91a0fbbd7145d6fb966231689c369d641da06f9b (patch) | |
tree | f7ca752f52b78b37fa98ad73725b123b4ca42908 | |
parent | 94a79bac7a06aa0f931e9d651928de7eea0a8b5c (diff) |
Use boost::optional and boost::none instead of smelly pointer (#24134)
* Remove bad pointer usage from CharacterCache
Use TrinityCore Option type instead which is intended for this purpose. (Wrapper around boost::option until C++17 bump is finalised)
* Unify codestyle regarding TC optional type
Based upon advice from @Shauren
(cherry picked from commit 76831f1f467efe4aa26a38dc58c9eab2229bce71)
-rw-r--r-- | src/server/game/Cache/CharacterCache.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Cache/CharacterCache.h | 3 | ||||
-rw-r--r-- | src/server/game/Garrison/Garrison.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Handlers/CharacterHandler.cpp | 4 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptReloadMgr.cpp | 4 | ||||
-rw-r--r-- | src/server/game/Spells/SpellEffects.cpp | 4 |
6 files changed, 8 insertions, 11 deletions
diff --git a/src/server/game/Cache/CharacterCache.cpp b/src/server/game/Cache/CharacterCache.cpp index aea05434410..fa55d2a8235 100644 --- a/src/server/game/Cache/CharacterCache.cpp +++ b/src/server/game/Cache/CharacterCache.cpp @@ -117,7 +117,7 @@ void CharacterCache::DeleteCharacterCacheEntry(ObjectGuid const& guid, std::stri _characterCacheByNameStore.erase(name); } -void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string const& name, uint8* gender /*= nullptr*/, uint8* race /*= nullptr*/) +void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender /*= {}*/, Optional<uint8> race /*= {}*/) { auto itr = _characterCacheStore.find(guid); if (itr == _characterCacheStore.end()) diff --git a/src/server/game/Cache/CharacterCache.h b/src/server/game/Cache/CharacterCache.h index a9a872da837..74feef11e35 100644 --- a/src/server/game/Cache/CharacterCache.h +++ b/src/server/game/Cache/CharacterCache.h @@ -20,6 +20,7 @@ #include "Define.h" #include "ObjectGuid.h" +#include "Optional.h" #include <string> struct CharacterCacheEntry @@ -47,7 +48,7 @@ class TC_GAME_API CharacterCache void AddCharacterCacheEntry(ObjectGuid const& guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, bool isDeleted); void DeleteCharacterCacheEntry(ObjectGuid const& guid, std::string const& name); - void UpdateCharacterData(ObjectGuid const& guid, std::string const& name, uint8* gender = nullptr, uint8* race = nullptr); + void UpdateCharacterData(ObjectGuid const& guid, std::string const& name, Optional<uint8> gender = {}, Optional<uint8> race = {}); void UpdateCharacterGender(ObjectGuid const& guid, uint8 gender); void UpdateCharacterLevel(ObjectGuid const& guid, uint8 level); void UpdateCharacterAccountId(ObjectGuid const& guid, uint32 accountId); diff --git a/src/server/game/Garrison/Garrison.cpp b/src/server/game/Garrison/Garrison.cpp index 1f09b37f61f..96b41bbb9a3 100644 --- a/src/server/game/Garrison/Garrison.cpp +++ b/src/server/game/Garrison/Garrison.cpp @@ -815,7 +815,7 @@ void Garrison::Plot::ClearBuildingInfo(GarrisonType garrisonType, Player* owner) plotPlaced.PlotInfo = &PacketInfo; owner->SendDirectMessage(plotPlaced.Write()); - BuildingInfo.PacketInfo = boost::none; + BuildingInfo.PacketInfo.reset(); } void Garrison::Plot::SetBuildingInfo(WorldPackets::Garrison::GarrisonBuildingInfo const& buildingInfo, Player* owner) diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index f6f4976a0ef..419e66ffe09 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -1842,7 +1842,7 @@ void WorldSession::HandleCharCustomizeCallback(std::shared_ptr<WorldPackets::Cha CharacterDatabase.CommitTransaction(trans); - sCharacterCache->UpdateCharacterData(customizeInfo->CharGUID, customizeInfo->CharName, &customizeInfo->SexID); + sCharacterCache->UpdateCharacterData(customizeInfo->CharGUID, customizeInfo->CharName, customizeInfo->SexID); SendCharCustomize(RESPONSE_SUCCESS, customizeInfo.get()); @@ -2167,7 +2167,7 @@ void WorldSession::HandleCharRaceOrFactionChangeCallback(std::shared_ptr<WorldPa trans->Append(stmt); } - sCharacterCache->UpdateCharacterData(factionChangeInfo->Guid, factionChangeInfo->Name, &factionChangeInfo->SexID, &factionChangeInfo->RaceID); + sCharacterCache->UpdateCharacterData(factionChangeInfo->Guid, factionChangeInfo->Name, factionChangeInfo->SexID, factionChangeInfo->RaceID); if (oldRace != factionChangeInfo->RaceID) { diff --git a/src/server/game/Scripting/ScriptReloadMgr.cpp b/src/server/game/Scripting/ScriptReloadMgr.cpp index 7a44b9432cd..47275a2d74d 100644 --- a/src/server/game/Scripting/ScriptReloadMgr.cpp +++ b/src/server/game/Scripting/ScriptReloadMgr.cpp @@ -278,7 +278,7 @@ Optional<std::shared_ptr<ScriptModule>> path.generic_string().c_str()); } - return boost::none; + return {}; } // Use RAII to release the library on failure. @@ -305,7 +305,7 @@ Optional<std::shared_ptr<ScriptModule>> TC_LOG_ERROR("scripts.hotswap", "Could not extract all required functions from the shared library \"%s\"!", path.generic_string().c_str()); - return boost::none; + return {}; } } diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index e3297b1407d..a127167b186 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -2148,8 +2148,6 @@ void Spell::EffectDispel() WorldPackets::CombatLog::SpellDispellData dispellData; dispellData.SpellID = dispelableAura.GetAura()->GetId(); dispellData.Harmful = false; // TODO: use me - dispellData.Rolled = boost::none; // TODO: use me - dispellData.Needed = boost::none; // TODO: use me unitTarget->RemoveAurasDueToSpellByDispel(dispelableAura.GetAura()->GetId(), m_spellInfo->Id, dispelableAura.GetAura()->GetCasterGUID(), m_caster, dispelableAura.GetDispelCharges()); @@ -4568,8 +4566,6 @@ void Spell::EffectStealBeneficialBuff() WorldPackets::CombatLog::SpellDispellData dispellData; dispellData.SpellID = dispell.first; dispellData.Harmful = false; // TODO: use me - dispellData.Rolled = boost::none; // TODO: use me - dispellData.Needed = boost::none; // TODO: use me unitTarget->RemoveAurasDueToSpellBySteal(dispell.first, dispell.second, m_caster); |