Re: Re: Re: Re: Re: Re: Re: Packet generalization

Hi Atul,

Thanks for the comments! The patch was actually for my development BitTorrent branch, not the official one. I wanted to wait for more feedback before merging it there. Have you tried:

bzr branch http://bzr.calitko.org/developers/peter/calitko-BitTorrent

I thought it was an interesting thing to try out with the function object but it is true it does not provide any advantage in our case, just a different syntax. I agree with you that by convention createPacket() should be preferred.

Another point would be that we could put two functions in the factory class: extractRawBytes() and createPacket() from these raw bytes. The factory need to know a bit about the format anyway in order to decide which packet to create, so adding knowledge how to extract a packet from raw data is not too much extra knowledge. We also would not need a second helper for PacketReader.

I did a quick check on the Internet what the differences between auto_ptr and scope_ptr are and it turns out they are almost identical. The only difference seems to be that scope_ptr cannot be copied. This means that for the factory case we do need auto_ptr because we want to stress that the caller gets the ownership (and we can’t return a scope_ptr anyway). If we allocate object on the stack in ctors for example, then scope_ptr seems to be a better choice. What do the others think?

I also thought it would be nice to declare typedefs like PacketPointer, so that we won’t need to always write auto_ptr
. However, if we get to use auto_ptr, scope_ptr and shared_ptr, we would need three different typedefs, e.g. PacketPointer, PacketSharedPointer, PacketScopePointer?. Any other suggestions for non-cryptic but shorter names? Maybe we could also say we use only auto_ptr, except when emitting slots in which case we should emit a shared_ptr. Btw. I need to check whether passing a argument of a template class works. At least qRegisterMetaType(”MyClass”); should be called once.

Regards,

Peter

atul wrote:

Dear Peter
I was not able to extract the patch on the source branch … However I could read it fine…
You have a great idea there and yes that is what our factory should do….
However, do we need to write the factory method a functor? I mean conventionally we use create/clone/get with factories… I would call it as getPacket ( not use the operator()() overload )
( Especially as it need not be called the same way as a global function here )

Also compare boost::scoped_ptr with auto_ptr … Next post I will post a book excerpt to illustrate the difference…. Do we need the ownership transfer semantics here?
What says everybody?
— cheers atul

Would you like to post a relpy?


This post is a reply to:
Re: Re: Re: Re: Re: Re: Packet generalization
Dear Peter I was not able to extract the patch on the source branch ... However I could read it fine... You have a great idea there and yes that is what (more...)

No follow-ups yet.