Previous Table of Contents Next


19.8.2 Mapping for Union Types


   CORBA unions are mapped to a Pseudo-Automation Interface called a Pseudo-Union. A Pseudo-Union contains properties that correspond to the members of the union, with the addition of a discriminator property. The discriminator property’s name is UNION_d, and its type is the Automation type that corresponds to the OMG IDL union discriminant.

   If a union element is accessed from the Pseudo-Union, and the current value of the discriminant does not match the property being requested, then the operation of the Pseudo-Union returns DISP_E_TYPEMISMATCH. Whenever an element is set, the discriminant’s value is set to the value that corresponds to that element.

   A Pseudo-Union derives from the methodless interface DICORBAUnion which, in turn, derives from DIForeignComplexType:

   // ODL[odl, dual, uuid(...)]interface DICORBAUnion: DIForeignComplexType // ODL{

   [hidden] HRESULT repositoryID ([out) BSTR * val);}

   The UUID for DICORBAUnion is:

   {A8B553C2-3B72-11cf-BBFC-444553540000}

   This interface can also be implemented as generic (nondual) Automation Interface, in which case it is named DCORBAUnion and its UUID is:

   {E977F902-3B75-11cf-BBFC-444553540000}

   To support OMG IDL described unions that support multiple case labels per union branch, the DICORBAUnion2 interface is defined in a way to provide two additional accessors.

   // ODL[odl, dual, uuid(...)]interface DICORBAUnion2 : DICORBAUnion {

   HRESULT SetValue([in] long disc, [in] VARIANT val);

   [propget, id(-4)]

   HRESULT CurrentValue([out, retval] VARIANT * val);};

   The SetValuemethod can be used to set the discriminant and value simultaneously. The CurrentValuemethod will use the current discriminant value to initialize the VARIANT with the union element. All mapped unions should support the DICORBAUnion2 interface.

   The uuid for the DICORBAUnion2 interface is: {1a2face0-2199-11d1-9d47-00a024a73e4f}

   The uuid for the DCORBAUnion2 interface is: {5d4b8bc0-2199-11d1-9d47-00a024a73e4f}

   An example of mapping a CORBA union to a Pseudo-Union follows. The union

   interface A; // IDL

   union U switch(long)

   {

   case 1: long l;

   case 2: float f;

   default: A obj; };

   maps to Automation as if it were defined as follows, except that the mapped Automation Dual Interface derives from DICORBAUnion2.

   interface A; // IDL

   interface U

   {

   // Switch discriminant

   readonly attribute long UNION_d;

   attribute long l;

   attribute float f;

   attribute A obj; };

   Note – The mapping for the OMG IDL default label will be ignored if the cases are exhaustive over the permissible cases (for example, if the switch type is boolean and a case TRUE and case FALSE are both defined).