mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-22 16:03:31 +00:00
the whole game
This commit is contained in:
35
src/util/MemUtils.h
Executable file
35
src/util/MemUtils.h
Executable file
@@ -0,0 +1,35 @@
|
||||
#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__*/
|
||||
Reference in New Issue
Block a user