next up previous
Next: Arrays Up: Untyped values Previous: Unknown Constructed Types

Subtyping

Another feature of MICO's Any implementation is its subtyping support. The extraction operators of type Any implement the subtyping rules for recursive types as prescribed by the Reference Model for Open Distributed Processing (RM-ODP), see [1, 2, 3, 4] for details. The idea behind subtyping is the following: Imagine you want to call a CORBA method

  void bar (in long x);

but want to pass a short as an argument instead of the required long. This should work in theory since each possible short value is also a long value which means short is a subtype of long. More generally speaking a type tex2html_wrap_inline2097 is a subtype of type tex2html_wrap_inline2099 if you could pass tex2html_wrap_inline2097 as an input parameter where a tex2html_wrap_inline2099 is expected. This means for basic types such as long: a basic type tex2html_wrap_inline2097 is a subtype of a basic type tex2html_wrap_inline2099 iff the set of possible values of tex2html_wrap_inline2097 is a subset of the set of possible values of tex2html_wrap_inline2099. Figure 5.1 shows the subtype relations between CORBA's basic data types. In C++ the compiler can automatically convert types along a chain of arrows, but in a distributed CORBA application this can't be done by the compiler alone because binding between client and server is performed at runtime using a trader or a naming service. That is the subtype checking must be done at runtime as well.

 figure740
Figure 5.1:   Subtype relations between basic CORBA types.

In MICO the Any type performs subtype checking at runtime. For example:

  // C++
  CORBA::Any a;
  a <<= (CORBA::Short) 42;
  ...
  CORBA::Double d;
  a >>= d;

will work because short is a subtype of double according to figure 5.1 but:

  // C++
  CORBA::Any a;
  a <<= (CORBA::Long) 42;
  ...
  CORBA::ULong d;
  a >>= d;

will fail because long is not a subtype of unsigned long. There is a special subtyping rule for structured types: A struct type tex2html_wrap_inline2097 is a subtype of a struct type tex2html_wrap_inline2099 iff the elements of tex2html_wrap_inline2099 are supertypes of the first elements of tex2html_wrap_inline2097. struct S1 is for example a subtype of struct S2:

  struct S1 {
    short s;
    long l;
  };

  struct S2 {
    long s;
  };

That is you can put a struct S1 into an Any and unpack it as a struct S2 later:

  // C++
  CORBA::Any a;
  S1 s1 = { 10, 20 };
  a <<= s1;
  ...
  S2 s2;
  a >>= s2;

There are similar rules for the other constructed types.


next up previous
Next: Arrays Up: Untyped values Previous: Unknown Constructed Types

MICO
Tue Nov 10 11:04:45 CET 1998