diff --git a/src/common/Utilities/DataMap.h b/src/common/Utilities/DataMap.h new file mode 100644 index 000000000..75e8b7555 --- /dev/null +++ b/src/common/Utilities/DataMap.h @@ -0,0 +1,34 @@ +/* + * Originally written by Rochet2 - Copyright (C) 2018+ AzerothCore , released under GNU AGPL v3 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-AGPL + */ + +#ifndef _DATA_MAP_H_ +#define _DATA_MAP_H_ + +#include +#include +#include + +class DataMap +{ +public: + class Base + { + public: + virtual ~Base() = default; + }; + + template T* GetCustomData(std::string const & k) const { + static_assert(std::is_base_of::value, "T must derive from Base"); + auto it = Container.find(k); + if (it != Container.end()) + return dynamic_cast(it->second.get()); + return nullptr; + } + void SetCustomData(std::string const & k, Base* v) { Container[k] = std::unique_ptr(v); } + +private: + std::unordered_map> Container; +}; + +#endif diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 68b8bda28..7a6a989c2 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -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(this); else return NULL; } DynamicObject const* ToDynObject() const { if (GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast(this); else return NULL; } + DataMap DataMap; + protected: Object();