The RoseUnion class is used for EXPRESS select instances. The EXPRESS compiler creates sub-classes of RoseUnion for each select type in a schema. The RoseUnion class defines only one new function. All other functions are inherited from RoseObject.

Useful Functions Inherited from RoseObject

Some RoseObject functions are only appropriate for select instances. These functions are defined by RoseObject instead of RoseUnion to reduce typecasting by late-bound programs. Refer to RoseObject for more information about the following functions:

    RoseAttribute * RoseObject::getAttribute();

    <type_ref>  RoseObject::get<name>();

    RoseBoolean RoseObject::isExternal();
    RoseBoolean RoseObject::isUnresolved();

    RoseBoolean RoseObject::put<name>(<type_ref> val);


RoseBoolean putAttribute(
	const char * att_name

RoseBoolean putAttribute(
	RoseAttribute * att

The putAttribute() function sets the union to contain values of the specified type. A select contains attributes for each possible select value, but only one of these can have a value at a time. The function takes an attribute object or name. Each attribute is named after the type prepended with an underscore. If a matching attribute is not found, the union attribute is set to null. The RoseObject::getAttribute() function is used to find what attribute a union is set to.


/* Set the union so that it holds _widget object data */ 
RoseUnion * obj;
RoseObject * widget_obj;

obj->putAttribute ("_widget");
obj->putObject (widget_obj);

if (!obj-> getAttribute())
    printf ("The select is empty\n");
    printf ("The select contains %s data\n", 
	    obj-> getAttribute()-> slotDomain()-> name());