57 lines
772 B
C++
57 lines
772 B
C++
#ifndef resource_ptr_h__
|
|||
|
|
#define resource_ptr_h__
|
||
|
|
|
||
|
|
namespace LifeGraphics
|
||
|
|
{
|
||
|
|
template<typename T>
|
||
|
|
class resource_ptr
|
||
|
|
{
|
||
|
|
protected:
|
||
|
|
T* _ptr;
|
||
|
|
int _refCount;
|
||
|
|
public:
|
||
|
|
resource_ptr()
|
||
|
|
:_refCount(0), _ptr(0)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
resource_ptr(T* ptr)
|
||
|
|
:_refCount(0), _ptr(0)
|
||
|
|
{
|
||
|
|
_ptr = ptr;
|
||
|
|
//touch();
|
||
|
|
}
|
||
|
|
|
||
|
|
~resource_ptr(){}
|
||
|
|
T* ptr() {return _ptr;}
|
||
|
|
void resetPtr(T* ptr)
|
||
|
|
{
|
||
|
|
_refCount = 0;
|
||
|
|
_ptr = ptr;
|
||
|
|
// touch();
|
||
|
|
}
|
||
|
|
|
||
|
|
resource_ptr<T>& operator=(const resource_ptr<T>& ptr) {
|
||
|
|
//release();
|
||
|
|
_ptr = ptr._ptr;
|
||
|
|
//_refCount = ptr._refCount;
|
||
|
|
//touch();
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
|
T* operator->(){return _ptr;}
|
||
|
|
/* void touch()
|
||
|
|
{
|
||
|
|
_refCount++;
|
||
|
|
}
|
||
|
|
void release()
|
||
|
|
{
|
||
|
|
_refCount--;
|
||
|
|
}*/
|
||
|
|
int refCount()
|
||
|
|
{
|
||
|
|
return _refCount;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|