[haiku-development] Re: BWeakReferenceable
- From: Clemens <clemens.zeidler@xxxxxxxxxxxxxx>
- To: haiku-development@xxxxxxxxxxxxx
- Date: Fri, 23 Sep 2011 11:30:40 +1200
On Thu, 22 Sep 2011 20:01:32 +1200, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
wrote:
Hi Clemens,
clemens.zeidler@xxxxxxxxxxxxxx wrote:
found Axel's nice WeakReferenceable implementation but had some problems
to understand how to use it. For example, the management of the
WeakPointer ref counting and the conversion into a WeakReference was a
bit confusing to me. I attached a new API which is more similar to
BReference and hopefully easier to use.
Consistency is important across the API, so please go ahead.
While you're at it, WeakPointer should get the 'B' prefix as well if
this class is ever going to be made public. Or would it be possible to
eliminate this class from the public eye?
Actually, I wanted to hide the WeakPointer but I don't not know how. Tried
to put it into a cpp file but the BWeakReference template needs the
implementation... There should be no need to access the WeakPointer
directly.
@Philippe: as Stephan already wrote there must be already a reference on
the pointer when calling the method, thus it is safe.
Another question: when using BReference function arguments can become quit
long, e.g.
void Method(BReference<LongClassNameNumber1> class1, BReference<Class2>
class2);
How you guys handling that? On solution would be to make a typedef like
typedef BReference<LongClassNameNumber1> LongClassNameNumber1Ref;
=>
void Method(LongClassNameNumber1Ref class1, Class2Ref class2);
this solution has the drawback that you have to do it for each class.
Another solution would be to shorten the name a bit e.g.:
template<class T>
typedef BReference<T> sp; // sp strong pointer or sr strong reference
=>
void Method(sp<LongClassNameNumber1> class1, sp<Class2> class2);
although sp is not very meaningful combined with the template argument I
thing its pretty obvious what it means.
Regards,
Clemens
Other related posts: