mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add ResourceHandler
This commit is contained in:
parent
dd88f8b4b1
commit
f31cfa0b11
1
SDLWrapper/_handler.cpp
Normal file
1
SDLWrapper/_handler.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "_handler.h"
|
38
SDLWrapper/_handler.h
Normal file
38
SDLWrapper/_handler.h
Normal 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
|
Loading…
Reference in New Issue
Block a user