[omniORB] User's Guide semantics ...

Duncan Grisby dgrisby@uk.research.att.com
Tue, 22 May 2001 11:37:14 +0100


On Thursday 17 May, Richard Hardgrave wrote:

[...]
> What, exactly, does this mean?  At compile-time the object
> reference is "narrowed" to Echo_ptr only if, at runtime,
> the object reference can be "widened" to Echo_ptr???  Or,
> is there some implication that putting the ptr under the
> care of an Echo_var is doing the "narrowing"?

I agree that the wording is rather unfortunate. Change the word
"widened" to "narrowed", and it will probably make more sense.

_narrow() is just the CORBA equivalent of C++ dynamic_cast<>. narrow()
always happens at run time, not at compile time. All it means is that
you are holding an object reference of some base interface, say
CORBA::Object, and you want to use it as some derived interface, say
Echo. So you do

  CORBA::Object_var obj = ... get object reference...
  Echo_var e_obj = Echo::_narrow(obj);
  if (CORBA::is_nil(e_obj)) { 
    // The object was not of type Echo...
  }
  ...

The point is that, until runtime, the program has no way to make sure
the object reference obj is really an Echo -- it might be something
totally different. The _narrow() lets you check, and also satisfies
the C++ compiler's compile-time type checks.

Cheers,

Duncan.

-- 
 -- Duncan Grisby  \  Research Engineer  --
  -- AT&T Laboratories Cambridge          --
   -- http://www.uk.research.att.com/~dpg1 --