Previous Table of Contents Next


19.6 Mapping for Enumerated Types

   CORBA enums map to Automation enums. Consider the following example

   // OMG IDL module MyModule {

   enum color {red, green, blue}; interface foo { void op1(in color col);

   };};

   which maps to the following ODL:

   // ODLtypedef enum {MyModule_red, MyModule_green, MyModule_blue} MyModule_color;

   [odl,dual,uuid(7d1951f2-b5d3-8b7c-1dc3-aa0d5b3d6a2b)]interface DIMyModule_foo: IDispatch {HRESULT op1([in] MyModule_color col, [optional,out] VARIANT * excep_OBJ);}

   Internally, Automation maps enum parameters to the platform’s integer type. (For Win32, the integer type is equivalent to a long.) If the number of elements in the CORBA enum exceeds the maximum value of an integer, the condition should be trapped at some point during static or dynamic construction of the Automation View Interface corresponding to the CORBA interface in which the enum type appears as a parameter. If the overflow is detected at run-time, the Automation View operation should return the HRESULT DISP_E_OVERFLOW.

   If an actual parameter applied to the mapped parameter in the Automation View Interface exceeds the maximum value of the enum, the View operation should return the HRESULT DISP_E_OVERFLOW.

   Since all Automation controllers do not promote the ODL definition of enums into the controller scripting language context, vendors may wish to generate a header file containing an appropriate enum declaration or a set of constant declarations for the client language. Since the method for doing so is an implementation detail, it is not specified here. However, it should be noted that some languages type enums other than as longs, introducing the possibility of conversion errors or faults. If such problems arise, it is best to use a series of constant declarations rather than an enumerated type declaration in the client header file.

   For example, the following enum declaration

   enum color {red, green, blue, yellow, white};// OMG IDL

   could be translated to the following Visual Basic code:

   ' Visual BasicGlobal const color_red = 0Global const color_green = 1Global const color_blue = 2Global const color_yellow = 3Global const color_white = 4

   In this case the default naming rules for the enum values should follow those for interfaces. That is, the name should be fully scoped with the names of enclosing modules or interfaces. (See Section 17.7.8, “Naming Conventions for View Components,? on page 17-30.)

   If the enum is declared at global OMG IDL scope, as in the previous example, then the name of the enum should also be included in the constant name.