diff options
author | ariel- <ariel-@users.noreply.github.com> | 2016-10-06 23:14:51 -0300 |
---|---|---|
committer | ariel- <ariel-@users.noreply.github.com> | 2016-10-06 23:14:51 -0300 |
commit | 3b6fd226bedb689847dadaeeba36a588ee9bc928 (patch) | |
tree | 150c771b9981e66adb69fae74b1a17873b0d7014 /src | |
parent | f6788b78a6d5237c86ec5ff8c087a0d630f3afeb (diff) |
Core/Misc: fix interaction of spells like Shadowmeld with Threat reducing effects
- SPELL_AURA_MOD_TOTAL_THREAT should be temporary and not added/subtracted from total, only computed
- Cleanup of reference related code
- Kill getLast() and reverse iterator obsevers, LinkedList iterator can't be used as a standard reverse_iterator (ie with operator++). They weren't used anyways
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Combat/HostileRefManager.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Combat/HostileRefManager.h | 11 | ||||
-rw-r--r-- | src/server/game/Combat/ThreatManager.cpp | 27 | ||||
-rw-r--r-- | src/server/game/Combat/ThreatManager.h | 37 | ||||
-rw-r--r-- | src/server/game/Combat/UnitEvents.h | 39 | ||||
-rw-r--r-- | src/server/game/Grids/GridRefManager.h | 2 | ||||
-rw-r--r-- | src/server/game/Loot/LootMgr.h | 11 | ||||
-rw-r--r-- | src/server/game/Maps/MapRefManager.h | 15 | ||||
-rw-r--r-- | src/server/shared/Dynamic/LinkedList.h | 56 | ||||
-rw-r--r-- | src/server/shared/Dynamic/LinkedReference/RefManager.h | 30 | ||||
-rw-r--r-- | src/server/shared/Dynamic/LinkedReference/Reference.h | 7 |
11 files changed, 118 insertions, 125 deletions
diff --git a/src/server/game/Combat/HostileRefManager.cpp b/src/server/game/Combat/HostileRefManager.cpp index 397fd59b7d1..965b910c3f4 100644 --- a/src/server/game/Combat/HostileRefManager.cpp +++ b/src/server/game/Combat/HostileRefManager.cpp @@ -28,8 +28,8 @@ HostileRefManager::~HostileRefManager() } //================================================= -// send threat to all my hateres for the victim -// The victim is hated than by them as well +// send threat to all my haters for the victim +// The victim is then hated by them as well // use for buffs and healing threat functionality void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell) @@ -37,9 +37,10 @@ void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo c if (getSize() == 0) return; - HostileReference* ref = getFirst(); float threat = ThreatCalcHelper::calcThreat(victim, iOwner, baseThreat, (threatSpell ? threatSpell->GetSchoolMask() : SPELL_SCHOOL_MASK_NORMAL), threatSpell); threat /= getSize(); + + HostileReference* ref = getFirst(); while (ref) { if (ThreatCalcHelper::isValidProcess(victim, ref->GetSource()->GetOwner(), threatSpell)) @@ -54,7 +55,6 @@ void HostileRefManager::threatAssist(Unit* victim, float baseThreat, SpellInfo c void HostileRefManager::addTempThreat(float threat, bool apply) { HostileReference* ref = getFirst(); - while (ref) { if (apply) diff --git a/src/server/game/Combat/HostileRefManager.h b/src/server/game/Combat/HostileRefManager.h index 855f9e3d272..859bee3caf7 100644 --- a/src/server/game/Combat/HostileRefManager.h +++ b/src/server/game/Combat/HostileRefManager.h @@ -31,18 +31,16 @@ class SpellInfo; class TC_GAME_API HostileRefManager : public RefManager<Unit, ThreatManager> { - private: - Unit* iOwner; public: - explicit HostileRefManager(Unit* owner) { iOwner = owner; } + explicit HostileRefManager(Unit* owner) : iOwner(owner) { } ~HostileRefManager(); - Unit* GetOwner() { return iOwner; } + Unit* GetOwner() const { return iOwner; } // send threat to all my hateres for the victim // The victim is hated than by them as well // use for buffs and healing threat functionality - void threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell = NULL); + void threatAssist(Unit* victim, float baseThreat, SpellInfo const* threatSpell = nullptr); void addTempThreat(float threat, bool apply); @@ -68,6 +66,9 @@ class TC_GAME_API HostileRefManager : public RefManager<Unit, ThreatManager> void deleteReference(Unit* creature); void UpdateVisibility(); + + private: + Unit* iOwner; }; //================================================= #endif diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp index e04e1485d64..fec4ec300cc 100644 --- a/src/server/game/Combat/ThreatManager.cpp +++ b/src/server/game/Combat/ThreatManager.cpp @@ -30,7 +30,7 @@ //============================================================== // The hatingUnit is not used yet -float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell) +float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float threat, SpellSchoolMask schoolMask, SpellInfo const* threatSpell /*= nullptr*/) { if (threatSpell) { @@ -39,7 +39,7 @@ float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float threat *= threatEntry->pctMod; // Energize is not affected by Mods - for (uint8 i = 0; i < MAX_SPELL_EFFECTS; i++) + for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) if (threatSpell->Effects[i].Effect == SPELL_EFFECT_ENERGIZE || threatSpell->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE) return threat; @@ -50,7 +50,7 @@ float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float return hatedUnit->ApplyTotalThreatModifier(threat, schoolMask); } -bool ThreatCalcHelper::isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell) +bool ThreatCalcHelper::isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell /*= nullptr*/) { //function deals with adding threat and adding players and pets into ThreatList //mobs, NPCs, guards have ThreatList and HateOfflineList @@ -134,18 +134,20 @@ void HostileReference::fireStatusChanged(ThreatRefStatusChangeEvent& threatRefSt void HostileReference::addThreat(float modThreat) { + if (!modThreat) + return; + iThreat += modThreat; + // the threat is changed. Source and target unit have to be available // if the link was cut before relink it again if (!isOnline()) updateOnlineStatus(); - if (modThreat != 0.0f) - { - ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, modThreat); - fireStatusChanged(event); - } - if (isValid() && modThreat >= 0.0f) + ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, modThreat); + fireStatusChanged(event); + + if (isValid() && modThreat > 0.0f) { Unit* victimOwner = getTarget()->GetCharmerOrOwner(); if (victimOwner && victimOwner->IsAlive()) @@ -155,9 +157,7 @@ void HostileReference::addThreat(float modThreat) void HostileReference::addThreatPercent(int32 percent) { - float tmpThreat = iThreat; - AddPct(tmpThreat, percent); - addThreat(tmpThreat - iThreat); + addThreat(CalculatePct(iThreat, percent)); } //============================================================ @@ -193,6 +193,7 @@ void HostileReference::updateOnlineStatus() else accessible = true; } + setAccessibleState(accessible); setOnlineOfflineState(online); } @@ -221,7 +222,7 @@ void HostileReference::setAccessibleState(bool isAccessible) { iAccessible = isAccessible; - ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ASSECCIBLE_STATUS, this); + ThreatRefStatusChangeEvent event(UEV_THREAT_REF_ACCESSIBLE_STATUS, this); fireStatusChanged(event); } } diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index a68d803304d..cad62659317 100644 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -41,8 +41,8 @@ class SpellInfo; struct TC_GAME_API ThreatCalcHelper { - static float calcThreat(Unit* hatedUnit, Unit* hatingUnit, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = NULL); - static bool isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell = NULL); + static float calcThreat(Unit* hatedUnit, Unit* hatingUnit, float threat, SpellSchoolMask schoolMask = SPELL_SCHOOL_MASK_NORMAL, SpellInfo const* threatSpell = nullptr); + static bool isValidProcess(Unit* hatedUnit, Unit* hatingUnit, SpellInfo const* threatSpell = nullptr); }; //============================================================== @@ -54,11 +54,11 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager> //================================================= void addThreat(float modThreat); - void setThreat(float threat) { addThreat(threat - getThreat()); } + void setThreat(float threat) { addThreat(threat - iThreat); } void addThreatPercent(int32 percent); - float getThreat() const { return iThreat; } + float getThreat() const { return iThreat + iTempThreatModifier; } bool isOnline() const { return iOnline; } @@ -66,27 +66,27 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager> // in this case online = true, but accessible = false bool isAccessible() const { return iAccessible; } - // used for temporary setting a threat and reducting it later again. + // used for temporary setting a threat and reducing it later again. // the threat modification is stored void setTempThreat(float threat) { - addTempThreat(threat - getThreat()); + addTempThreat(threat - iTempThreatModifier); } void addTempThreat(float threat) { - iTempThreatModifier = threat; - if (iTempThreatModifier != 0.0f) - addThreat(iTempThreatModifier); + if (!threat) + return; + + iTempThreatModifier += threat; + + ThreatRefStatusChangeEvent event(UEV_THREAT_REF_THREAT_CHANGE, this, threat); + fireStatusChanged(event); } void resetTempThreat() { - if (iTempThreatModifier != 0.0f) - { - addThreat(-iTempThreatModifier); - iTempThreatModifier = 0.0f; - } + addTempThreat(-iTempThreatModifier); } float getTempThreatModifier() { return iTempThreatModifier; } @@ -100,7 +100,7 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager> void setAccessibleState(bool isAccessible); //================================================= - bool operator == (const HostileReference& hostileRef) const { return hostileRef.getUnitGuid() == getUnitGuid(); } + bool operator==(HostileReference const& hostileRef) const { return hostileRef.getUnitGuid() == getUnitGuid(); } //================================================= @@ -113,7 +113,7 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager> //================================================= - HostileReference* next() { return ((HostileReference*) Reference<Unit, ThreatManager>::next()); } + HostileReference* next() { return static_cast<HostileReference*>(Reference<Unit, ThreatManager>::next()); } //================================================= @@ -125,14 +125,17 @@ class TC_GAME_API HostileReference : public Reference<Unit, ThreatManager> // Tell our refFrom (source) object, that the link is cut (Target destroyed) void sourceObjectDestroyLink() override; + private: // Inform the source, that the status of that reference was changed void fireStatusChanged(ThreatRefStatusChangeEvent& threatRefStatusChangeEvent); Unit* GetSourceUnit(); + private: float iThreat; - float iTempThreatModifier; // used for taunt + float iTempThreatModifier; // used for SPELL_AURA_MOD_TOTAL_THREAT + ObjectGuid iUnitGuid; bool iOnline; bool iAccessible; diff --git a/src/server/game/Combat/UnitEvents.h b/src/server/game/Combat/UnitEvents.h index f50edcf3c7d..ee1a960c524 100644 --- a/src/server/game/Combat/UnitEvents.h +++ b/src/server/game/Combat/UnitEvents.h @@ -40,7 +40,7 @@ enum UNIT_EVENT_TYPE UEV_THREAT_REF_REMOVE_FROM_LIST = 1<<2, // Player/Pet entered/left water or some other place where it is/was not accessible for the creature - UEV_THREAT_REF_ASSECCIBLE_STATUS = 1<<3, + UEV_THREAT_REF_ACCESSIBLE_STATUS = 1<<3, // Threat list is going to be sorted (if dirty flag is set) UEV_THREAT_SORT_LIST = 1<<4, @@ -58,7 +58,7 @@ enum UNIT_EVENT_TYPE //UEV_UNIT_HEALTH_CHANGE = 1<<8, }; -#define UEV_THREAT_REF_EVENT_MASK (UEV_THREAT_REF_ONLINE_STATUS | UEV_THREAT_REF_THREAT_CHANGE | UEV_THREAT_REF_REMOVE_FROM_LIST | UEV_THREAT_REF_ASSECCIBLE_STATUS) +#define UEV_THREAT_REF_EVENT_MASK (UEV_THREAT_REF_ONLINE_STATUS | UEV_THREAT_REF_THREAT_CHANGE | UEV_THREAT_REF_REMOVE_FROM_LIST | UEV_THREAT_REF_ACCESSIBLE_STATUS) #define UEV_THREAT_MANAGER_EVENT_MASK (UEV_THREAT_SORT_LIST | UEV_THREAT_SET_NEXT_TARGET | UEV_THREAT_VICTIM_CHANGED) #define UEV_ALL_EVENT_MASK (0xffffffff) @@ -69,14 +69,16 @@ enum UNIT_EVENT_TYPE class UnitBaseEvent { - private: - uint32 iType; public: - UnitBaseEvent(uint32 pType) { iType = pType; } + explicit UnitBaseEvent(uint32 pType) { iType = pType; } uint32 getType() const { return iType; } bool matchesTypeMask(uint32 pMask) const { return (iType & pMask) != 0; } - void setType(uint32 pType) { iType = pType; } + private: + uint32 iType; + + protected: + ~UnitBaseEvent() { } }; //============================================================== @@ -92,14 +94,15 @@ class TC_GAME_API ThreatRefStatusChangeEvent : public UnitBaseEvent bool iBValue; }; ThreatManager* iThreatManager; + public: - ThreatRefStatusChangeEvent(uint32 pType) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = NULL; } + explicit ThreatRefStatusChangeEvent(uint32 pType) : UnitBaseEvent(pType), iHostileReference(nullptr), iThreatManager(nullptr) { } - ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; } + ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iThreatManager(nullptr) { } - ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, float pValue) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; iFValue = pValue; } + ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, float pValue) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iFValue(pValue), iThreatManager(nullptr) { } - ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, bool pValue) : UnitBaseEvent(pType), iThreatManager(NULL) { iHostileReference = pHostileReference; iBValue = pValue; } + ThreatRefStatusChangeEvent(uint32 pType, HostileReference* pHostileReference, bool pValue) : UnitBaseEvent(pType), iHostileReference(pHostileReference), iBValue(pValue), iThreatManager(nullptr) { } int32 getIValue() const { return iIValue; } @@ -116,20 +119,4 @@ class TC_GAME_API ThreatRefStatusChangeEvent : public UnitBaseEvent ThreatManager* getThreatManager() const { return iThreatManager; } }; -//============================================================== - -class ThreatManagerEvent : public ThreatRefStatusChangeEvent -{ - private: - ThreatContainer* iThreatContainer; - public: - ThreatManagerEvent(uint32 pType) : ThreatRefStatusChangeEvent(pType), iThreatContainer(NULL) { } - ThreatManagerEvent(uint32 pType, HostileReference* pHostileReference) : ThreatRefStatusChangeEvent(pType, pHostileReference), iThreatContainer(NULL) { } - - void setThreatContainer(ThreatContainer* pThreatContainer) { iThreatContainer = pThreatContainer; } - - ThreatContainer* getThreatContainer() const { return iThreatContainer; } -}; - -//============================================================== #endif diff --git a/src/server/game/Grids/GridRefManager.h b/src/server/game/Grids/GridRefManager.h index 755417d873d..ceaf632aa63 100644 --- a/src/server/game/Grids/GridRefManager.h +++ b/src/server/game/Grids/GridRefManager.h @@ -35,8 +35,6 @@ class GridRefManager : public RefManager<GridRefManager<OBJECT>, OBJECT> iterator begin() { return iterator(getFirst()); } iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } }; #endif diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index a66b8f0b4c5..bca5cde1fa5 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -271,13 +271,13 @@ class TC_GAME_API LootTemplate LootGroups Groups; // groups have own (optimised) processing, grouped entries go there // Objects of this class must never be copied, we are storing pointers in container - LootTemplate(LootTemplate const&); - LootTemplate& operator=(LootTemplate const&); + LootTemplate(LootTemplate const&) = delete; + LootTemplate& operator=(LootTemplate const&) = delete; }; //===================================================== -class LootValidatorRef : public Reference<Loot, LootValidatorRef> +class LootValidatorRef : public Reference<Loot, LootValidatorRef> { public: LootValidatorRef() { } @@ -293,12 +293,9 @@ class LootValidatorRefManager : public RefManager<Loot, LootValidatorRef> typedef LinkedListHead::Iterator< LootValidatorRef > iterator; LootValidatorRef* getFirst() { return (LootValidatorRef*)RefManager<Loot, LootValidatorRef>::getFirst(); } - LootValidatorRef* getLast() { return (LootValidatorRef*)RefManager<Loot, LootValidatorRef>::getLast(); } iterator begin() { return iterator(getFirst()); } - iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } + iterator end() { return iterator(nullptr); } }; //===================================================== diff --git a/src/server/game/Maps/MapRefManager.h b/src/server/game/Maps/MapRefManager.h index 09aa67d43eb..14d1d59bd36 100644 --- a/src/server/game/Maps/MapRefManager.h +++ b/src/server/game/Maps/MapRefManager.h @@ -26,20 +26,17 @@ class MapReference; class MapRefManager : public RefManager<Map, Player> { public: - typedef LinkedListHead::Iterator< MapReference > iterator; - typedef LinkedListHead::Iterator< MapReference const > const_iterator; + typedef LinkedListHead::Iterator<MapReference> iterator; + typedef LinkedListHead::Iterator<MapReference const> const_iterator; - MapReference* getFirst() { return (MapReference*)RefManager<Map, Player>::getFirst(); } + MapReference* getFirst() { return (MapReference*)RefManager<Map, Player>::getFirst(); } MapReference const* getFirst() const { return (MapReference const*)RefManager<Map, Player>::getFirst(); } - MapReference* getLast() { return (MapReference*)RefManager<Map, Player>::getLast(); } - MapReference const* getLast() const { return (MapReference const*)RefManager<Map, Player>::getLast(); } iterator begin() { return iterator(getFirst()); } - iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } + iterator end() { return iterator(nullptr); } + const_iterator begin() const { return const_iterator(getFirst()); } - const_iterator end() const { return const_iterator(NULL); } + const_iterator end() const { return const_iterator(nullptr); } }; #endif diff --git a/src/server/shared/Dynamic/LinkedList.h b/src/server/shared/Dynamic/LinkedList.h index 94f67cac909..1c99144db0e 100644 --- a/src/server/shared/Dynamic/LinkedList.h +++ b/src/server/shared/Dynamic/LinkedList.h @@ -32,18 +32,18 @@ class LinkedListElement LinkedListElement* iNext; LinkedListElement* iPrev; + public: - LinkedListElement() : iNext(NULL), iPrev(NULL) { } - virtual ~LinkedListElement() { delink(); } + LinkedListElement() : iNext(nullptr), iPrev(nullptr) { } - bool hasNext() const { return(iNext && iNext->iNext != NULL); } - bool hasPrev() const { return(iPrev && iPrev->iPrev != NULL); } - bool isInList() const { return(iNext != NULL && iPrev != NULL); } + bool hasNext() const { return (iNext && iNext->iNext != nullptr); } + bool hasPrev() const { return (iPrev && iPrev->iPrev != nullptr); } + bool isInList() const { return (iNext != nullptr && iPrev != nullptr); } - LinkedListElement * next() { return hasNext() ? iNext : NULL; } - LinkedListElement const* next() const { return hasNext() ? iNext : NULL; } - LinkedListElement * prev() { return hasPrev() ? iPrev : NULL; } - LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; } + LinkedListElement * next() { return hasNext() ? iNext : nullptr; } + LinkedListElement const* next() const { return hasNext() ? iNext : nullptr; } + LinkedListElement * prev() { return hasPrev() ? iPrev : nullptr; } + LinkedListElement const* prev() const { return hasPrev() ? iPrev : nullptr; } LinkedListElement * nocheck_next() { return iNext; } LinkedListElement const* nocheck_next() const { return iNext; } @@ -52,10 +52,13 @@ class LinkedListElement void delink() { - if (isInList()) - { - iNext->iPrev = iPrev; iPrev->iNext = iNext; iNext = NULL; iPrev = NULL; - } + if (!isInList()) + return; + + iNext->iPrev = iPrev; + iPrev->iNext = iNext; + iNext = nullptr; + iPrev = nullptr; } void insertBefore(LinkedListElement* pElem) @@ -75,8 +78,14 @@ class LinkedListElement } private: - LinkedListElement(LinkedListElement const&); - LinkedListElement& operator=(LinkedListElement const&); + LinkedListElement(LinkedListElement const&) = delete; + LinkedListElement& operator=(LinkedListElement const&) = delete; + + protected: + ~LinkedListElement() + { + delink(); + } }; //============================================ @@ -97,15 +106,13 @@ class LinkedListHead iLast.iPrev = &iFirst; } - virtual ~LinkedListHead() { } - bool isEmpty() const { return(!iFirst.iNext->isInList()); } - LinkedListElement * getFirst() { return(isEmpty() ? NULL : iFirst.iNext); } - LinkedListElement const* getFirst() const { return(isEmpty() ? NULL : iFirst.iNext); } + LinkedListElement * getFirst() { return (isEmpty() ? nullptr : iFirst.iNext); } + LinkedListElement const* getFirst() const { return (isEmpty() ? nullptr : iFirst.iNext); } - LinkedListElement * getLast() { return(isEmpty() ? NULL : iLast.iPrev); } - LinkedListElement const* getLast() const { return(isEmpty() ? NULL : iLast.iPrev); } + LinkedListElement * getLast() { return(isEmpty() ? nullptr : iLast.iPrev); } + LinkedListElement const* getLast() const { return(isEmpty() ? nullptr : iLast.iPrev); } void insertFirst(LinkedListElement* pElem) { @@ -248,8 +255,11 @@ class LinkedListHead typedef Iterator<LinkedListElement> iterator; private: - LinkedListHead(LinkedListHead const&); - LinkedListHead& operator=(LinkedListHead const&); + LinkedListHead(LinkedListHead const&) = delete; + LinkedListHead& operator=(LinkedListHead const&) = delete; + + protected: + ~LinkedListHead() { } }; //============================================ diff --git a/src/server/shared/Dynamic/LinkedReference/RefManager.h b/src/server/shared/Dynamic/LinkedReference/RefManager.h index 9dbab4f338e..3c716e3c6b7 100644 --- a/src/server/shared/Dynamic/LinkedReference/RefManager.h +++ b/src/server/shared/Dynamic/LinkedReference/RefManager.h @@ -23,31 +23,29 @@ #include "Dynamic/LinkedList.h" #include "Dynamic/LinkedReference/Reference.h" -template <class TO, class FROM> class RefManager : public LinkedListHead +template <class TO, class FROM> +class RefManager : public LinkedListHead { public: - typedef LinkedListHead::Iterator< Reference<TO, FROM> > iterator; + typedef LinkedListHead::Iterator<Reference<TO, FROM>> iterator; RefManager() { } - virtual ~RefManager() { clearReferences(); } - Reference<TO, FROM>* getFirst() { return ((Reference<TO, FROM>*) LinkedListHead::getFirst()); } - Reference<TO, FROM> const* getFirst() const { return ((Reference<TO, FROM> const*) LinkedListHead::getFirst()); } - Reference<TO, FROM>* getLast() { return ((Reference<TO, FROM>*) LinkedListHead::getLast()); } - Reference<TO, FROM> const* getLast() const { return ((Reference<TO, FROM> const*) LinkedListHead::getLast()); } + Reference<TO, FROM>* getFirst() { return static_cast<Reference<TO, FROM>*>(LinkedListHead::getFirst()); } + + Reference<TO, FROM> const* getFirst() const { return static_cast<Reference<TO, FROM> const*>(LinkedListHead::getFirst()); } iterator begin() { return iterator(getFirst()); } - iterator end() { return iterator(NULL); } - iterator rbegin() { return iterator(getLast()); } - iterator rend() { return iterator(NULL); } + iterator end() { return iterator(nullptr); } + + virtual ~RefManager() + { + clearReferences(); + } void clearReferences() { - LinkedListElement* ref; - while ((ref = getFirst()) != NULL) - { - ((Reference<TO, FROM>*) ref)->invalidate(); - ref->delink(); // the delink might be already done by invalidate(), but doing it here again does not hurt and insures an empty list - } + while (Reference<TO, FROM>* ref = getFirst()) + ref->invalidate(); } }; diff --git a/src/server/shared/Dynamic/LinkedReference/Reference.h b/src/server/shared/Dynamic/LinkedReference/Reference.h index 4a473b0f2ac..0dcf91fb052 100644 --- a/src/server/shared/Dynamic/LinkedReference/Reference.h +++ b/src/server/shared/Dynamic/LinkedReference/Reference.h @@ -29,6 +29,7 @@ template <class TO, class FROM> class Reference : public LinkedListElement private: TO* iRefTo; FROM* iRefFrom; + protected: // Tell our refTo (target) object that we have a link virtual void targetObjectBuildLink() = 0; @@ -90,14 +91,14 @@ template <class TO, class FROM> class Reference : public LinkedListElement Reference<TO, FROM> * nocheck_prev() { return((Reference<TO, FROM> *) LinkedListElement::nocheck_prev()); } Reference<TO, FROM> const* nocheck_prev() const { return((Reference<TO, FROM> const*) LinkedListElement::nocheck_prev()); } - TO* operator ->() const { return iRefTo; } + TO* operator->() const { return iRefTo; } TO* getTarget() const { return iRefTo; } FROM* GetSource() const { return iRefFrom; } private: - Reference(Reference const&); - Reference& operator=(Reference const&); + Reference(Reference const&) = delete; + Reference& operator=(Reference const&) = delete; }; //===================================================== |