union |
The CORBA union indicates (TBD) ..... . It maps to VB's union type. |
// CORBA IDL |
union Nums switch (char) { case 'f': float f; case 'l': long l; default: short s; }; |
e.g. Nums NumsHelper |
// VB Imports System Namespace demo.unions ' ' Union definition : Nums ' ' @author TomORB VB Native Compiler 1.0rc1 ' <Serializable()> _ Public NotInheritable Class Nums Implements Org.Omg.CORBA.Portable.IDLEntity ' ' Union member _d ' Private __d As Char ' ' Union member f ' Private _f As Single ' ' Union member l ' Private _l As Integer ' ' Union member s ' Private _s As Short ' ' Default constructor ' Public Sub New() __d = "1"c End Sub ' ' Get/Set discriminator value ' Public Property discriminator As Char Get Return __d End Get Set __d = value End Set End Property ' ' Get/Set f value ' Public Property f As Single Set __d = "f"c _f = value End Set Get Return _f End Get End Property ' ' Get/Set l value ' Public Property l As Integer Set __d = "l"c _l = value End Set Get Return _l End Get End Property ' ' Get/Set s value ' Public Property s As Short Set __d = "1"c _s = value End Set Get Return _s End Get End Property ' ' Set s value ' Public Sub Set_Discriminator_And_S(dvalue As Char, value As Short) __d = dvalue _s = value End Sub End Class End Namespace Namespace demo.unions ' ' Helper class for : Nums ' ' @author TomORB VB Native Compiler 1.0rc1 ' Public Class NumsHelper ' ' Insert Nums into an any ' param name="a" an any ' param name="t" Nums value ' Public Shared Sub Insert(a As Org.Omg.CORBA.Any, t As demo.unions.Nums) a.Type(Type()) Write(a.Create_Output_Stream(),t) End Sub ' ' Extract Nums from an any ' @param a an any ' @return the extracted Nums value ' Public Shared Function Extract(a As Org.Omg.CORBA.Any) As demo.unions.Nums If Not(a.Type().Equal(Type())) Then Throw New Org.Omg.CORBA.MARSHAL() End If Return Read(a.Create_Input_Stream()) End Function ' ' Internal TypeCode value ' Private Shared _tc As Org.Omg.CORBA.TypeCode = Nothing Private Shared _working As Boolean = false ' ' Return the Nums TypeCode ' @return a TypeCode ' Public Shared Function Type() As Org.Omg.CORBA.TypeCode If _tc Is Nothing Then SyncLock (GetType(Org.Omg.CORBA.TypeCode)) If Not(_tc Is Nothing) Then Return _tc End If If _working Then Return Org.Omg.CORBA.ORB.Init().Create_Recursive_TC(Id()) End If _working = True Dim orb As Org.Omg.CORBA.ORB = Org.Omg.CORBA.ORB.Init() Dim _members() As Org.Omg.CORBA.UnionMember = New Org.Omg.CORBA.UnionMember(2){} Dim any As Org.Omg.CORBA.Any any = orb.Create_Any() any.Insert_Char("f"c) _members(0) = New Org.Omg.CORBA.UnionMember() _members(0).name = "f" _members(0).label = any _members(0).type = orb.Get_Primitive_TC(Org.Omg.CORBA.TCKind.tk_float) any = orb.Create_Any() any.Insert_Char("l"c) _members(1) = New Org.Omg.CORBA.UnionMember() _members(1).name = "l" _members(1).label = any _members(1).type = orb.Get_Primitive_TC(Org.Omg.CORBA.TCKind.tk_long) any = orb.Create_Any() any.Insert_Octet(Convert.ToByte(0)) _members(2) = New Org.Omg.CORBA.UnionMember() _members(2).name = "s" _members(2).label = any _members(2).type = orb.Get_Primitive_TC(Org.Omg.CORBA.TCKind.tk_short) _tc = orb.Create_Union_TC(Id(),"Nums",orb.Get_Primitive_TC( Org.Omg.CORBA.TCKind.tk_char),_members) _working = False End SyncLock End If Return _tc End Function ' ' Return the Nums IDL ID ' @return an ID ' Public Shared Function Id() As String Return _id End Function Private Shared _id As String = "IDL:demo/unions/Nums:1.0" ' ' Read Nums from a marshalled stream ' @param istream the input stream ' @return the readed Nums value ' Public Shared Function Read(istream As Org.Omg.CORBA.Portable.InputStream) As demo.unions.Nums Dim new_one As demo.unions.Nums = New demo.unions.Nums() new_one.discriminator = istream.Read_Char() If new_one.discriminator = CType("f"c, Char) Then new_one.f = istream.Read_Float() ElseIf new_one.discriminator = CType("l"c, Char) Then new_one.l = istream.Read_Long() Else new_one.s = istream.Read_Short() End If Return new_one End Function ' ' Write Nums into a marshalled stream ' @param ostream the output stream ' @param value Nums value ' Public Shared Sub Write(ostream As Org.Omg.CORBA.Portable.OutputStream, value As demo.unions.Nums) ostream.Write_Char(value.discriminator) If value.discriminator = CType( "f"c, Char) Then ostream.Write_Float(value.f) ElseIf value.discriminator = CType( "l"c, Char) Then ostream.Write_Long(value.l) Else ostream.Write_Short(value.s) End If End Sub End Class End Namespace |