AzeorthCore 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
59{
60 std::shared_lock<std::shared_mutex> lock(*GetLock());
61
62 typename MapType::iterator itr = GetContainer().find(guid);
63 return (itr != GetContainer().end()) ? itr->second : nullptr;
64}
static std::shared_mutex * GetLock()
Definition: ObjectAccessor.cpp:74
static MapType & GetContainer()
Definition: ObjectAccessor.cpp:67

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

◆ GetContainer()

template<class T >
auto HashMapHolder< T >::GetContainer
static
68{
69 static MapType _objectMap;
70 return _objectMap;
71}
std::unordered_map< ObjectGuid, T * > MapType
Definition: ObjectAccessor.h:51

Referenced by ObjectAccessor::GetPlayers().

◆ GetLock()

template<class T >
std::shared_mutex * HashMapHolder< T >::GetLock
static
75{
76 static std::shared_mutex _lock;
77 return &_lock;
78}

◆ Insert()

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

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

◆ Remove()

template<class T >
void HashMapHolder< T >::Remove ( T *  o)
static
51{
52 std::unique_lock<std::shared_mutex> lock(*GetLock());
53
54 GetContainer().erase(o->GetGUID());
55}

Referenced by ObjectAccessor::RemoveObject().