From f31cfa0b1146919472e22ec97e0119e5e5ec5ffa Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Sat, 29 Jul 2017 11:49:34 +0800 Subject: [PATCH] Add ResourceHandler --- SDLWrapper/_handler.cpp | 1 + SDLWrapper/_handler.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 SDLWrapper/_handler.cpp create mode 100644 SDLWrapper/_handler.h diff --git a/SDLWrapper/_handler.cpp b/SDLWrapper/_handler.cpp new file mode 100644 index 0000000..8db72c7 --- /dev/null +++ b/SDLWrapper/_handler.cpp @@ -0,0 +1 @@ +#include "_handler.h" diff --git a/SDLWrapper/_handler.h b/SDLWrapper/_handler.h new file mode 100644 index 0000000..7782d5e --- /dev/null +++ b/SDLWrapper/_handler.h @@ -0,0 +1,38 @@ +#pragma once +#include + +namespace MiniEngine +{ + +class ResourceHandler +{ +public: + using RawDeleter = std::function; + + template + ResourceHandler(T* ResourcePtr,RawDeleter RawDelFunc) : + _ptr(ResourcePtr), + _delfunc(RawDelFunc) {} + + ~ResourceHandler() + { + _delfunc(_ptr); + } + + template + T* get() const + { + return (T*)(_ptr); + } + + template + const T* cget() const + { + return (const T*)(_ptr); + } +private: + void* _ptr; + RawDeleter _delfunc; +}; + +}/// End of namespace MiniEngine