AzerothCore 3.3.5a
OpenSource WoW Emulator
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SafeUnitPointer Class Reference

#include "UnitUtils.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
49: ptr(defVal), defaultValue(defVal) {}
Unit * defaultValue
Definition UnitUtils.h:60
Unit * ptr
Definition UnitUtils.h:59

◆ SafeUnitPointer() [2/2]

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

References ABORT.

◆ ~SafeUnitPointer()

SafeUnitPointer::~SafeUnitPointer ( )
4329{
4330 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4331 ptr = defaultValue;
4332}
void RemovePointedBy(SafeUnitPointer *sup)
Definition Unit.h:1942

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

Member Function Documentation

◆ Initialize()

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

References defaultValue, and ptr.

Referenced by Player::Player().

◆ operator Unit *()

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

References ptr.

◆ operator->()

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

References ptr.

◆ operator=()

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

References SetPointedTo().

◆ SetPointedTo()

void SafeUnitPointer::SetPointedTo ( Unit u)
4335{
4336 if (ptr != defaultValue && ptr) ptr->RemovePointedBy(this);
4337 ptr = u;
4338 if (ptr != defaultValue && ptr) ptr->AddPointedBy(this);
4339}
void AddPointedBy(SafeUnitPointer *sup)
Definition Unit.h:1941

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

Referenced by operator=().

◆ UnitDeleted()

void SafeUnitPointer::UnitDeleted ( )
4342{
4343 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted !!!");
4344 if (defaultValue)
4345 {
4346 if (Player* p = defaultValue->ToPlayer())
4347 {
4348 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A1) - {}, {}, {}, {}, {}, {}, {}, {}",
4349 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);
4350 if (ptr)
4351 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (A2)");
4352
4353 p->GetSession()->KickPlayer("Unit deleted");
4354 }
4355 }
4356 else if (ptr)
4357 LOG_INFO("misc", "SafeUnitPointer::UnitDeleted (B1)");
4358
4359 ptr = defaultValue;
4360}
#define LOG_INFO(filterType__,...)
Definition Log.h:165
Player * ToPlayer()
Definition Object.h:202
Definition Player.h:1082

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

Member Data Documentation

◆ defaultValue

Unit* SafeUnitPointer::defaultValue
private

◆ ptr

Unit* SafeUnitPointer::ptr
private

The documentation for this class was generated from the following files: