interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

VUtil::RefCounted Class Reference

#include <vos/vos/refcount.hh>

Inheritance diagram for VUtil::RefCounted:

A3DL::ActionEvent VIP::Connection VIP::Message VIP::SocketMultiplexer VOS::AccessControlList VOS::IdentityChanged VOS::Message VOS::MessageBlock VOS::MsgField VOS::ParentChildRelation VOS::PropertyEvent VOS::TalkMessage VOS::Vobject VOS::VobjectEvent List of all members.

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
    class Foo : public virtual RefCounted { ... };
    class Bar : public virtual RefCounted { ... };
    class Baz : public virtual Foo, public virtual Bar { ... };
Otherwise you could have two (or more) seperate reference counters for the same object, and that won't do at all.

Definition at line 84 of file refcount.hh.

Public Member Functions


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]

copy constructor, need to reset count on the copy

Definition at line 97 of file refcount.hh.

virtual VUtil::RefCounted::~RefCounted (  )  [inline, virtual]

Destructor.

(Cleans up excise listeners)

Definition at line 100 of file refcount.hh.


Member Function Documentation

virtual void VUtil::RefCounted::acquire (  )  [virtual]

Increment the reference count.

Reimplemented in VOS::MetaObject.

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]

Get the current reference count.

Reimplemented in VOS::MetaObject.

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: