#include <refcount.hpp>
Inheritance diagram for GarbageSafe:
Generic object that maintains a counter of references to it and automatically deletes itself when the counter becomes zero.
Definition at line 35 of file refcount.hpp.
Public Member Functions | |
GarbageSafe () | |
Constructor. | |
Protected Member Functions | |
bool | CanDie () |
Is it OK to delete the object now? | |
virtual | ~GarbageSafe () |
Friends | |
class | GarbageSafePointer |
class | GarbageSafeConstPointer |
|
Constructor. Constructor sets the counter to 1 assuming there will be at least one reference (otherwise we couldn't do any garbage collection anyway). If the object is allocated statically, then the reference means reference by name (so if everything works Ok, the counter never reaches zero). If the object is allocated dynamically, then we've got a pointer and must take care about it. Definition at line 64 of file refcount.hpp. |
|
Our destructor is virtual. Yes, it is. And, BTW, it is intentionally made protected so that it is impossible to create such an object on stack or as a global. Definition at line 70 of file refcount.hpp. |
|
Is it OK to delete the object now? Our children have no access to the private attribute RefCount and should never need it except when checking if the destruction is not an error. This solves the problem. Definition at line 53 of file refcount.hpp. |
|
Definition at line 36 of file refcount.hpp. |
|
Definition at line 37 of file refcount.hpp. |