Previous Table of Contents Next


18.3.6 Mapping for Union Types


   ODL unions are not discriminated unions and must be custom marshaled in any interfaces that use them. For this reason, this specification does not provide any mapping for ODL unions to CORBA unions.

   MIDL unions, while always discriminated, are not required to be encapsulated. The discriminator for a nonencapsulated MIDL union could, for example, be another argument to the operation. The discriminants for MIDL unions are not required to be constant expressions.

   18.3.6.1 Mapping for Encapsulated Unions

   When mapping from Microsoft IDL to OMG IDL, Microsoft IDL encapsulated unions having constant discriminators are mapped to OMG IDL unions as shown next.

   // Microsoft IDL

    typedef enum{dchar,dShort,dLong,dFloat,dDouble} UNION_DISCRIMINATOR;

    typedef union switch (UNION_DISCRIMINATOR _d){case dChar: char c;case dShort: short s;case dLong: long l;case dFloat: float f;case dDouble: double d;default: byte v[8];}UNION_OF_CHAR_AND_ARITHMETIC;

   The OMG IDL definition is as follows.

   // OMG IDL

    enum UNION_DISCRIMINATOR

   {

   dChar,

   dShort,

   dLong,

   dFloat,

   dDouble

   };

    union UNION_OF_CHAR_AND_ARITHMETIC

   switch(UNION_DISCRIMINATOR)

   {

   case dChar: char c;

   case dShort: short s;

   case dLong: long l;

   case dFloat:. float f;

   case dDouble:. double d;

   default: octet v[8];

   };

   18.3.6.2 Mapping for nonencapsulated unions

   Microsoft IDL nonencapsulated unions and Microsoft IDL encapsulated unions with nonconstant discriminators are mapped to an any in OMG IDL. The type of the any is determined at run-time during conversion of the Microsoft IDL union.

   // Microsoft IDL

   typedef [switch_type( short )] union

   tagUNION_OF_CHAR_AND_ARITHMETIC

    {

    [case(0)] char c;

    [case(1)] short s;

    [case(2)] long l;

    [case(3)] float f;

    [case(4)] double d;

    [default] byte v[8];

    } UNION_OF_CHAR_AND_ARITHMETIC;

   The corresponding OMG IDL syntax is as follows.

   // OMG IDLtypedef any UNION_OF_CHAR_AND_ARITHMETIC;