| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
on |
| 16 |
|
| 17 |
<html> |
| 18 |
<head> |
| 19 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 20 |
<meta http-equiv="Content-Language" content="en-us"> |
| 21 |
<title>template</title> |
| 22 |
</head> |
| 23 |
<body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> |
| 24 |
<table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> |
| 25 |
<tr> |
| 26 |
<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> |
| 27 |
</tr> |
| 28 |
</table> |
| 29 |
<table border="0" align="right" cellpadding="0" cellspacing="0"> |
| 30 |
<tr> |
| 31 |
<td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> |
| 32 |
<td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> |
| 33 |
<td><a href="system.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> |
| 34 |
<td><a href="testcase.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> |
| 35 |
</tr> |
| 36 |
</table> |
| 37 |
<p><br clear="all"> |
| 38 |
</p> |
| 39 |
<hr> |
| 40 |
<h1>template</h1> |
| 41 |
<hr align="left" width="75%"> |
| 42 |
<p>The keyword is a homonym. It is used to... |
| 43 |
<ol> |
| 44 |
<li>specify a set of values to be sent or received (<a href="#Templates">see below</a>);</li> |
| 45 |
<li>extend the range of allowed parameters (<a href="function.html#template">see here</a> <a href="#Example 3">and here</a>).</li> |
| 46 |
</ol> |
| 47 |
<p>Related keywords:</p> |
| 48 |
<ul> |
| 49 |
<li><a href="modifies.html"><b><font face="Courier New" color="#003258" size="4">modifies</font></b></a> (sense 1)</li> |
| 50 |
<li><a href="complement.html"><b><font face="Courier New" color="#003258" size="4">complement</font></b></a> (sense 1)</li> |
| 51 |
<li><a href="ifpresent.html"><b><font face="Courier New" color="#003258" size="4">ifpresent</font></b></a> (sense 1)</li> |
| 52 |
<li><a href="sizeof.html"><b><font face="Courier New" color="#003258" size="4">sizeof</font></b></a> (sense 1)</li> |
| 53 |
<li><a href="subset.html"><b><font face="Courier New" color="#003258" size="4">subset</font></b></a> (sense 1)</li> |
| 54 |
<li><a href="superset.html"><b><font face="Courier New" color="#003258" size="4">superset</font></b></a> (sense 1)</li> |
| 55 |
<li><a href="pattern.html"><b><font face="Courier New" color="#003258" size="4">pattern</font></b></a> |
| 56 |
<li><a href="permutation.html"><b><font face="Courier New" color="#003258" size="4">permutation</font></b></a> (sense 1)</li> |
| 57 |
<li><a href="function.html"><b><font face="Courier New" color="#003258" size="4">function</font></b></a> (sense 2)</li> |
| 58 |
</ul> |
| 59 |
<hr align="left" width="75%"> |
| 60 |
<p>1. <a name="Templates">Templates</a> are used either to test whether a set of received values matches the template specification or to transmit a set of distinct values. |
| 61 |
<ul> |
| 62 |
<li>Templates used to receive messages have the advantage that all valid message variants may be described in a single template. When a message arrives, the program can decide whether it is a |
| 63 |
valid one or not. This procedure is called matching.</li> |
| 64 |
<p> |
| 65 |
<li>Templates used to send messages are advantageous because they can be parameterized, thus, reused. All fields of these templates must have a determined value at the point when a message is |
| 66 |
sent using them. These templates may be used to receive messages as well, but only when all fields of the expected message are fixed and known beforehand.</li> |
| 67 |
</p> |
| 68 |
</ul> |
| 69 |
<hr align="left" width="50%"> |
| 70 |
<div align="center"> |
| 71 |
<center> |
| 72 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 73 |
<tr> |
| 74 |
<td width="100%"> |
| 75 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>template</b></font> <i>type identifier </i>[<i> formal_parameter_list</i> ] [<font face="Courier New" color="#003258" |
| 76 |
size="5"><b> modifies</b></font> <i>base_template_identifier</i> ] := <i>body </i></h3> |
| 77 |
</td> |
| 78 |
</tr> |
| 79 |
</table> |
| 80 |
</center> |
| 81 |
</div> |
| 82 |
<ul> |
| 83 |
<li> |
| 84 |
<p><i>type</i> specifies the legal set of values of the template. In case of structured types it also determines the fields of the template.</p> |
| 85 |
</li> |
| 86 |
<li> |
| 87 |
<p><i>identifier</i> is a name used to refer to the template. Must begin with a letter, may contain letters, numbers and |
| 88 |
underscore characters. According to the Naming convention, the prefix <b>t_</b> or <b>tr_</b> is recommended. The former one is used denote a |
| 89 |
specific value the template used with sending operations, whereas the latter one is used to denote a receiving template including field matching.</p> |
| 90 |
</li> |
| 91 |
<li> |
| 92 |
<p><i> formal_parameter_list</i> provides the list of the parameters of the template. The formal parameters themselves can be templates or values. (In the first case, the keyword is used in |
| 93 |
sense 2., <a href="#Example 3">see example</a>) These optional parameters may be used to alter the template at every invocation.</p> |
| 94 |
</li> |
| 95 |
<li> |
| 96 |
<p><font face="Courier New"><b>modifies</b></font> denotes a <a href="#Example 4">derived template</a> where only some of the fields of the original template are changed.</p> |
| 97 |
</li> |
| 98 |
<li> |
| 99 |
<p><i>base_template_identifier</i> identifies the parent template some of the field of which are modified. Both templates have the same fields.</p> |
| 100 |
</li> |
| 101 |
<li> |
| 102 |
<p><i>body</i> lists the permitted values for each field: constants, matching expressions, templates or parameter references shall be assigned to each field of a template. The matching |
| 103 |
mechanisms are elucidated in detail in Annex B of the standard. Below, abundant examples are given as illustrations.</p> |
| 104 |
</li> |
| 105 |
</ul> |
| 106 |
<hr align="left" width="50%"> |
| 107 |
<p>Examples:</p> |
| 108 |
<ol> |
| 109 |
<li><a href="#parametrized">Parameterized value list template</a></li> |
| 110 |
<li><a href="#Example 2">Value range template, parameterized with a template parameter</a></li> |
| 111 |
<li><a href="#Example 3">Complemented value list template</a></li> |
| 112 |
<li><a href="#ifpresent">Matching not omitted optional fields only</a></li> |
| 113 |
<li><a href="#subset">Excluding a field with superfluous elements</a></li> |
| 114 |
<li><a href="#superset">Excluding a field with missing elements</a></li> |
| 115 |
<li><a href="#Example 7">Character pattern matching</a></li> |
| 116 |
<li><a href="#Example 4">Modified template</a></li> |
| 117 |
</ol> |
| 118 |
<hr align="left" width="50%"> |
| 119 |
<p><a name="parametrized">Example</a> 1 (parameterized value list template): |
| 120 |
<p><font face="Courier New">type record MyMessageType {<br> |
| 121 |
<blockquote>integer field1 optional,<br> |
| 122 |
charstring field2,<br> |
| 123 |
boolean field3<br> |
| 124 |
}</blockquote> |
| 125 |
<p>template MyMessageType tr_MyTemplate (boolean pl_param) := {<br> |
| 126 |
<blockquote>field1 := ?,<br> |
| 127 |
field2 := (âBâ, âOâ, âQâ),<br> |
| 128 |
field3 := pl_param<br> |
| 129 |
}</blockquote> |
| 130 |
</font> |
| 131 |
<p>First, we define a record (MyMessageType) containing three fields, the first one being optional. The type of the template will be the one just defined. The template we'll define is called |
| 132 |
tr_MyTemplate. In the template name prefix, 't' stands for 'template' and 'r' for receiving.<br> |
| 133 |
The template accepts the following messages: the first field must be present, but its content is don't care. The second field may have the value B, O or Q. The value of the last field must be in |
| 134 |
function of the parameter pl_param either true or false.<br> |
| 135 |
The template can be used for receiving only, because it contains an undefined field (the first one).</p> |
| 136 |
<hr align="left" width="25%"> |
| 137 |
<p><a name="Example 2">Example 2</a> (value range template, parameterized with a template parameter): |
| 138 |
<p><font face="Courier New">type record MujMessageType {<br> |
| 139 |
<blockquote>integer field1 optional,<br> |
| 140 |
charstring field2,<br> |
| 141 |
float field3<br> |
| 142 |
}</blockquote> |
| 143 |
<p>template MujMessageType tr_MujTemplate (template integer pl_parametr) := {<br> |
| 144 |
<blockquote>field1 := pl_parametr,<br> |
| 145 |
field2 := (âCâ .. âXâ),<br> |
| 146 |
field3 := (1.0 .. 1.37)<br> |
| 147 |
}</blockquote> |
| 148 |
</font> |
| 149 |
<p>First, we define a record (MujMessageType) containing three fields, the first one being optional. The type of the template will be the one just defined. The template we'll define is called |
| 150 |
tr_MujTemplate.<br> |
| 151 |
The template accepts the following messages: the first field is determined by the parameter pl_parametr. When the actual value of the parameter gives a value or a range, the field must have the |
| 152 |
same value or range. When the parameter contains an asterisk, the field may be absent. When the parameter holds a question mark, the field must be present, but its content is don't care. The second |
| 153 |
field may have any value from the series C, D, E, and so on to X included. The value of the last field must be between 1.0 and 1.37.<br> |
| 154 |
The template can be used for receiving only, because it contains an undefined field (the first one).</p> |
| 155 |
<hr align="left" width="25%"> |
| 156 |
<p><a name="Example 3">Example 3</a> (complemented value list template): |
| 157 |
<p><font face="Courier New">type record MiaMessageType {<br> |
| 158 |
<blockquote>float field1 optional,<br> |
| 159 |
charstring field2,<br> |
| 160 |
integer field3<br> |
| 161 |
}</blockquote> |
| 162 |
<p>template MiaMessageType tr_MiaTemplate := {<br> |
| 163 |
<blockquote>field1 := *,<br> |
| 164 |
field2 := complement (âCâ, "L", âXâ),<br> |
| 165 |
field3 := (1 .. infinity)<br> |
| 166 |
}</blockquote> |
| 167 |
</font> |
| 168 |
<p>First, we define a record (MiaMessageType) containing three fields, the first one being optional. The type of the template will be the one just defined. The template we'll define is called |
| 169 |
tr_MiaTemplate.<br> |
| 170 |
The template accepts the following messages: the first field may be either absent or present, in either case its content is don't care. The second field may have any value except the capital letters |
| 171 |
C, L, and X. The value of the last field must be greater than 1.</p> |
| 172 |
<hr align="left" width="25%"> |
| 173 |
<p><a name="ifpresent">Example 4</a> (matching not omitted optional fields only): |
| 174 |
<p><font face="Courier New">type record MonMessageType {<br> |
| 175 |
<blockquote>float field1 optional<br> |
| 176 |
}</blockquote> |
| 177 |
<p>template MonMessageType tr_MonTemplate := {<br> |
| 178 |
<blockquote>field1 := (1.0 .. 1.99, 2.71) ifpresent<br> |
| 179 |
}</blockquote> |
| 180 |
</font> |
| 181 |
<p>First, we define a record (MonMessageType) containing an optional field. The type of the template will be the one just defined. The template we'll define is called tr_MonTemplate.<br> |
| 182 |
The template accepts the following messages: the first field may be either absent or present. If it is present, its value must either fit in the range 1.0 .. 1.99 or equal 2.71.</p> |
| 183 |
<hr align="left" width="25%"> |
| 184 |
<p><a name="subset">Example 5</a> (excluding a field with superfluous elements): |
| 185 |
<p><font face="Courier New">type set of integer MeinMessageType;</font> |
| 186 |
<p><font face="Courier New"> template MeinMessageType tr_MeinTemplate := subset { 1, 2, 3 };</font> |
| 187 |
<p>The template matches the sets {1,3,1,2} and {1,3} but does not match {4,3,2} and {0,1,2,3,4}. (In the latter sets there are superfluous elements, like 0 or 4)</p> |
| 188 |
<hr align="left" width="25%"> |
| 189 |
<p><a name="superset">Example 6</a> (excluding a field with missing elements): |
| 190 |
<p><font face="Courier New">type set of integer MeenMessageType;</font> |
| 191 |
<p><font face="Courier New"> template MeenMessageType tr_MeenTemplate := superset { 1, 2, 3 };</font> |
| 192 |
<p>The template matches the sets {1,3,1,2} and {0,1,2,3,4} but does not match {1,3} and {4,3,2}. (In the latter sets there are missing elements, like 2 or 1)</p> |
| 193 |
<hr align="left" width="25%"> |
| 194 |
<p><a name="Example 7">Example 7</a>: (character pattern matching)</p> |
| 195 |
<p><font face="Courier New">template charstring tr_AzulejoTemplate:= pattern "ab?\?xyz*";</font> |
| 196 |
<p>The template tr_AzulejoTemplate would match any character string which consists of the characters 'ab', followed by a single arbitrary character, followed by the characters '?xyz', followed by |
| 197 |
any number of any characters.</p> |
| 198 |
<hr align="left" width="25%"> |
| 199 |
<p><a name="Example 4">Example 8</a> (modified template): |
| 200 |
<p><font face="Courier New">// Parent template:<br> |
| 201 |
template MyMsgType t_MyMessage1 := {<br> |
| 202 |
<blockquote>field1 := 123,<br> |
| 203 |
field2 := true<br> |
| 204 |
}</p> |
| 205 |
</blockquote> |
| 206 |
// modified template: |
| 207 |
<br> |
| 208 |
template MyMsgType t_MyMessage2 modifies t_MyMessage1 :={ |
| 209 |
<br> |
| 210 |
<blockquote>field2 := false<br> |
| 211 |
} |
| 212 |
</p> |
| 213 |
</blockquote> |
| 214 |
</font> |
| 215 |
<p>The modified template (t_MyMessage2) has the same structure (the same fields) as the parent template (t_MyMessage1). The first field has the same value as specified in the parent template, but |
| 216 |
the second one has a new value assigned (false). |
| 217 |
<hr align="left" width="25%"> |
| 218 |
<hr align="left" width="25%"> |
| 219 |
<p><a HREF="../info/BNF.html#templatedef">BNF definition</a> of <font face="Courier New"> template</font> (sense 1)<br> |
| 220 |
<a HREF="BNF.html#formaltemplatepar">BNF definition</a> of <font face="Courier New"> template</font> (sense 2)</p> |
| 221 |
</body> |
| 222 |
</html> |