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

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

◆ GetContainer()

template<class T >
auto HashMapHolder< T >::GetContainer
static
66{
67 static MapType _objectMap;
68 return _objectMap;
69}
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
73{
74 static std::shared_mutex _lock;
75 return &_lock;
76}

◆ Insert()

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

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

◆ Remove()

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

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