CORBA Enumeration Examples

CORBA enumerations can be used in many situations. The following examples show how to use the enumeration that appears in the Project Catalog after the IDL is cataloged.

Using enums in Operation Invocations

The following example shows how enumerations can be used in operation invocations or as the discriminator of a union:
	module CorbaTests
	{
	interface EnumTest
	{
	enum Slot { s1, s2, s3 };
	
	union UnionTest switch(Slot)
	{
	
	case s1: string  stringMember;
	case s2: long    longMember;
	default: boolean booleanMember;
	
	};
	
	void enumOp(in Slot aSlot);
	
	void unionOp(in UnionTest aUnionTest);
	
	Slot retEnumOp(in Slot aSlot);
	
	void outEnumOp(out Slot aSlot);
	
	void inoutEnumOp(inout Slot aSlot);
	};
	};
	
	

Using enums as IN Arguments

	s1 = Module1.CorbaTests.EnumTest.Slot.s1
	
	enumTest = Module1.CorbaTests.EnumTest("EnumTest")
	
	enumOp enumTest using aSlot = s1
	

Using enums as OUT Arguments

	enumTest = Module1.CorbaTests.EnumTest("EnumTest")
	
	outEnumOp enumTest returning s3 = aSlot
	

Using enums as IN/OUT Arguments

	enumTest = Module1.CorbaTests.EnumTest("EnumTest")
	
	inoutEnumOp enumTest using aSlot = s2 returning s4 = aSlot
	

enum as the Return Type

	s2 = Module1.CorbaTests.EnumTest.Slot.s2
	
	enumTest = Module1.CorbaTests.EnumTest("EnumTest")
	
	retEnumOp enumTest using aSlot = s2 returning s1
	

enum as the Discriminator of a Union

	enumTest = Module1.CorbaTests.EnumTest("EnumTest")
	
	unionTest = Module1.CorbaTests.EnumTest.UnionTest()
	
	unionTest.longMember = 10
	
	unionOp enumTest using aUnionTest = unionTest
	
	unionTest.stringMember = "aString"
	
	unionOp enumTest using aUnionTest = unionTest
	
	unionTest.booleanMember = true
	
	unionOp enumTest using aUnionTest = unionTest