![]() |
Overview The create_union operation creates a new union definition (UnionDef) in the Interface Repository. Original interface CORBA module: Container Interface Exceptions CORBA::SystemException
Intended Usage
The create_union operation creates a new union definition in the Interface Repository persistent database, and returns a pointer to a new UnionDef object associated with the union definition.
IDL Syntax
UnionDef create_union (in RepositoryId id, in Identifier name, in VersionSpec version, in IDLType discriminator_type, in UnionMemberSeq members);
Input parameters
- name
- The name that will be associated with this UnionDef object in the Interface Repository.
- discriminator_type
- This is a CORBA::IDLType * that identifies the union's discriminator type. The discriminator type can be a PrimitiveDef (with a primitive kind of CORBA::pk_long, CORBA::pk_short, CORBA::pk_ulong, CORBA::pk_ushort, CORBA::pk_char, CORBA::pk_wchar, or CORBA::pk_boolean) or an EnumDef (which represents an enumerator definition).
- id
- The id represents the CORBA::RepositoryId that will uniquely identify this UnionDef within the Interface Repository.
- members
This is a reference to a CORBA::UnionMemberSeq that provides the list of the elements that will comprise the new union (UnionDef). The length of the CORBA::UnionMemberSeq must be greater than zero.
Each CORBA::UnionMember within the CORBA::UnionMemberSeq has 4 fields. The name field identifies the name of the UnionMember. The type field of the UnionMember is ignored by create_union, and should be set to CORBA::_tc_void. The label field of each UnionMember is a CORBA::Any data type that represents a distinct value of the discriminator_type (a label of type CORBA::Octet and value 0 indicates the default union member). The type_def field is a CORBA::IDLType * that represents the type definition of the UnionMember.
- version
- The version number that will be associated with this UnionDef object in the Interface Repository.
Return values
- UnionDef_ptr
- A pointer to the created UnionDef object is returned to the caller. The memory associated with this object can later be released by invoking CORBA::release.
Example
// C++ // assume 'primitive_long', 'primitive_double' // 'structure_1', and 'repository_ptr' have already been instantiated CORBA::PrimitiveDef * primitive_long; CORBA::PrimitiveDef * primitive_double; CORBA::StructDef * structure_1; CORBA::Repository * repository_ptr; // establish the id, name, and version values for the union CORBA::RepositoryId rep_id; CORBA::Identifier name; CORBA::VersionSpec version; rep_id = CORBA::string_dup ("unique RepositoryId for my union"); name = CORBA::string_dup ("union new"); version = CORBA::string_dup ("1.0"); // the discriminator type is in this case CORBA::Long CORBA::IDLType * discriminator_type; discriminator_type = primitive_long; // instantiate a UnionMemberSeq and set the length to 2 CORBA::UnionMemberSeq union_members; union_members.length(2); // establish the UnionMemberSeq to represent a union with two // elements: a CORBA::Double called 'x', and a previously created // structure called 'y'. union_members[0].name = CORBA::string_dup ("x"); union_members[0].type_def = CORBA::IDLType::_duplicate (primitive_double); union_members[0].label <<= (CORBA::Long) 1; union_members[1].name = CORBA::string_dup ("y"); union_members[1].type_def = CORBA::IDLType::_duplicate (structure_1); union_members[1].label <<= (CORBA::Long) 2; // create the new union . . . CORBA::UnionDef * new_union; new_union = repository_ptr-> create_union (rep_id, name, version, discriminator_type, union_members);