Titan Core Initial Contribution
[deliverable/titan.core.git] / help / info / union.html
1 <!--
2 Copyright (c) 2000-2014 Ericsson Telecom AB
3
4 All rights reserved. This program and the accompanying materials
5 are made available under the terms of the Eclipse Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/epl-v10.html
8 -->
9 <html>
10 <head>
11 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
12 <meta http-equiv="Content-Language" content="en-us">
13 <title>union</title>
14 </head>
15 <body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258">
16 <table align="left" border="0" cellspacing="0" cellpadding="0" valign=top>
17 <tr>
18 <td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td>
19 </tr>
20 </table>
21 <table border="0" align="right" cellpadding="0" cellspacing="0">
22 <tr>
23 <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td>
24 <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td>
25 <td><a href="unichar2oct.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td>
26 <td><a href="universal.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td>
27 </tr>
28 </table>
29 <p><br clear="all">
30 </p>
31 <hr>
32 <h1>union</h1>
33 <hr align="left" width="75%">
34 <p>The keyword denotes a structured type: a collection of fields, each one identified by an identifier. Only one of the specified fields will ever be present in an actual union value.&nbsp;
35 <ul>
36 <li>Union types are useful to model a structure which can take one of a finite number of known types.</li>
37 <li>Optional elements are forbidden (they do not make sense).</li>
38 <li>Element type can be any basic or user-defined data type.</li>
39 <li>More elements can have same type as long as their identifiers differ.</li>
40 <li>Elements of the union may be accessed using the <a href="#Example 2">dot notation</a> or <a href="#Example 3">assignment notation</a>.</li>
41 <li>The <a href="#Example 4">ischosen()</a> predefined function returns the value true if and only if the referenced element of the union type is actually selected for the given union.</li>
42 </ul>
43 <p>Related keywords:</p>
44 <ul>
45 <li><a href="type.html"><font face="Courier New" color="#003258" size="4"><b>type</b></font></a> &nbsp;</li>
46 <li><a href="address.html"><font face="Courier New" color="#003258" size="4"><b>address</b></font></a></li>
47 <li><a href="ischosen.html"><b><font face="Courier New" color="#003258" size="4">ischosen</font></b></a></li>
48 </ul>
49 <hr align="left" width="50%">
50 <div align="center">
51 <center>
52 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
53 <tr>
54 <td width="100%">
55 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>type union</b>&nbsp;</font> (<i>identifier&nbsp;</i> | <font face="Courier New" color="#003258" size="5"><b>address</b></font>)<font
56 face="Courier New" color="#003258" size="5"><b> {</b></font>&nbsp; <i>type_reference</i>&nbsp; <i>element_identifier</i> ... <font face="Courier New" color="#003258" size="5"><b>};</b></font></h3>
57 </td>
58 </tr>
59 </table>
60 </center>
61 </div>
62 <ul>
63 <li>
64 <p>The <a href="type.html"><font face="Courier New" color="#003258" size="4"><b>type</b></font></a> <font face="Courier New" color="#003258" size="4"><b>union</b></font> keywords
65 introduce the type definition.</p>
66 </li>
67 <li>
68 <p><i>identifier</i> is the&nbsp;name used to refer to the union. Must begin with a letter, may contain letters, numbers and underscore characters.</p>
69 </li>
70 <li>
71 <p><a href="address.html"><font face="Courier New" color="#003258" size="4"><b>address</b></font></a> is a user defined type to allow addressing specific entities inside the
72 System Under Test.</p>
73 </li>
74 <li>
75 <p><i>type_reference</i> refers to an already defined (structured or simple) <a href="type.html">type</a>.</p>
76 </li>
77 <li>
78 <p><i>element_identifier</i> identifies the elements of the union. The identifiers must be unique within the same union</p>
79 </li>
80 <li>
81 <p><b>...</b> indicates that&nbsp; <i>type_reference</i> <i>element_identifier</i> pairs may be repeated. They are separated by comma.</p>
82 </li>
83 </ul>
84 <hr align="left" width="50%">
85 <p>Example 1: type definition
86 <p><font face="Courier New">type union MyUnionType {&nbsp;<br>
87 &nbsp;&nbsp;&nbsp;integer Number1,<br>
88 &nbsp;&nbsp;&nbsp;integer Number2,<br>
89 &nbsp;&nbsp;&nbsp;charstring String<br>
90 }</font>
91 <p>The union called MyUnionType consists of three elements. The first two are both of type integer and have the identifier Number1 and Number2, respectively. The third element is of type character
92 string and has the identifier String.</p>
93 <hr align="left" width="50%">
94 <p><a name="Example 2">Example 2</a>: dot notation (For the type definition see example 1)
95 <p><font face="Courier New">var MyUnionType v_myUnion;&nbsp;<br>
96 v_myUnion.Number1 := 12;</font>
97 <p>The variable v_myUnion of type MyUnionType is defined. The value 12 is assigned to the field Number1 making the given field to be the chosen one</p>
98 <hr align="left" width="50%">
99 <p><a name="Example 3">Example 3</a>: assignment notation (For the type and variable definition see example 1 &amp; 2)
100 <p><font face="Courier New">v_myUnion := {Number2 := 112};</font>
101 <p>The value 112 is assigned to the field Number2.&nbsp;</p>
102 <hr align="left" width="50%">
103 <p><a name="Example 4">Example 4</a>: the predefined function ischosen&nbsp;
104 <p><font face="Courier New">var boolean v_whichone := ischosen(v_myUnion.Number1);</font>
105 <p>The variable v_whichone will have the value true if the field Number1 is chosen (as in example 2).</p>
106 <hr align="left" width="25%">
107 <p><a HREF="BNF.html#uniondef">BNF definition</a> of <font face="Courier New"> union</font></p>
108 </body>
109 </html>
This page took 0.032266 seconds and 5 git commands to generate.