mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-22 07:53:30 +00:00
36 lines
740 B
C++
Executable File
36 lines
740 B
C++
Executable File
#ifndef MEMUTILS_H__
|
|
#define MEMUTILS_H__
|
|
|
|
template <class T>
|
|
class Ref {
|
|
public:
|
|
//~Ref() { //@todo: add this if the pointer is created externally
|
|
// dec();
|
|
//}
|
|
void inc() { ++_count; }
|
|
void dec() { if (--_count == 0 && _obj) delete _obj; }
|
|
|
|
__inline short refCount() { return _count; }
|
|
__inline bool isUnique() { return _count == 1; }
|
|
|
|
__inline T* obj() { return _obj; }
|
|
|
|
T& operator->() { return *_obj; }
|
|
void operator++() { inc(); }
|
|
void operator--() { dec(); }
|
|
|
|
static Ref* create(T* object) { return new Ref(object); }
|
|
private:
|
|
Ref(T* object)
|
|
: _obj(object),
|
|
_count(1) {}
|
|
|
|
Ref(const Ref& rhs);
|
|
Ref& operator=(const Ref& rhs);
|
|
|
|
T* _obj;
|
|
short _count;
|
|
};
|
|
|
|
#endif /*MEMUTILS_H__*/
|