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
1275: ptr(defVal), defaultValue(defVal) {}
Unit * defaultValue
Definition: Unit.h:1286
Unit * ptr
Definition: Unit.h:1285

◆ SafeUnitPointer() [2/2]

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

References ABORT.

◆ ~SafeUnitPointer()

SafeUnitPointer::~SafeUnitPointer ( )
4236{
4237 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4238 ptr = defaultValue;
4239}
void RemovePointedBy(SafeUnitPointer *sup)
Definition: Unit.h:2406

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

Member Function Documentation

◆ Initialize()

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

References defaultValue, and ptr.

Referenced by Player::Player().

◆ operator Unit *()

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

References ptr.

◆ operator->()

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

References ptr.

◆ operator=()

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

References SetPointedTo().

◆ SetPointedTo()

void SafeUnitPointer::SetPointedTo ( Unit u)
4242{
4243 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4244 ptr = u;
4245 if (ptr != defaultValue && ptr) ptr->AddPointedBy(this);
4246}
void AddPointedBy(SafeUnitPointer *sup)
Definition: Unit.h:2405

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

Referenced by operator=().

◆ UnitDeleted()

void SafeUnitPointer::UnitDeleted ( )
4249{
4250 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted !!!");
4251 if (defaultValue)
4252 {
4253 if (Player* p = defaultValue->ToPlayer())
4254 {
4255 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A1) - {}, {}, {}, {}, {}, {}, {}, {}",
4256 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);
4257 if (ptr)
4258 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A2)");
4259
4260 p->GetSession()->KickPlayer("Unit deleted");
4261 }
4262 }
4263 else if (ptr)
4264 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (B1)");
4265
4266 ptr = defaultValue;
4267}
#define LOG_INFO(filterType__,...)
Definition: Log.h:167
Player * ToPlayer()
Definition: Object.h:195
Definition: Player.h:1046

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

Member Data Documentation

◆ defaultValue

Unit* SafeUnitPointer::defaultValue
private

◆ ptr

Unit* SafeUnitPointer::ptr
private