AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
HashMapHolder< T > Class Template Reference

#include "ObjectAccessor.h"

Public Types

typedef std::unordered_map< ObjectGuid, T * > MapType
 

Static Public Member Functions

static void Insert (T *o)
 
static void Remove (T *o)
 
static T * Find (ObjectGuid guid)
 
static MapTypeGetContainer ()
 
static std::shared_mutex * GetLock ()
 

Private Member Functions

 HashMapHolder ()=default
 

Detailed Description

template<class T>
class HashMapHolder< T >

Member Typedef Documentation

◆ MapType

template<class T >
typedef std::unordered_map<ObjectGuid, T*> HashMapHolder< T >::MapType

Constructor & Destructor Documentation

◆ HashMapHolder()

template<class T >
HashMapHolder< T >::HashMapHolder ( )
privatedefault

Member Function Documentation

◆ Find()

template<class T >
T * HashMapHolder< T >::Find ( ObjectGuid  guid)
static
54{
55 std::shared_lock<std::shared_mutex> lock(*GetLock());
56
57 typename MapType::iterator itr = GetContainer().find(guid);
58 return (itr != GetContainer().end()) ? itr->second : nullptr;
59}
static std::shared_mutex * GetLock()
Definition: ObjectAccessor.cpp:69
static MapType & GetContainer()
Definition: ObjectAccessor.cpp:62

Referenced by ObjectAccessor::FindConnectedPlayer(), ObjectAccessor::FindPlayer(), WorldSession::HandleRequestPartyMemberStatsOpcode(), Player::LoadFromDB(), Player::Satisfy(), and Map::ScriptsProcess().

◆ GetContainer()

template<class T >
auto HashMapHolder< T >::GetContainer
static
63{
64 static MapType _objectMap;
65 return _objectMap;
66}
std::unordered_map< ObjectGuid, T * > MapType
Definition: ObjectAccessor.h:47

Referenced by ObjectAccessor::GetPlayers().

◆ GetLock()

template<class T >
std::shared_mutex * HashMapHolder< T >::GetLock
static
70{
71 static std::shared_mutex _lock;
72 return &_lock;
73}

◆ Insert()

template<class T >
void HashMapHolder< T >::Insert ( T *  o)
static
34{
35 static_assert(std::is_same<Player, T>::value
36 || std::is_same<MotionTransport, T>::value,
37 "Only Player and Motion Transport can be registered in global HashMapHolder");
38
39 std::unique_lock<std::shared_mutex> lock(*GetLock());
40
41 GetContainer()[o->GetGUID()] = o;
42}

Referenced by ObjectAccessor::AddObject(), and TransportMgr::CreateTransport().

◆ Remove()

template<class T >
void HashMapHolder< T >::Remove ( T *  o)
static
46{
47 std::unique_lock<std::shared_mutex> lock(*GetLock());
48
49 GetContainer().erase(o->GetGUID());
50}

Referenced by ObjectAccessor::RemoveObject(), and MotionTransport::~MotionTransport().