Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

GarbageSafe Class Reference

#include <refcount.hpp>

Inheritance diagram for GarbageSafe:

Inheritance graph
[legend]
List of all members.

Detailed Description

Generic object that needs to be garbage-collected.

Generic object that maintains a counter of references to it and automatically deletes itself when the counter becomes zero.

Note:
The objects of this class are to be created IN DYNAMIC MEMORY ONLY

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 & Destructor Documentation

GarbageSafe::GarbageSafe  ) 
 

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.

virtual GarbageSafe::~GarbageSafe  )  [protected, virtual]
 

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.


Member Function Documentation

bool GarbageSafe::CanDie  )  [protected]
 

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.


Friends And Related Function Documentation

friend class GarbageSafePointer [friend]
 

Definition at line 36 of file refcount.hpp.

friend class GarbageSafeConstPointer [friend]
 

Definition at line 37 of file refcount.hpp.


The documentation for this class was generated from the following file:
Generated on Tue Dec 18 00:41:40 2007 for InteLib by  doxygen 1.4.1