Add ResourceHandler

This commit is contained in:
Kirigaya Kazuto 2017-07-29 11:49:34 +08:00
parent dd88f8b4b1
commit f31cfa0b11
2 changed files with 39 additions and 0 deletions

1
SDLWrapper/_handler.cpp Normal file
View File

@ -0,0 +1 @@
#include "_handler.h"

38
SDLWrapper/_handler.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include <functional>
namespace MiniEngine
{
class ResourceHandler
{
public:
using RawDeleter = std::function<void(void*)>;
template<typename T>
ResourceHandler(T* ResourcePtr,RawDeleter RawDelFunc) :
_ptr(ResourcePtr),
_delfunc(RawDelFunc) {}
~ResourceHandler()
{
_delfunc(_ptr);
}
template<typename T>
T* get() const
{
return (T*)(_ptr);
}
template<typename T>
const T* cget() const
{
return (const T*)(_ptr);
}
private:
void* _ptr;
RawDeleter _delfunc;
};
}/// End of namespace MiniEngine