mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 05:06:24 +00:00
Implement data storage for Entitiies (#748)
This commit is contained in:
34
src/common/Utilities/DataMap.h
Normal file
34
src/common/Utilities/DataMap.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Originally written by Rochet2 - Copyright (C) 2018+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-AGPL
|
||||
*/
|
||||
|
||||
#ifndef _DATA_MAP_H_
|
||||
#define _DATA_MAP_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
class DataMap
|
||||
{
|
||||
public:
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() = default;
|
||||
};
|
||||
|
||||
template<class T> T* GetCustomData(std::string const & k) const {
|
||||
static_assert(std::is_base_of<Base, T>::value, "T must derive from Base");
|
||||
auto it = Container.find(k);
|
||||
if (it != Container.end())
|
||||
return dynamic_cast<T*>(it->second.get());
|
||||
return nullptr;
|
||||
}
|
||||
void SetCustomData(std::string const & k, Base* v) { Container[k] = std::unique_ptr<Base>(v); }
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<Base>> Container;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#define _OBJECT_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "DataMap.h"
|
||||
#include "UpdateMask.h"
|
||||
#include "UpdateData.h"
|
||||
#include "GridReference.h"
|
||||
@@ -318,6 +319,8 @@ class Object
|
||||
DynamicObject* ToDynObject() { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject*>(this); else return NULL; }
|
||||
DynamicObject const* ToDynObject() const { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast<DynamicObject const*>(this); else return NULL; }
|
||||
|
||||
DataMap DataMap;
|
||||
|
||||
protected:
|
||||
|
||||
Object();
|
||||
|
||||
Reference in New Issue
Block a user