VUtil::RefCounted Class Reference
#include <vos/vos/refcount.hh>
Inheritance diagram for VUtil::RefCounted:

Detailed Description
This is a simple base class for reference counting objects.It also provides a facility for tracking references to this object, so that they may be notified when the application wants this object to be deleted. You can use vRef to automatically release RefCounted objects when they would normally be destroyed (go out of scope).
- Note:
- If you have a situation where you are doing multiple inheritance from two or more classes that (directly or indirectly) themselves inherit from RefCounted, you need to mark your inheritance as a virtual base class. This means in your code Otherwise you could have two (or more) seperate reference counters for the same object, and that won't do at all.
class Foo : public virtual RefCounted { ... }; class Bar : public virtual RefCounted { ... }; class Baz : public virtual Foo, public virtual Bar { ... };
Definition at line 84 of file refcount.hh.
Public Member Functions
- RefCounted ()
- RefCounted (const RefCounted &)
- virtual ~RefCounted ()
- virtual void destroy ()
- This method is used by release() to destroy this object if the refcount reaches 0.
- This method is used by release() to destroy this object if the refcount reaches 0.
- virtual void acquire ()
- virtual void release ()
- virtual int getRefCount ()
- virtual void addExciseListener (ObjectExciseListener *oel)
- virtual void removeExciseListener (ObjectExciseListener *oel, bool releaseIfRefcounted=true)
- virtual void excise ()
- Ask that all known references to this object to release their references so the object can be deleted, by calling ObjectExciseListener::notifyObjectExcise().
- Ask that all known references to this object to release their references so the object can be deleted, by calling ObjectExciseListener::notifyObjectExcise().
Constructor & Destructor Documentation
| VUtil::RefCounted::RefCounted | ( | ) | [inline] |
Construct the refcount object with a starting count of 1.
Definition at line 94 of file refcount.hh.
| VUtil::RefCounted::RefCounted | ( | const RefCounted & | ) | [inline] |
| virtual VUtil::RefCounted::~RefCounted | ( | ) | [inline, virtual] |
Member Function Documentation
| virtual void VUtil::RefCounted::acquire | ( | ) | [virtual] |
| virtual void VUtil::RefCounted::addExciseListener | ( | ObjectExciseListener * | oel | ) | [virtual] |
Add an excise listener.
When the excise() method is called on this object, each excise listener will be notified so that it may clean up any references to this object.
- Parameters:
-
oel the excise listener to call back. This can itself be a refcounted object, and if so, its refcount will be incremented.
| virtual void VUtil::RefCounted::destroy | ( | ) | [virtual] |
This method is used by release() to destroy this object if the refcount reaches 0.
By default, it simply calls "delete this". However, you can override it in a subclass if you really want to do something other than deleting this object.
Reimplemented in VOS::VersionedVobject.
| virtual void VUtil::RefCounted::excise | ( | ) | [virtual] |
Ask that all known references to this object to release their references so the object can be deleted, by calling ObjectExciseListener::notifyObjectExcise().
- Note:
- This method is virtual and objects making use of this class will probably want to supply their own additional code to detach from linking data structures. Make sure to call RefCounted::excise() in yoru override method so that the excise listeners are called back. Overriding excise() will probably be sufficient for most uses; the purpose of the ObjectExciseListener facility is for plugin/application level hooks which may be beyond the scope of your immediate code.
Reimplemented in VOS::MetaObject, VOS::Site, and VOS::VobjectBase.
| virtual int VUtil::RefCounted::getRefCount | ( | ) | [virtual] |
| virtual void VUtil::RefCounted::release | ( | ) | [virtual] |
Decrement the reference count.
The object will be deleted if (count == 0)
Reimplemented in VOS::MetaObject.
| virtual void VUtil::RefCounted::removeExciseListener | ( | ObjectExciseListener * | oel, | |
| bool | releaseIfRefcounted = true | |||
| ) | [virtual] |
Remove an excise listener.
- See also:
- addExciseListener()
- Parameters:
-
oel the ObjectExciseListener to remove releaseIfRefcounted Should we test the object excise listener to see if it is refcounted, and if so release it? Under certain special circumstances (such as calling "removeExciseListener(this)" from a destructor) this behavior is undesirable.
The documentation for this class was generated from the following file:
- /home/tetron/hack/vos/libs/vos/vutil/refcount.hh