You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Jiri Krutil <ji...@krutil.com> on 2011/06/21 10:19:50 UTC

Comparing handles in C++ client

Hi

In the C++ client, things like Receiver appear to be handles with  
pointer semantics.

Can one compare two handles for equality to find out if they both  
refer to the same implementation object?

Even if neither class Receiver nor class Handle implement operator==,  
the following code surprisingly complies:

qpid::messaging::Receiver r1;
qpid::messaging::Receiver r2;
...
bool equal = (r1 == r2);

How come this compiles and what does it do?

Cheers
Jiri


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Comparing handles in C++ client

Posted by Gordon Sim <gs...@redhat.com>.
On 06/21/2011 03:07 PM, jkrutil wrote:
>
> Gordon Sim wrote:
>>
>> At present two handles are equal if either they are both null or if they
>> are both non-null. The only time they are not equal is if one is null
>> and the other is not.
>>
>
> So is there a way how to test if two handles point to the same object?

Not in general at present. You could test two receivers by comparing 
their names (likewise for sessions and senders).

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Comparing handles in C++ client

Posted by jkrutil <qp...@krutil.com>.
Gordon Sim wrote:
> 
> At present two handles are equal if either they are both null or if they 
> are both non-null. The only time they are not equal is if one is null 
> and the other is not.
> 

So is there a way how to test if two handles point to the same object?

--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Comparing-handles-in-C-client-tp6499057p6500120.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org


Re: Comparing handles in C++ client

Posted by Gordon Sim <gs...@redhat.com>.
On 06/21/2011 09:19 AM, Jiri Krutil wrote:
> Hi
>
> In the C++ client, things like Receiver appear to be handles with
> pointer semantics.
>
> Can one compare two handles for equality to find out if they both refer
> to the same implementation object?
>
> Even if neither class Receiver nor class Handle implement operator==,
> the following code surprisingly complies:
>
> qpid::messaging::Receiver r1;
> qpid::messaging::Receiver r2;
> ..
> bool equal = (r1 == r2);
>
> How come this compiles and what does it do?

I believe that is due to the conversion to bool defined for Handle.

At present two handles are equal if either they are both null or if they 
are both non-null. The only time they are not equal is if one is null 
and the other is not.

It would probably make sense to define a slightly more intuitive 
equality operator.

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org