[omniORB] What's the omniORBpy alternative to DynEnum?

Duncan Grisby duncan at grisby.org
Fri Mar 12 17:24:47 GMT 2004


On Monday 8 March, Alex Tingle wrote:

> I'm using omniORBpy. I need to be able to create an Any that
> contains an enumerator. I have the enumeration type's TypeCode, and
> the value of the enumerator as a string.
>
> If this were C++, I'd do something like this: [1]
> 
>  DynAny_var  da=daf->create_dyn_any_from_type_code(enum_tc);
>  DynEnum_var de=DynEnum::_narrow(da);
>  de->set_as_string(value_string);
> 
> What's the best way to achieve this in omniORBpy?

This is one of the few cases where it would be useful if omniORBpy
supported DynAny. In the absence of that, you can dig into the
TypeCode to get the enum items out.

Inside a TypeCode is a type descriptor, which is a tuple (or a single
integer in the case of basic types like long). In the case of enums,
item 3 in that tuple is another tuple containing the enum items. You
can test the enum items by name. This function will get you a named
enum item given a TypeCode:

def nameToEnumItem(tc, name):
    assert tc.kind() == CORBA.tk_enum
    descriptor = tc._d
    enums = descriptor[3]
    for e in enums:
        if e._n == name:
            return e
    return None

This clearly relies on the internal structures of omniORBpy, so in
theory it could break with a new major release of omniORBpy. I don't
see why this bit of it would ever change, though. You might want to
raise an exception if the item is not found instead or returning None.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list