AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SafeUnitPointer Class Reference

#include "Unit.h"

Public Member Functions

 SafeUnitPointer (Unit *defVal)
 
 SafeUnitPointer (const SafeUnitPointer &)
 
void Initialize (Unit *defVal)
 
 ~SafeUnitPointer ()
 
void SetPointedTo (Unit *u)
 
void UnitDeleted ()
 
Unitoperator-> () const
 
void operator= (Unit *u)
 
 operator Unit * () const
 

Private Attributes

Unitptr
 
UnitdefaultValue
 

Detailed Description

Constructor & Destructor Documentation

◆ SafeUnitPointer() [1/2]

SafeUnitPointer::SafeUnitPointer ( Unit defVal)
inlineexplicit
1287: ptr(defVal), defaultValue(defVal) {}
Unit * defaultValue
Definition: Unit.h:1298
Unit * ptr
Definition: Unit.h:1297

◆ SafeUnitPointer() [2/2]

SafeUnitPointer::SafeUnitPointer ( const SafeUnitPointer )
inline
1288{ ABORT(); }
#define ABORT
Definition: Errors.h:76

References ABORT.

◆ ~SafeUnitPointer()

SafeUnitPointer::~SafeUnitPointer ( )
4248{
4249 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4250 ptr = defaultValue;
4251}
void RemovePointedBy(SafeUnitPointer *sup)
Definition: Unit.h:2420

References defaultValue, ptr, and Unit::RemovePointedBy().

Member Function Documentation

◆ Initialize()

void SafeUnitPointer::Initialize ( Unit defVal)
inline
1289{ defaultValue = defVal; ptr = defVal; }

References defaultValue, and ptr.

Referenced by Player::Player().

◆ operator Unit *()

SafeUnitPointer::operator Unit * ( ) const
inline
1295{ return ptr; }

References ptr.

◆ operator->()

Unit * SafeUnitPointer::operator-> ( ) const
inline
1293{ return ptr; }

References ptr.

◆ operator=()

void SafeUnitPointer::operator= ( Unit u)
inline
1294{ SetPointedTo(u); }
void SetPointedTo(Unit *u)
Definition: Unit.cpp:4253

References SetPointedTo().

◆ SetPointedTo()

void SafeUnitPointer::SetPointedTo ( Unit u)
4254{
4255 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4256 ptr = u;
4257 if (ptr != defaultValue && ptr) ptr->AddPointedBy(this);
4258}
void AddPointedBy(SafeUnitPointer *sup)
Definition: Unit.h:2419

References Unit::AddPointedBy(), defaultValue, ptr, and Unit::RemovePointedBy().

Referenced by operator=().

◆ UnitDeleted()

void SafeUnitPointer::UnitDeleted ( )
4261{
4262 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted !!!");
4263 if (defaultValue)
4264 {
4265 if (Player* p = defaultValue->ToPlayer())
4266 {
4267 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A1) - {}, {}, {}, {}, {}, {}, {}, {}",
4268 p->GetGUID().ToString(), p->GetMapId(), p->GetInstanceId(), p->FindMap()->GetId(), p->IsInWorld() ? 1 : 0, p->IsDuringRemoveFromWorld() ? 1 : 0, p->IsBeingTeleported() ? 1 : 0, p->isBeingLoaded() ? 1 : 0);
4269 if (ptr)
4270 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A2)");
4271
4272 p->GetSession()->KickPlayer("Unit deleted");
4273 }
4274 }
4275 else if (ptr)
4276 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (B1)");
4277
4278 ptr = defaultValue;
4279}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
Player * ToPlayer()
Definition: Object.h:195
Definition: Player.h:1056

References defaultValue, LOG_INFO, ptr, and Object::ToPlayer().

Member Data Documentation

◆ defaultValue

Unit* SafeUnitPointer::defaultValue
private

◆ ptr

Unit* SafeUnitPointer::ptr
private