Files
lime/project/include/utils/Object.h
2018-07-18 17:32:51 -07:00

65 lines
586 B
C++

#ifndef LIME_UTILS_OBJECT_H
#define LIME_UTILS_OBJECT_H
namespace lime {
class Object {
protected:
virtual ~Object () {}
public:
Object (bool has_initial_ref = false) : ref_count (has_initial_ref ? 1 : 0) {}
Object *grab () {
ref_count++;
return this;
}
Object *IncRef () {
ref_count++;
return this;
}
void DecRef () {
ref_count--;
if (ref_count <= 0) {
delete this;
}
}
void drop () {
ref_count--;
if (ref_count <= 0) {
delete this;
}
}
int ref_count;
};
}
#endif