Документ взят из кэша поисковой машины. Адрес оригинального документа : http://rtm-cs.sinp.msu.ru/manual/mico/doc/node56.html
Дата изменения: Mon Jun 7 21:54:59 1999
Дата индексирования: Mon Oct 1 21:22:35 2012
Кодировка:
Subtyping 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 T1 is a subtype of type T2 if you could pass T1 as an input parameter where a T2 is expected. This means for basic types such as long: a basic type T1 is a subtype of a basic type T2 iff the set of possible values of T1 is a subset of the set of possible values of T2. 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.

 figure802
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 T1 is a subtype of a struct type T2 iff the elements of T2 are supertypes of the first elements of T1. 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

Arno Puder
Mon Jun 7 10:53:40 PDT 1999