Remove resource handler.

We decide to use shared_ptr instead. And we will treat a resource class
as a reference. (instead of object)
This commit is contained in:
Kirigaya Kazuto 2017-11-05 18:44:14 +08:00
parent 386c4633e7
commit 002617a557
6 changed files with 9 additions and 77 deletions

View File

@ -23,7 +23,7 @@ SDL_Cursor* Cursor::_get()
//private
void Cursor::_clear()
{
_cur.release();
_cur.reset();
}
Cursor::Cursor(Surface surf,Point hotspot)

View File

@ -1,14 +1,14 @@
#pragma once
#include "include.h"
#include "__Noncopyable.h"
#include "_handler.h"
#include "_SystemCursorType.h"
#include "Point.h"
#include "Surface.h"
#include "__Plugin.h"
#include <memory>
namespace MiniEngine
{
class Cursor : public NonCopyable
class Cursor
{
public:
Cursor()=default;
@ -25,7 +25,7 @@ public:
void release();
private:
res_ptr<SDL_Cursor> _cur;
std::shared_ptr<SDL_Cursor> _cur;
void _set(SDL_Cursor*);
void _set_no_delete(SDL_Cursor*);

View File

@ -10,7 +10,7 @@ void Font::_set(TTF_Font* p)
// private
void Font::_clear()
{
_font.release();
_font.reset();
}
// private
TTF_Font* Font::_get() const

View File

@ -9,10 +9,9 @@
#include <vector>
#include "__Plugin.h"
#include "__Noncopyable.h"
#include "_handler.h"
namespace MiniEngine
{
class Font : public NonCopyable
class Font
{
public:
Font() = default;
@ -118,7 +117,7 @@ private:
void _real_setFontStyle(int);
int _style_caster(FontStyle);
res_ptr<TTF_Font> _font;
std::shared_ptr<TTF_Font> _font;
void _set(TTF_Font*);
void _clear();

View File

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

View File

@ -1,66 +0,0 @@
#pragma once
#include <functional>
namespace MiniEngine
{
template<typename T>
class res_ptr
{
public:
res_ptr() : _ptr(nullptr) {}
res_ptr(T* ptr,const std::function<void(T*)>& delFunc) : _ptr(ptr), _delfunc(delFunc) {}
res_ptr(const res_ptr&)=delete;
res_ptr& operator = (const res_ptr&)=delete;
res_ptr(res_ptr&& t)
{
_ptr=t._ptr;
_delfunc=t._delfunc;
t._ptr=nullptr;
}
res_ptr& operator = (res_ptr&& t)
{
release();
_ptr=t._ptr;
_delfunc=t._delfunc;
t._ptr=nullptr;
return *this;
}
~res_ptr()
{
release();
}
void release()
{
if(_ptr)
{
_delfunc(_ptr);
_ptr=nullptr;
}
}
void reset(T* ptr,const std::function<void(T*)>& delFunc)
{
release();
_ptr=ptr;
_delfunc=delFunc;
}
T* get()
{
return _ptr;
}
const T* get() const
{
return _ptr;
}
T* operator -> ()
{
return _ptr;
}
private:
T* _ptr;
std::function<void(T*)> _delfunc;
};
}/// End of namespace MiniEngine