Bug 147 - base class for reference counted objects
: base class for reference counted objects
Status: RESOLVED FIXED
: ns-3
simulation core
: pre-release
: All All
: P3 normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2008-03-17 09:07 EDT by
Modified: 2008-07-01 13:32 EDT (History)


Attachments
class RefCountBase (4.68 KB, patch)
2008-03-17 09:07 EDT, Tom Henderson
Details | Diff


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2008-03-17 09:07:00 EDT
As discussed in November, a base class for providing implementations of
Ref/Unref for classes that do not derive from ns3::Object.

Written by George, with proposed rename by Tom from "SmartPointer" to
"RefCountBase".

We need to decide which classes use this base class.  Should any of the below
be specifically excluded from this class?:
AttributeAccessor
AttributeChecker
Packet
Object
TraceSourceAccessor
------- Comment #1 From 2008-03-17 09:07:32 EDT -------
Created an attachment (id=116) [details]
class RefCountBase
------- Comment #2 From 2008-03-17 10:51:10 EDT -------
(In reply to comment #0)
> As discussed in November, a base class for providing implementations of
> Ref/Unref for classes that do not derive from ns3::Object.
> 
> Written by George, with proposed rename by Tom from "SmartPointer" to
> "RefCountBase".
> 
> We need to decide which classes use this base class.  Should any of the below
> be specifically excluded from this class?:
> AttributeAccessor
> AttributeChecker
> Packet
> Object
> TraceSourceAccessor

Object should not because the implementation is very different/incompatible.
All the others could but they already derive from the ObjectBase class so doing
what you suggest now would require some multiple inheritance which I would
rather avoid.

Since I plan to remove eventually the ObjectBase class from their inheritance
tree, could we defer using RefCountBase in the classes which derive from
ObjectBase until I have done that removal ?

Other than that, looks good to me.
------- Comment #3 From 2008-03-17 12:43:00 EDT -------
(In reply to comment #2)
> Object should not because the implementation is very different/incompatible.
> All the others could but they already derive from the ObjectBase class so doing
> what you suggest now would require some multiple inheritance which I would
> rather avoid.
> 
> Since I plan to remove eventually the ObjectBase class from their inheritance
> tree, could we defer using RefCountBase in the classes which derive from
> ObjectBase until I have done that removal ?
> 
> Other than that, looks good to me.
> 

Instead, we could add Ref and Unref into ObjectBase, and then eventually
renaming ObjectBase to RefCountedBase?  There is no problem with Object
inheriting from this class too (as it does now), because it would just
reimplement Ref and Unref with its own implementation, provided we make the
ObjectBase::Ref and Unref methods virtual.
------- Comment #4 From 2008-03-17 12:58:32 EDT -------
(In reply to comment #3)
> (In reply to comment #2)
> > Object should not because the implementation is very different/incompatible.
> > All the others could but they already derive from the ObjectBase class so doing
> > what you suggest now would require some multiple inheritance which I would
> > rather avoid.
> > 
> > Since I plan to remove eventually the ObjectBase class from their inheritance
> > tree, could we defer using RefCountBase in the classes which derive from
> > ObjectBase until I have done that removal ?
> > 
> > Other than that, looks good to me.
> > 
> 
> Instead, we could add Ref and Unref into ObjectBase, and then eventually
> renaming ObjectBase to RefCountedBase?  There is no problem with Object

The plan is to move the attribute system to ObjectBase, not the reference
counting to allow classes which do not want to be refcounted to get the
attributes anyway. 

The only reason why they inherit from ObjectBase now is that I needed to do
this as a temporary hack to get the attributes working a few weeks ago and
never removed it since then because no one reminded me of the merge of
RefCountedBase.

> inheriting from this class too (as it does now), because it would just
> reimplement Ref and Unref with its own implementation, provided we make the
> ObjectBase::Ref and Unref methods virtual.

We cannot make these virtual for performance reasons.
------- Comment #5 From 2008-03-27 17:26:00 EDT -------
Since there were no comments on this bug for a while, and since tom's patch
seems ok and since the ObjectBase code was merged earlier last week, I pushed
out tom's patch (modulo a few things to make it build).

Final patch: changeset 03a23eb5f1e8