Getting the implementation object from a reference
Sai-Lai Lo
S.Lo@orl.co.uk
Fri, 6 Mar 1998 16:23:11 GMT
I think both methods will have difficult dealing with the general case when the
object references may or may not be referring to object implementations in
this address space.
Furthermore, the dynamic_cast relies on the fact that Interface_ptr is a
pointer to the base class of Inteface_i. The fact that this is true at the
moment is just an artefact of the implementation and should not be held as
a design required by the CORBA spec. In otherwise, don't use it or it'll
bite you in the long run.
It seems to me the proper way to do this is to maintain a hash table
of all object implementations in the application. Given any object
reference, the function CORBA::Object::_hash() can be used to return a hash
value, which can then be used to index into the open hash table.
Then one can walk through the hash list and for each
implementation, test if the object reference is referring to this
implementation using CORBA::Object::_is_equilvalent(). The approach will be
portable and do not rely on any implementation details of an ORB.
Sai-Lai
>>>>> Steve Brenneis writes:
> I would suggest using _narrow and then test the result using CORBA::is_nil. If it is not nil then a static or C-style cast would be safe.
> As a side note, it will be nice when all compilers support RTTI and dynamic casting. It should simplify the implementation of _narrow significantly.
> ----------
> From: Ole Storm
> Sent: Wednesday, March 04, 1998 7:34 AM
> To: omniorb-listorlcouk
> Subject: Getting the implementation object from a reference
> Greetings,
> Having a reference to a CORBA object, I would like to get the associated
> implementation object. I am aware that I can use dynamic casting:
> Interface_i *p = dynamic_cast<Interface_i*>(i_ptr);
> if(p)
> // ok to use p...
> - but what do I do with compilers that do not support run-time type
> information??
> Regards,
> Ole.
> ---------------------------------------------------------------
> Ole Storm
> The Institute of Applied Computer Science (IFAD)
> Forskerparken 10, DK-5230 Odense M, Denmark
> Phone: +45 6315 7134, Fax: +45 6593 2999, Email: storm@ifad.dk
> WWW: http://www.ifad.dk
> ---------------------------------------------------------------