6-mapping_ttcn3_data_types_to_c++_constructs.adoc 113 KB
Newer Older
Elemer Lelik's avatar
Elemer Lelik committed
1
[[mapping-ttcn-3-data-types-to-c-constructs]]
2
= Mapping TTCN–3 Data Types to {cpp} Constructs
Elemer Lelik's avatar
Elemer Lelik committed
3
4
5
:table-number: 7
:toc:

6
The TTCN–3 language elements of the test suite are individually mapped into more or less equivalent {cpp} constructs. The data types are mapped to {cpp} classes, the test cases become {cpp} functions, and so on. In order to write a Test Port, it is inevitable to be familiar with the internal representation format of TTCN–3 data types and values. This section gives an overview about the data types and their equivalent {cpp} constructs.
Elemer Lelik's avatar
Elemer Lelik committed
7
8
9
10

[[mapping-of-names-and-identifiers]]
== Mapping of Names and Identifiers

11
12
In order to identify the TTCN–3 language elements in the generated {cpp} program properly,
the names of test suite are translated to {cpp} identifiers according to the following simple rules.
Elemer Lelik's avatar
Elemer Lelik committed
13

14
15
16
If the TTCN–3 identifier does not contain any underscore (_) character, 
its equivalent {cpp} identifier will be the same. 
For example, the TTCN–3 variable `MyVar` will be translated to a {cpp} variable called `MyVar`.
Elemer Lelik's avatar
Elemer Lelik committed
17

18
19
20
If the TTCN–3 identifier contains one or more underscore characters,
each underscore character will be duplicated in the {cpp} identifier.
So the TTCN–3 identifier `My_Long_Name` will be mapped to a {cpp} identifier called `My\__Long__Name`.
Elemer Lelik's avatar
Elemer Lelik committed
21

22
The idea behind this name mapping is that we may freely use the {cpp} identifiers containing one underscore character in the generated code and in the Test Ports as well. Otherwise name clashes can always happen because the name space of TTCN–3 and {cpp} is identical. Furthermore, the generated {cpp} language elements fulfill the condition that the scope of a translated {cpp} identifier is identical as the scope of the original TTCN–3 identifier.
Elemer Lelik's avatar
Elemer Lelik committed
23

24
The identifiers that are keywords of C or {cpp} but not keywords in TTCN–3 are mapped to themselves, but a single underscore character is appended at the end (for example `typedef` becomes `typedef_`). The same rule applies to the all-uppercase identifiers that are used in the Base Library: identifier `INTEGER` in TTCN–3 becomes `INTEGER_` in {cpp}, `TRUE` footnote:[The built-in `verdict` and `boolean` constants in TTCN–3 shall be written with all lowercase letters, such as true or pass. Although previous compiler versions have accepted `TRUE` or `PASS` as well, these words are treated by the compiler as regular identifiers as specified in the standard.] is mapped to `TRUE_`, etc.
Elemer Lelik's avatar
Elemer Lelik committed
25
26
27
28
29
30
31
32
33
34
35

Here is the complete list (in alphabetical order) of the identifiers that are handled in such special way:asm, auto, bitand, bitor, bool, break, case, class, compl, continue, delete, double, enum, explicit, export, friend, inline, int, ischosen, long, main, mutable, namespace, new, operator, private, protected, public, register, short, signed, static, stderr, stdin, stdout, struct, switch, this, throw, try, typedef, typeid, typename, unsigned, using, virtual, void, volatile, ADDRESS, BITSTRING, BOOLEAN, CHAR, CHARSTRING, COMPONENT, DEFAULT, ERROR, FAIL, FALSE, FLOAT, HEXSTRING, INCONC, INTEGER, NONE, OBJID, OCTETSTRING, PASS, PORT, TIMER, TRUE, VERDICTTYPE.

The identifiers that are the names of common preprocessor macros of the C library (such as `putchar`, `errno` or `NULL`) should be avoided in TTCN–3 modules. The name clashes with macros can cause mysterious compilation error messages.

Note that these name mapping rules apply to *all* TTCN–3 identifiers, including module, Test Port, type, field, variable and function names.

WARNING: By default, from version 1.2.pl0 the compiler does NOT duplicate the underscores in output file names and file references (for example when handling imports).

== Namespaces

36
The compiler generates a {cpp} namespace for every TTCN–3 and ASN.1 module. All {cpp} definitions that belong to the module (including Test Port classes and external functions) are placed in that namespace. The name of the namespace is derived from the module identifier according to the rules described in <<mapping-of-names-and-identifiers, Mapping of Names and Identifiers>>.
Elemer Lelik's avatar
Elemer Lelik committed
37
38
39

The definitions of the TTCN–3 Base Library do not use any namespace.

40
When accessing a {cpp} entity that belongs to a different module than the referring Test Port or external function is in the reference has to be prefixed with the namespace of the referenced module. For example, to access the {cpp} class that realizes type `MyType` defined in module `MyExample1` from a Test Port that belongs to module `MyExample2` the reference shall be written as `MyExample1::MyType`.
Elemer Lelik's avatar
Elemer Lelik committed
41
42
43
44

[[predefined-ttcn-3-data-types]]
== Predefined TTCN–3 Data Types

45
46
47
There are some basic data types in TTCN–3 that have no equivalent data types in language C/{cpp} (for example bitstring, verdicttype). Other types have {cpp} equivalent, but the TTCN–3 executor must know whether a variable has a valid value or not because sending an unbound value must result in a dynamic test case error.
Thus, in the TTCN–3 Base Library all basic data types of TTCN–3 were implemented as {cpp} classes.
This section describes the member functions of these classes.
Elemer Lelik's avatar
Elemer Lelik committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

=== `Integer`

The TTCN–3 type `integer` is implemented in class `INTEGER`. +
The class `INTEGER` has the following public member functions:

.Public member functions of the class `INTEGER`
[cols=",,",]
|==================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`INTEGER()` |Initializes to unbound value.
|`INTEGER(int)` |Initializes to a given value.
|`INTEGER(const INTEGER&`) |Copy constructor.
|`explicit INTEGER(const char *)` |Initializes with the (NUL terminated) string representation of an integer.
^.^|_Destructor_
|`˜INTEGER()` |
.2+^.^|_Assignment operators_
|`INTEGER()` |Initializes to unbound value.
|`INTEGER()` |Initializes to unbound value.
.12+^.^|_Comparison operators_
| boolean operator==(int) const | Returns TRUE if equals
| boolean operator==(const INTEGER&) const | and FALSE otherwise.
| boolean operator!=(int) const  |
| boolean operator!=(const INTEGER&) const  |
| boolean operator<(int) const  |
| boolean operator<(const INTEGER&) const  |
| boolean operator<=(int) const  |
| boolean operator<=(const INTEGER&) const  |
| boolean operator>(int) const  |
| boolean operator>(const INTEGER&) const  |
| boolean operator>=(int) const  |
| boolean operator>=(const INTEGER&) const  |
.12+^.^|_Arithmetic operators_
| INTEGER operator+() const |Unary plus.
| INTEGER operator-() const |Unary minus.
| INTEGER operator+(int) const |Addition.
| INTEGER operator+(const INTEGER&) const |
| INTEGER operator-(int) const |Subtraction.
| INTEGER operator-(const INTEGER&) const |
| INTEGER operator*(int) const |Multiplication.
| INTEGER operator*(const INTEGER&) const |
| INTEGER operator/(int) const |Integer division.
| INTEGER operator/(const INTEGER&) const |
| INTEGER& operator++() |Incrementation (prefix).
| INTEGER& operator—() |Decrementation (prefix).
^.^|_Casting operator_
| operator int() const |Returns the value.
.5+^.^|_Other member functions_
| `void log() const` |Puts the value into log.
| `boolean is_bound() const` |Returns whether the value is bound.
| `void clean_up()` |Deletes the value, setting it to unbound.
| `long long int get_long_long_val() const` |Returns the value as a long long `int`.
| `void set_long_long_val(long long int)` |Sets the given long long `int` value.
|==================================================

The comparison, arithmetic and shifting operators are also available as global functions for that case when the left side is `int` and the right side is `INTEGER`. Using the value of an unbound variable for anything will cause dynamic test case error.

106
The casting operator `int()` is applicable only to `INTEGER` objects holding a signed value with at most 31 useful bits, since in C/{cpp} the native `int` type is 32-bit large including the sign bit. Casting an `INTEGER` object holding a bigger (for example a 32-bit unsigned) value will result in run-time error.
Elemer Lelik's avatar
Elemer Lelik committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

Please note that if the value stored in an `INTEGER` object is too big (that is, it cannot be represented as a `long long int`) the value returned by `get_long_long_val()` will contain only the lowest `sizeof(long long int)` bytes of the original value. Another way to obtain a value of a number having more useful bits than 31 is to convert the INTEGER object to its string representation using the `int2str()` predefined function. Then the string value can be converted to any native integer type using the `sscanf()` library function or such. The following example demonstrates a common scenario:
[source]
----
unsigned int get_unsigned_int_val(const INTEGER& other_value)
{
  unsigned int ret_val = 0;
  sscanf((const char *)int2str(), “%u”, &ret_val);
  return ret_val;
}
----

In addition, the following global functions are available for modulo division. These functions return the result of `mod` and `rem` operations according to TTCN–3 semantics.
[source]
----
INTEGER mod(const INTEGER& left_operand, const INTEGER& right_operand);
INTEGER mod(const INTEGER& left_operand, int right_operand);
INTEGER mod(int left_operand, const INTEGER& right_operand);
INTEGER mod(int left_operand, int right_operand);

INTEGER rem(const INTEGER& left_operand, const INTEGER& right_operand);
INTEGER rem(const INTEGER& left_operand, int right_operand);
INTEGER rem(int left_operand, const INTEGER& right_operand);
INTEGER rem(int left_operand, int right_operand);
----

Other operators (global functions):
[source]
----
INTEGER operator+(int int_value, const INTEGER& other_value);  // Add
INTEGER operator-(int int_value, const INTEGER& other_value);  // Subtract
INTEGER operator*(int int_value, const INTEGER& other_value);  // Multiply
INTEGER operator/(int int_value, const INTEGER& other_value);  // Divide
boolean operator==(int int_value, const INTEGER& other_value); // Equal
boolean operator!=(int int_value, const INTEGER& other_value); // Not equal
boolean operator<(int int_value, const INTEGER& other_value);  // Less than
boolean operator>(int int_value, const INTEGER& other_value);  // More than
----

=== `Float`

The TTCN–3 type `float` is implemented in class `FLOAT`. +
The class `FLOAT` has the following public member functions:

.Public member functions of the class `FLOAT`

[width="100%",cols=",,"]
|=================================================================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`FLOAT()` |Initializes to unbound value.
|`FLOAT(double)` |Initializes to a given value.
|`FLOAT(const FLOAT&`) |Copy constructor.
^.^|_Destructor_
|`˜FLOAT()` |
.2+^.^|Assignment operators
|`FLOAT& operator=(double)`  |Assigns the given value
|`FLOAT& operator=(const FLOAT&)` |and sets the bound flag.
.12+^.^|_Comparison operators_
|boolean operator==(double) const |Returns TRUE if equals
|boolean operator==(const FLOAT&) const  |and FALSE otherwise.
|boolean operator!=(double) const  |
|boolean operator!=(const FLOAT&) const  |
|boolean operator<(double) const  |
|boolean operator<(const FLOAT&) const  |
|boolean operator<=(double) const  |
|boolean operator<=(const FLOAT&) const  |
|boolean operator>(double) const  |
|boolean operator>(const FLOAT&) const  |
|boolean operator>=(double) const  |
|boolean operator>=(const FLOAT&) const  |
.10+^.^|_Arithmetic operators_
|double operator+() const  |Unary plus.
|double operator-() const  |Unary minus.
|double operator+(double) const |Addition.
|double operator+(const FLOAT&) const  |
|double operator-(double) const  |Subtraction.
|double operator-(const FLOAT&) const  |
|double operator*(double) const  |Multiplication.
|double operator*(const FLOAT&) const  |
|double operator/(double) const  |Division.
|double operator/(const FLOAT&) const  |
^.^|_Casting operator_
|operator double() const |Returns the value.
.3+^.^|_Other member functions_
|`void log() const`|Puts the value into log, either in exponential or decimal dot notation.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.

|=================================================================================================

The comparison and arithmetic operators are also available as global functions for that case when the left side is `double` and the right side is `FLOAT`. Using the value of an unbound variable for anything will cause dynamic test case error.

Other operators (global functions):
[source]
----
FLOAT operator+(double double_value, const FLOAT& other_value);    // Add
FLOAT operator-(double double_value, const FLOAT& other_value);    // Subtract
FLOAT operator*(double double_value, const FLOAT& other_value);    // Multiply
FLOAT operator/(double double_value, const FLOAT& other_value);    // Divide
boolean operator==(double double_value, const FLOAT& other_value); // Equal
boolean operator!=(double double_value, const FLOAT& other_value); // Not equal
boolean operator<(double double_value, const FLOAT& other_value);  // Less than
boolean operator>(double double_value, const FLOAT& other_value);  // More than
----

=== `Boolean`

The TTCN–3 type `boolean` is implemented in class `BOOLEAN`.We have introduced an ancillary C enumerated type called `boolean` to set and get values. It may have two predefined values: `TRUE` or `FALSE`. You may use `boolean` values in C conditions since `FALSE` equals to zero and `TRUE` is not zero. +
The class `BOOLEAN` has the following public member functions:

.Public member functions of the class `BOOLEAN`

[cols=",,",,]
|==================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`BOOLEAN()` |Initializes to unbound value.
|`BOOLEAN(boolean)` |Initializes to a given value.
|`BOOLEAN(const BOOLEAN&)` | Copy constructor.
^.^|_Destructor_
|`˜BOOLEAN()` |
.2+^.^|_Assignment operators_
|`BOOLEAN& operator=(boolean)` |Assigns the given value
|`BOOLEAN& operator=(const BOOLEAN&)` |and sets the bound flag.
.4+^.^|_Comparison operators_
|boolean operator==(boolean) const |Returns TRUE if equals
|boolean operator==(const BOOLEAN&) const |and FALSE otherwise.
|boolean operator!=(boolean) const |Same as XOR.
|boolean operator!=(const BOOLEAN&) const |
.8+^.^|_Logical operators_
|boolean operator!() const |Negation (NOT).
|boolean operator&&(boolean) const |Logical AND.
|boolean operator&&(const BOOLEAN&) const |
|boolean operator|(boolean) const |Logical OR.
|boolean operator|(const BOOLEAN&) const |
|boolean operatorˆ(boolean) const |Exclusive or (XOR).
|boolean operatorˆ(const BOOLEAN&) const |
^.^|_Casting operator_
|operator boolean() const |Returns the value.
.3+^.^|_Other member functions_
|`void log() const` |Puts the value into log. Like “TRUE” or “FALSE”.
|`boolean is_bound() const` |Returns whether the value is bound
|`void clean_up()` |Deletes the value, setting it to unbound.

|==================================================

The comparison and logical operators are also available as global functions for that case when the left side is `boolean` and the right side is `BOOLEAN`. Using the value of an unbound variable for anything will cause dynamic test case error.

Other operators (global functions):
[source]
----
BOOLEAN operator&&(boolean bool_value, const BOOLEAN& other_value); // And
BOOLEAN operator^(boolean bool_value, const BOOLEAN& other_value);  // Not
BOOLEAN operator||(boolean bool_value, const BOOLEAN& other_value); // Or
boolean operator==(boolean bool_value, const BOOLEAN& other_value); // Equal
boolean operator!=(boolean bool_value, const BOOLEAN& other_value);// Not equal
----

=== `Verdicttype`

The TTCN–3 type `verdicttype` is implemented in class `VERDICTTYPE`. We have introduced an ancillary C enumerated type called `verdicttype` to set and get values. It may have five predefined values: `NONE`, `PASS`, `INCONC`, `FAIL` or `ERROR`.
The order of these values is `NONE < PASS < INCONC < FAIL < ERROR`. The class `VERDICTTYPE` has the following public member functions:

.Public member functions of the class `VERDICTTYPE`

[cols=",,",,]
|==================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`VERDICTTYPE()` |Initializes to unbound value.
|`VERDICTTYPE(verdicttype)`  |Initializes to a given value.
|`VERDICTTYPE(const VERDICTTYPE&)`  |Copy constructor.
^.^|_Destructor_
|`˜VERDICTTYPE()` |
.2+^.^|_Assignment operators_
|`VERDICTTYPE& operator=(verdicttype)` |Assigns the given value
|`VERDICTTYPE& operator= (const VERDICTTYPE&)`  |and sets the bound flag.
.4+^.^|_Comparison operators_
|boolean operator==(verdicttype) const |Returns TRUE if equals
|boolean operator==(const VERDICTTYPE&) const  |and FALSE otherwise.
|boolean operator!=(verdicttype) const  |
|boolean operator!=(const VERDICTTYPE&) const  |
^.^|_Casting operator_ |Returns the value.
|operator verdicttype() const  |Returns the value.
.3+^.^|_Other member functions_ |Puts the value into log.
|`void log() const`|Puts the value into log. |Like “pass” or “fail”.
|`boolean is_bound() const` | Returns whether the value is bound.
|`void clean_up()` | Deletes the value, setting it to unbound.
|==================================================

The comparison operators are also available as global functions for that case when the left side is `verdicttype` and the right side is `VERDICTTYPE`. Using the value of an unbound `VERDICTTYPE` variable for anything will cause dynamic test case error.

From version 1.2.pl0 there are the following three static member functions in class `TTCN_Runtime` defined in the Base Library for getting or modifying the local verdict of the current test components:
[source]
----
void TTCN_Runtime::setverdict(verdicttype);
void TTCN_Runtime::setverdict(const VERDICTTYPE&);
verdicttype TTCN_Runtime::getverdict();
----

308
These functions are the {cpp} equivalents of TTCN–3 `setverdict` and `getverdict` operations. Use them only if your Test Port or {cpp} function encounters a low-level failure, but it can continue its normal operation (that is, error recovery is not necessary).
Elemer Lelik's avatar
Elemer Lelik committed
309
310
311
312
313
314
315
316
317
318
319
320

Other operators (global functions):
[source]
----
boolean operator==(verdicttype par_value,
                     const VERDICTTYPE& other_value); // Equal
boolean operator!=(verdicttype par_value,
                     const VERDICTTYPE& other_value); // Not equal
----

=== `Bitstring`

321
The equivalent {cpp} class of TTCN–3 type `bitstring` is called `BITSTRING`. The bits of the bit string are stored in an array of unsigned characters. In order to reduce the wasted memory space the bits are packed together, so each character contains eight bits. The first character contains the first eight bits of the bit string; the second byte contains the bits from the 9th up to the 16th, and so on. The first bit of the bit string is the LSB of the first character; the second bit is the second least significant bit of the first character, and so on. The character array is not terminated with a `NUL` character and if the length of the bit string is not a multiple of eight, the unused bits of the last character can contain any value. So the length of the bit string must be always given.
Elemer Lelik's avatar
Elemer Lelik committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354

The class `BITSTRING` has the following public member functions:

.Public member functions of the class `BITSTRING`

[width="100%",cols=",,"]
|==============================================================================================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`BITSTRING()` |Initializes to unbound value.
|`BITSTRING(int n_bits, unsigned char *bits_ptr)` |Initializes from a given length
and pointer to character array.
|`BITSTRING(const BITSTRING&)` |Copy constructor.
|`BITSTRING(const BITSTRING_ELEMENT&)` |Initializes from a single bitstring element.
^.^|_Destructor_
|`˜BITSTRING()` |
.2+^.^|_Assignment operators_
|`BITSTRING& operator=(const BITSTRING&)` |Assigns the given value and sets the bound flag.
|`BITSTRING& operator=(const BITSTRING_ELEMENT&`) |Assigns the given single bitstring element.
.4+^.^|_Comparison operators_
|boolean operator==(const BITSTRING&) const |Returns TRUE if equals
|boolean operator==(const BITSTRING_ELEMENT&) const |and FALSE otherwise.
|boolean operator!=(const BITSTRING&) const |
|boolean operator!=(const BITSTRING_ELEMENT&) const |
.2+^.^|_Concatenation operator_
|BITSTRING operator+(const BITSTRING&) const |Concatenates two bitstrings.
|BITSTRING operator+(const BITSTRING_ELEMENT&) const |Concatenates a bitstring and a bitstring element.
.4+^.^|_Index operator_
|BITSTRING_ELEMENT operator[](int) |Gives access to the given element. Indexing begins from zero. Index overflow causes dynamic test case error.
|BITSTRING_ELEMENT operator[](const INTEGER&) |
|const BITSTRING_ELEMENT operator[](int) const |Gives read-only access to the given element.
|const BITSTRING_ELEMENT operator[](const INTEGER&) const |
.8+^.^|_Bitwise operators_
355
356
|BITSTRING operator~() const |{cpp} equivalent of operator not4b. (bitwise negation)
|BITSTRING operator&(const BITSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
357
358
and4b. (bitwise and)
|BITSTRING operator&(const BITSTRING_ELEMENT&) const |
359
|BITSTRING operator|(const BITSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
360
361
or4b. (bitwise or)
|BITSTRING operator|(const BITSTRING_ELEMENT&) const |
362
|BITSTRING operatorˆ(const BITSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
363
364
365
xor4b. (bitwise xor)
|BITSTRING operator^(const BITSTRING_ELEMENT&) const |
.8+^.^|_Shifting and rotating operators_
366
|BITSTRING operator<<(int) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
367
|BITSTRING operator<<(const INTEGER&) const |<<.(shift left)
368
|BITSTRING operator>>(int) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
369
|BITSTRING operator>>(const INTEGER&) const |>>. (shift right)
370
|BITSTRING operator<<=(int) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
371
|BITSTRING operator<<=(const INTEGER&) const |< @. (rotate left)
372
|BITSTRING operator>>=(int) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|BITSTRING operator>>=(const INTEGER&) const |@ >. (rotate right)
^.^|_Casting operator_
|operator const unsigned char*() const |Returns a pointer to the character array.
.4+^.^|_Other member functions_
|`int lengthof() const` |Returns the length measured in bits.
|`void log() const` |Puts the value into log.
Example: ’100011’B.
|`boolean is_bound() const` |Deletes the value, setting it to unbound
|`void clean_up()` |

|==============================================================================================================================

Using the value of an unbound `BITSTRING` variable for anything will cause dynamic test case error.

==== `Bitstring element`

389
The {cpp} class `BITSTRING_ELEMENT` is the equivalent of the TTCN-3 `bitstring`’s element type (the result of indexing a `bitstring` value). The class does not store the actual bit, only a reference to the original `BITSTRING` object, an index value and a bound flag.
Elemer Lelik's avatar
Elemer Lelik committed
390

balaskoa's avatar
Typo    
balaskoa committed
391
NOTE: changing the value of the `BITSTRING_ELEMENT` (through the assignment operator) changes the referenced bit in the original `bitstring` object.
Elemer Lelik's avatar
Elemer Lelik committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

The class `BITSTRING_ELEMENT` has the following public member functions:

.Public member functions of the class `BITSTRING_ELEMENT`

[width="100%",cols=,,",,]
|========================================================================================================================================================
2+^.^|*Member functions* |*Notes*
|_Constructor_
|`BITSTRING_ELEMENT`(boolean par_bound_flag, BITSTRING& par_str_val, int par_bit_pos) |Initializes the object with an unbound value or a reference to a bit in an existring BITSTRING object.
.2+^.^|_Assignment operators_
|`BITSTRING_ELEMENT& operator=(const BITSTRING&)` |Sets the referenced bit to the given bitstring of length 1.
|`BITSTRING_ELEMENT& operator=(const BITSTRING_ELEMENT&)` |Sets the referenced bit to the given bitstring element.
.4+^.^|_Comparison operators_
|boolean operator==(const BITSTRING&) const |Comparison with a bitstring or a bitstring element (the value of the referenced bits is compared, not the references and indexes).
|boolean operator==(const BITSTRING_ELEMENT&) const |
|boolean operator!=(const BITSTRING&) const |
|boolean operator!=(const BITSTRING_ELEMENT&) const |
.2+^.^|_Concatenation operator_
|BITSTRING operator+(const BITSTRING&) const |Concatenates a bitstring element with a bitstring, or two bitstring elements.
|BITSTRING operator+(const BITSTRING_ELEMENT&) const |
.8+^.^|_Bitwise operators_
414
415
|BITSTRING operator~() const |{cpp} equivalent of operator not4b. (bitwise negation)
|BITSTRING operator&(const BITSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
416
417
and4b. (bitwise and)
|BITSTRING operator&(const BITSTRING_ELEMENT&) const  |
418
|BITSTRING operator|(const BITSTRING&) const  | {cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
419
420
or4b. (bitwise or)
|BITSTRING operator|(const BITSTRING_ELEMENT&) const  |
421
|BITSTRING operatorˆ(const BITSTRING&) const | {cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
422
423
424
425
426
427
428
429
430
431
432
433
434
xor4b. (bitwise xor)
|BITSTRING operatorˆ(const BITSTRING_ELEMENT&) const |
.4+^.^|_Other member functions_
|`boolean get_bit() const` |Returns the referenced bit.
|`void log() const` | Puts the value into log.
Example: '1'B.
|`boolean is_bound() const` | Returns whether the value is bound.
|========================================================================================================================================================

Using the value of an unbound `BITSTRING_ELEMENT` variable for anything will cause dynamic test case error.

=== `Hexstring`

435
The equivalent {cpp} class of TTCN–3 type `hexstring` is called `HEXSTRING`. The hexadecimal digits (nibbles) are stored in an array of unsigned characters. In order to reduce the wasted memory space two nibbles are packed into one character. The first character contains the first two nibbles of the `hexstring`, the second byte contains the third and fourth nibbles, and so on. The hexadecimal digits at odd (first, third, fifth, etc.) positions occupy the lower 4 bits in the characters; the even ones use the upper 4 bits. The character array is never terminated with a `NUL` character, so the length must be always given with the pointer. If the `hexstring` has odd length the unused upper 4 bits of the last character may contain any value.
Elemer Lelik's avatar
Elemer Lelik committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

The class `HEXSTRING` has the following public member functions:

.Public member functions of the class `HEXSTRING`

[width="100%",cols=",,",options="header",]
|==============================================================================================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`HEXSTRING()` |Initializes to unbound value.
|`HEXSTRING(int n_nibbles, const unsigned char *nibbles_ptr)` |Initializes from a given length and pointer to the character array.
|`HEXSTRING(const HEXSTRING&)`|
|`HEXSTRING(const HEXSTRING_ELEMENT&)`|
^.^|_Destructor_
|`˜HEXSTRING()`  |
.2+^.^|_Assignment operators_
|`HEXSTRING& operator=(const HEXSTRING&)` |Assigns the given value
|`HEXSTRING& operator=(const HEXSTRING_ELEMENT&)` |
.4+^.^|_Comparison operators_
|boolean operator==(const HEXSTRING&) const  |Returns TRUE if equals and FALSE otherwise.
|boolean operator==(const HEXSTRING_ELEMENT&) const |
|boolean operator!=(const HEXSTRING&) const  |
|boolean operator!=(const HEXSTRING_ELEMENT&) const |
.2+^.^|_Concatenation operator_
|HEXSTRING operator+(const HEXSTRING&) const |Concatenates two hexstrings.
|HEXSTRING operator+(const HEXSTRING_ELEMENT&) const |Concatenates a hexstring and a hexstring element.
.4+^.^|_Index operator_
|HEXSTRING_ELEMENT operator[](int) |Gives access to the given element. Indexing begins from zero. Index overflow causes dynamic test case error.
|HEXSTRING_ELEMENT operator[](const INTEGER&) |
|const HEXSTRING_ELEMENT operator[](int) const |
|const HEXSTRING_ELEMENT operator[](const INTEGER&) const |
.8+^.^|_Bitwise operators_
468
469
|HEXSTRING operator~() const  |{cpp} equivalent of operator not4b. (bitwise negation)
|HEXSTRING operator&(const HEXSTRING&) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
470
471
and4b. (bitwise and)
|HEXSTRING operator&(const HEXSTRING_ELEMENT&) const  |
472
|HEXSTRING operator|(const HEXSTRING&) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
473
474
or4b. (bitwise or)
|HEXSTRING operator|(const HEXSTRING_ELEMENT&) const  |
475
|HEXSTRING operatorˆ(const HEXSTRING&) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
476
477
478
xor4b. (bitwise xor)
|HEXSTRING operator^(const HEXSTRING_ELEMENT&) const  |
.8+^.^|_Shifting and rotating operators_
479
|HEXSTRING operator<<(int) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
480
|HEXSTRING operator<<(const INTEGER&) const  |<<.(shift left)
481
|HEXSTRING operator>>(int) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
482
|HEXSTRING operator>>(const INTEGER&) const  |>>. (shift right)
483
|HEXSTRING operator<<=(int) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
484
|HEXSTRING operator<<=(const INTEGER&) const  |< @. (rotate left)
485
|HEXSTRING operator>>=(int) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|HEXSTRING operator>>=(const INTEGER&) const  |@ >. (rotate right)
^.^|_Casting operator_
|operator const unsigned char*() const |Returns a pointer to the character array. The pointer might be NULL if the length is 0.
.4+^.^|_Other member functions_
|`int lengthof() const` |Returns the length measured in nibbles.
|`void log() const` |Puts the value into log. Example: ’5A7’H.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|==============================================================================================================================

Using the value of an unbound `HEXSTRING` variable for anything will cause a dynamic test case error.

==== `Hexstring` element

500
The {cpp} class `HEXSTRING_ELEMENT` is the equivalent of the TTCN-3 `hexstring`’s element type (the result of indexing a `hexstring` value). The class does not store the actual hexadecimal digit (nibble), only a reference to the original HEXSTRING object, an index value and a bound flag.
Elemer Lelik's avatar
Elemer Lelik committed
501

balaskoa's avatar
Typo    
balaskoa committed
502
NOTE: changing the value of the `HEXSTRING_ELEMENT` (through the assignment operator) changes the referenced nibble in the original `hexstring` object.
Elemer Lelik's avatar
Elemer Lelik committed
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524

The class `HEXSTRING_ELEMENT` has the following public member functions:

.Public member functions of the class `HEXSTRING_ELEMENT`

[width="100%",cols=",,",options="",]
|===========================================================================================================================================================
2+^.^|*Member functions* |*Notes*
^.^|_Constructor_
| `HEXSTRING_ELEMENT(boolean par_bound_flag`, `HEXSTRING& par_str_val`, `int par_nibble_pos)` |Initializes the object with an unbound value or a reference to a nibble in an existring HEXSTRING object.
.2+^.^|_Assignment operators_
|`HEXSTRING_ELEMENT& operator=(const HEXSTRING&)` |Sets the referenced nibble to the given hexstring of length 1.
|`HEXSTRING_ELEMENT& operator=(const HEXSTRING_ELEMENT&)` | Sets the referenced nibble to the given hexstring element.
.4+^.^|_Comparison operators_
|boolean operator==(const HEXSTRING&) const |Comparison with a hexstring or a hexstring element (the value of the referenced nibbles is compared, not the references and indexes).
|boolean operator==(const HEXSTRING_ELEMENT&) const  |
|boolean operator!=(const HEXSTRING&) const |
|boolean operator!=(const HEXSTRING_ELEMENT&) const  |
.2+^.^|_Concatenation operator_
|HEXSTRING operator+(const HEXSTRING&) const  |Concatenates a hexstring element with a hexstring, or two hexstring elements.
|HEXSTRING operator+(const HEXSTRING_ELEMENT&) const |
.8+^.^|_Bitwise operators_
525
526
|HEXSTRING operator~() const  |{cpp} equivalent of operator not4b. (bitwise negation)
|HEXSTRING operator&(const HEXSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
527
528
and4b. (bitwise and)
|HEXSTRING operator&(const HEXSTRING_ELEMENT&) const  |
529
|HEXSTRING operator|(const HEXSTRING&) const  |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
530
531
or4b. (bitwise or)
|HEXSTRING operator|(const HEXSTRING_ELEMENT&) const  |
532
|HEXSTRING operatorˆ(const HEXSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
533
534
535
536
537
538
539
540
541
542
543
544
545
xor4b. (bitwise xor)
|HEXSTRING operatorˆ(const HEXSTRING_ELEMENT&) const |
.3+^.^|_Other member functions_
|`unsigned char get_nibble() const` |Returns the referenced nibble (stored in the lower 4 bits of the returned character).
|`void log() const` |Puts the value into log.
Example: '8'H.
|`boolean is_bound() const` |Returns whether the value is bound.
|===========================================================================================================================================================

Using the value of an unbound `HEXSTRING_ELEMENT` variable for anything will cause dynamic test case error.

=== `Octetstring`

546
The equivalent {cpp} class of TTCN–3 type `octetstring` is called `OCTETSTRING`. The octets are stored in an array of unsigned characters. Each character contains one octet; the first character is the first octet of the string. The character array is not terminated by a `NUL` character, so the length of the octet string must be always given.
Elemer Lelik's avatar
Elemer Lelik committed
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

The class `OCTETSTRING` has the following public member functions:

.Public member functions of the class `OCTETSTRING`

[width="100%",cols=",,",options="header",]
|==============================================================================================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`OCTETSTRING()` |Initializes to unbound value.
|`OCTETSTRING(int n_octets, const unsigned char *octets_ptr)` |Initializes from a given length and pointer to character array.
|`OCTETSTRING(const OCTETSTRING&)` |Copy constructor.
|`OCTETSTRING(const OCTETSTRING_ELEMENT&)` |Initializes from a single octetstring element.
^.^|_Destructor_
|`˜OCTETSTRING()` |
.2+^.^|_Assignment operators_
|`OCTETSTRING& operator=(const OCTETSTRING&)` |Assigns the given value and sets the bound flag.
|`OCTETSTRING& operator=(const OCTETSTRING_ELEMENT&)` |Assigns the given octetstring element.
.4+^.^|_Comparison operators_
| boolean operator==(const OCTETSTRING&) const  |Returns TRUE if equals
| boolean operator==(const OCTETSTRING_ELEMENT&) const  |and FALSE otherwise.
| boolean operator!=(const OCTETSTRING&) const  |
| boolean operator!=(const OCTETSTRING_ELEMENT&) const  |
.4+^.^|_Concatenation operator_
|OCTETSTRING operator+(const OCTETSTRING&) const |Concatenates two octetstrings.
|OCTETSTRING operator+(const OCTETSTRING_ELEMENT&) const |Concatenates an octetstring and an octetstring element.
|OCTETSTRING& operator+=(const OCTETSTRING&) const |Appends an octetstring to this one.
|OCTETSTRING& operator+=(const OCTETSTRING_ELEMENT&) const |Appends an octetstring element to this octetstring.
.4+^.^|_Index operator_
|OCTETSTRING_ELEMENT operator[](int) |Gives access to the given element. Indexing begins from zero. Index overflow causes dynamic test case error.
|OCTETSTRING_ELEMENT operator[](const INTEGER&) |
|const OCTETSTRING_ELEMENT operator[](int) const |Gives read-only access to the given element.
|const OCTETSTRING_ELEMENT operator[](const INTEGER&) const |
.8+^.^|_Bitwise operators_
581
582
|OCTETSTRING operator˜() const  |{cpp} equivalent of operator not4b.(bitwise negation)
|OCTETSTRING operator&(const OCTETSTRING&) const |{cpp} equivalent of operator and4b.
Elemer Lelik's avatar
Elemer Lelik committed
583
584
(bitwise and)
|OCTETSTRING operator&(const OCTETSTRING_ELEMENT&) const |
585
|OCTETSTRING operator|(const OCTETSTRING&) const  |{cpp} equivalent of operator or4b.
Elemer Lelik's avatar
Elemer Lelik committed
586
587
(bitwise or)
|OCTETSTRING operator|(const OCTETSTRING_ELEMENT&) const |
588
|OCTETSTRING operatorˆ(const OCTETSTRING&) const |{cpp} equivalent of operator xor4b.
Elemer Lelik's avatar
Elemer Lelik committed
589
590
591
(bitwise xor)
|OCTETSTRING operator^(const OCTETSTRING_ELEMENT&) const |
.8+^.^|_Shifting and rotating operators_
592
|OCTETSTRING operator<<(int) const |{cpp} equivalent of operator <<.
Elemer Lelik's avatar
Elemer Lelik committed
593
|OCTETSTRING operator<<(const INTEGER&) const |(shift left)
594
|OCTETSTRING operator>>(int) const  |{cpp} equivalent of operator >>.
Elemer Lelik's avatar
Elemer Lelik committed
595
|OCTETSTRING operator>>(const INTEGER&) const  |(shift right)
596
|OCTETSTRING operator<<=(int) const  |{cpp} equivalent of operator < @.
Elemer Lelik's avatar
Elemer Lelik committed
597
|OCTETSTRING operator<<=(const INTEGER&) const  |(rotate left)
598
|OCTETSTRING operator>>=(int) const  |{cpp} equivalent of operator @ >.
Elemer Lelik's avatar
Elemer Lelik committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|OCTETSTRING operator>>=(const INTEGER&) const  |(rotate right)
^.^|_Casting operator_
|operator const unsigned char*() const |Returns a pointer to the character array. The pointer might be NULL if the length is 0.
.4+^.^|_Other member functions_
|`int lengthof() const`  |Returns the length measured in octets.
|`void log() const` |Puts the value into log.
Like ’073CF0’O.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.

|==============================================================================================================================

Using the value of an unbound `OCTETSTRING` variable for anything will cause dynamic test case error.

==== `Octetstring` element

615
The {cpp} class `OCTETSTRING_ELEMENT` is the equivalent of the TTCN-3 `octetstring`’s element type (the result of indexing an `octetstring` value). The class does not store the actual octet, only a reference to the original OCTETSTRING object, an index value and a bound flag.
Elemer Lelik's avatar
Elemer Lelik committed
616

balaskoa's avatar
Typo    
balaskoa committed
617
NOTE: changing the value of the OCTETSTRING_ELEMENT (through the assignment operator) changes the referenced octet in the original `octetstring` object.
Elemer Lelik's avatar
Elemer Lelik committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

The class `OCTETSTRING_ELEMENT` has the following public member functions:

.Public member functions of the class `OCTETSTRING_ELEMENT`

[width="100%",cols=",,",options="header",]
|================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
^.^|_Constructor_
|`OCTETSTRING_ELEMENT(boolean par_bound_flag`, `OCTETSTRING& par_str_val`, `int par_octet_pos)` |Initializes the object with an unbound value or a reference to an octet in an existring OCTETSTRING object.
.2+^.^|_Assignment operators_
|`OCTETSTRING_ELEMENT& operator=(const OCTETSTRING&)` |Sets the referenced octet to the given octetstring of length 1.
|`OCTETSTRING_ELEMENT& operator=(const OCTETSTRING_ELEMENT&)` |Sets the referenced octet to the given octetstring element.
.4+^.^|_Comparison operators_
|boolean operator==(const OCTETSTRING&) const |Comparison with an octetstring or an octetstring element (the value of the referenced octets is compared, not the references and indexes).
|boolean operator==(const OCTETSTRING_ELEMENT&) const  |
|boolean operator!=(const OCTETSTRING&) const |
|boolean operator!=(const OCTETSTRING_ELEMENT&) const  |
.2+^.^|_Concatenation operator_
| OCTETSTRING operator+(const OCTETSTRING&) const |Concatenates an octetstring element with an octetstring, or two octetstring elements.
| OCTETSTRING operator+(const OCTETSTRING_ELEMENT&) const |
.8+^.^|_Bitwise operators_
640
641
|OCTETSTRING operator~() const |{cpp} equivalent of operator (bitwise negation)
|OCTETSTRING operator&(const OCTETSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
642
643
and4b. (bitwise and)
|OCTETSTRING operator&(const OCTETSTRING_ELEMENT&) const  |
644
|HEXSTRING operator|(const OCTETSTRING&) const  | {cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
645
646
or4b. (bitwise or)
|OCTETSTRING operator|(const OCTETSTRING_ELEMENT&) const  |
647
|OCTETSTRING operatorˆ(const OCTETSTRING&) const |{cpp} equivalent of operator
Elemer Lelik's avatar
Elemer Lelik committed
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
xor4b. (bitwise xor)
|OCTETSTRING operatorˆ(const OCTETSTRING_ELEMENT&) const |
.3+^.^|_Other member functions_
|`unsigned char get_octet() const` |Returns the referenced octet.
|`void log() const` |Puts the value into log.
Example: '3C'O.
|`boolean is_bound() const` |Returns whether the value is bound.

|================================================================================================================================================================

Using the value of an unbound `OCTETSTRING_ELEMENT` variable for anything will cause dynamic test case error.

=== `Char`

The `char` type, which has been removed from the TTCN–3 standard, is no longer supported by the run-time environment. The compiler substitutes all occurrences of `char` type with type `charstring` automatically.

664
To provide partial backward compatibility for older Test Ports that might have used the type `char`, `CHAR` is a typedef alias to class `CHARSTRING` in {cpp}.
Elemer Lelik's avatar
Elemer Lelik committed
665
666
667
668

[[Charstring]]
=== `Charstring`

669
The equivalent {cpp} class of TTCN–3 type `charstring` is called `CHARSTRING`. The characters are stored in a `NUL` character terminated array; thus, giving the length in the constructor and other operations is optional.
Elemer Lelik's avatar
Elemer Lelik committed
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716

The class `CHARSTRING` has the following public member functions:

.Public member functions of the class `CHARSTRING`

[width="100%",cols=",,",,]
|==============================================================================================================================
2+^.^|*Member functions* |*Notes*
.6+^.^|_Constructors_
|`CHARSTRING()`|Initializes to unbound value.
|`CHARSTRING(char)`|Initializes from a single character.
|`CHARSTRING(int n_chars, const char *chars_ptr)`|Initializes from a given length and pointer to character array.
|`CHARSTRING(const char *chars_ptr)`|Initializes from a given character array. The end is noted by a NUL character.
|`CHARSTRING(const CHARSTRING&)`|Copy constructor.
|`CHARSTRING(const CHARSTRING_ELEMENT&)`|Initializes from a charstring element.
^.^|_Destructor_
|`˜CHARSTRING()` |
.4+^.^|_Assignment operators_
|`CHARSTRING& operator=(const CHARSTRING&)`|Assigns the given value and sets the bound flag.
|`CHARSTRING& operator=(const char *)`|Assigns the NUL terminated string.
|`CHARSTRING& operator=(const CHARSTRING_ELEMENT&)`|Assigns the given charstring element.
|`CHARSTRING& operator=(const UNIVERSAL_CHARSTRING&)`|Assigns the given universal charstring value.
.8+^.^|_Comparison operators_
|boolean operator==(const CHARSTRING&) const  |Returns TRUE if equals and FALSE otherwise.
|boolean operator==(const char *) const |Compares to the NUL terminated string.
|boolean operator==(const CHARSTRING_ELEMENT&) const |Comparison with a charstring element.
|boolean operator==(const UNIVERSAL_CHARSTRING&) const |Comparison with a universal charstring.
|boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&) const |Comparison with a universal charstring element.
|boolean operator!=(const CHARSTRING&) const  |
|boolean operator!=(const char *) const |
|boolean operator!=(const CHARSTRING_ELEMENT&) const |
.9+^.^|_Concatenation operator_
|CHARSTRING operator+(const CHARSTRING&) const  |Concatenates two charstrings.
|CHARSTRING operator+(const char *) const |Concatenates with a NUL terminated string.
|CHARSTRING operator+(const CHARSTRING_ELEMENT) const |Concatenates with a charstring element.
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING&) const |Concatenates with a universal charstring.
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&) const |Concatenates with a universal charstring element.
|CHARSTRING operator+=(char) |Appends a character.
|CHARSTRING operator+=(const char *) |Appends a NUL terminated string.
|CHARSTRING operator+=(const CHARSTRING&) |Appends a charstring.
|CHARSTRING operator+=(const CHARSTRING_ELEMENT&) |Appends a charstring element.
.4+^.^|_Index operator_
|CHARSTRING_ELEMENT operator[](int) |Gives access to the given element. Indexing begins from zero. Index overflow causes dynamic test case error.
|CHARSTRING_ELEMENT operator[](const INTEGER&) |
|const CHARSTRING_ELEMENT operator[](int) const |Gives read-only access to the given element.
|const CHARSTRING_ELEMENT operator[](const INTEGER&) const |
.4+^.^|_Rotating operators_
717
|CHARSTRING operator<<=(int) const |{cpp} equivalent of operator < @.(rotate left)
Elemer Lelik's avatar
Elemer Lelik committed
718
|CHARSTRING operator<<=(const INTEGER&) const |
719
|CHARSTRING operator>>=(int) const  |{cpp} equivalent of operator @ >.
Elemer Lelik's avatar
Elemer Lelik committed
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
(rotate right)
|CHARSTRING operator>>=(const INTEGER&) const |
^.^|_Casting operator_
|operator const char*() const |Returns a pointer to the character array. The string is always terminated by NUL.
.3+^.^|_Other member functions_
|`int lengthof() const` |Returns the length measured in characters not including the terminator NUL.
|`void log() const` |Puts the value into log.
Example: ”abc”.
|`boolean is_bound() const`|Returns whether the value is bound.
|`void clean_up()`|Deletes the value, setting it to unbound.

|==============================================================================================================================

The comparison, concatenation and rotating operators are also available as global functions for that case when the left side is `const char*` and the right side is `CHARSTRING`.

The log() member function uses single character output for regular characters, but special characters (such as the quotation mark, backslash or newline characters) are printed using the escape sequences of the C language. Non-printable control characters are printed in TTCN–3 quadruple notation, where the first three octets are always zero. The concatenation operator (`&`) is used between the fragments when necessary. Note that the output does not always conform to TTCN–3 Core Language syntax, but it is always recognized by both our compiler and the configuration file parser.

Using the value of an unbound `CHARSTRING` variable for anything will cause dynamic test case error.

Other operators (global functions):
[source]
----
boolean operator==(const char* string_value,
                     const CHARSTRING& other_value);            // Equal
boolean operator==(const char* string_value,
                     const CHARSTRING_ELEMENT& other_value);    // Equal
boolean operator!=(const char* string_value,
                     const CHARSTRING& other_value);            // Not equal
boolean operator!=(const char* string_value,
                     const CHARSTRING_ELEMENT& other_value);    // Not equal
CHARSTRING operator+(const char* string_value,
                       const CHARSTRING& other_value);          // Concatenation
CHARSTRING operator+(const char* string_value,
                       const CHARSTRING_ELEMENT& other_value);  // Concatenation
----

==== `Charstring` element

758
The {cpp} class `CHARSTRING_ELEMENT` is the equivalent of the TTCN-3 `charstring`’s element type (the result of indexing a `charstring` value). The class does not store the actual character, only a reference to the original CHARSTRING object, an index value and a bound flag.
Elemer Lelik's avatar
Elemer Lelik committed
759

balaskoa's avatar
Typo    
balaskoa committed
760
NOTE: changing the value of the `CHARSTRING_ELEMENT` (through the assignment operator) changes the referenced character in the original `charstring` object.
Elemer Lelik's avatar
Elemer Lelik committed
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

The class `CHARSTRING_ELEMENT` has the following public member functions:

.Public member functions of the class `CHARSTRING_ELEMENT`

[width="100%",cols=",,",options="",]
|================================================================================================================================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
^.^|_Constructor_
|`CHARSTRING_ELEMENT(boolean par_bound_flag`, `CHARSTRING& par_str_val`, `int par_char_pos)` |Initializes the object with an unbound value or a reference to a character in an existring CHARSTRING object.
.3+^.^|_Assignment operators_
|`CHARSTRING_ELEMENT& operator=(const char*)` |Sets the referenced character to the given null-terminated string of length 1.
|`CHARSTRING_ELEMENT& operator=(const CHARSTRING&)` |Sets the referenced character to the given charstring of length 1.
|`CHARSTRING_ELEMENT& operator=(const CHARSTRING_ELEMENT&)` |Sets the referenced character to the given charstring element.
.8+^.^|_Comparison operators_
|boolean operator==(const char*) const |Comparison with a null-terminated string, a charstring, a universal charstring, a charstring element or a universal charstring element (when comparing element types, the value of the referenced characters is compared, not the references and indexes).
|boolean operator==(const CHARSTRING&) const |
|boolean operator==(const CHARSTRING_ELEMENT&) const  |
|boolean operator==(const UNIVERSAL_CHARSTRING&) const |
|boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&) const |
|boolean operator!=(const char*) const  |
|boolean operator!=(const CHARSTRING&) const |
|boolean operator!=(const CHARSTRING_ELEMENT&) const  |
.5+^.^|_Concatenation operator_
|CHARSTRING operator+(const char*) const  |Concatenates this object with a null-terminated string, a charstring, a charstring element, a universal charstring or a universal charstring element.
|CHARSTRING operator+(const CHARSTRING&) const |
|CHARSTRING operator+(const CHARSTRING_ELEMENT&) const |
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING&) const |
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&) const  |
.3+^.^|_Other member functions_
|`char get_char() const` |Returns the referenced character.
|`void log() const` |Puts the value into log. Example: “a”.
|`boolean is_bound() const` |Returns whether the value is bound.

|================================================================================================================================================================================================================================================================================

Using the value of an unbound `CHARSTRING_ELEMENT` variable for anything will cause dynamic test case error.

=== `Universal char`

This obsolete TTCN–3 type is converted automatically to `universal charstring` in the parser.

=== `Universal charstring`

Each character of a `universal charstring` value is represented in the following C structure defined in the Base Library:
[source]
----
struct universal_char {
  unsigned char uc_group, uc_plane, uc_row, uc_cell;
};
----

The four components of the quadruple (that is, group, plane, row and cell) are stored in fields `uc_group`, `uc_plane`, `uc_row` and `uc_cell`, respectively. All fields are 8bit unsigned numeric values with the possible value range 0 .. 255.

In case of single-octet characters, which can be also given in TTCN–3 charstring notation (between quotation marks), the fields `uc_group`, `uc_plane`, `uc_row` are set to zero. If tuple notation was used for an ASN.1 string value fields `uc_row` and `uc_cell` carry the tuple and the others are set to zero.

817
Except when performing encoding or decoding, the run-time environment does not check whether the quadruples used in the following API represent valid character positions according to <<8-references.adoc#_8,[8]>>. Moreover, if ASN.1 multi-octet character string values are used, it is not verified whether the elements of such strings are permitted characters of the corresponding string type.
Elemer Lelik's avatar
Elemer Lelik committed
818

819
The {cpp} equivalent of TTCN–3 type `universal charstring` is implemented in class `UNIVERSAL_CHARSTRING`. The characters of the string are stored in an array of structure `universal_char`. The array returned by the casting operator is not terminated with a special character, thus, the length of the string must be always considered when doing operations with the array. The length of the string, which can be obtained by using member function `lengthof()`, is measured in characters (quadruples) and not bytes.
Elemer Lelik's avatar
Elemer Lelik committed
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876

For the more convenient usage the strings containing only single-octet characters can also be used with class `UNIVERSAL_CHARSTRING`. Therefore some polymorphic member functions and operators have variants that take `const char*` as argument. In these member functions the characters of the `NUL` character terminated string are implicitly converted to quadruples with group, plane and row fields set to zero. `NULL` pointer as argument means the empty string for these functions.

The class `UNIVERSAL_CHARSTRING` has the following public member functions:

.Public member functions of the class `UNIVERSAL_CHARSTRING`

[width="100%",cols=",,",options="",]
|==============================================================================================================================
2+^.^|*Member functions* |*Notes*
.10+^.^|_Constructors_
|`UNIVERSAL_CHARSTRING()`|Initializes to unbound value.
|`UNIVERSAL_CHARSTRING (unsigned char group, unsigned char plane, unsigned char row, unsigned char cell)`| Constructs a string containing one character formed from the given quadruple.
|`UNIVERSAL_CHARSTRING (const universal_char&)`| Constructs a string containing the given single character.
|`UNIVERSAL_CHARSTRING (int n_uchars, const universal_char *uchars_ptr)`| Constructs a string from an array by taking the given number of single-octet characters.
|`UNIVERSAL_CHARSTRING (const char *chars_ptr)`| Constructs a string from a NUL terminated array of single-octet characters.
|`UNIVERSAL_CHARSTRING (int n_chars, const char *chars_ptr)`| Constructs a string from a given number of single-octet characters.
|`UNIVERSAL_CHARSTRING (const CHARSTRING&)`| Constructs a universal charstring from a charstring value.
|`UNIVERSAL_CHARSTRING (const CHARSTRING_ELEMENT&)`| Constructs a string containing the given singe charstring element.
|`UNIVERSAL_CHARSTRING (const UNIVERSAL_CHARSTRING&)`| Copy constructor.
|`UNIVERSAL_CHARSTRING (const UNIVERSAL_CHARSTRING_ELEMENT&)`| Constructs a string containing the given singe universal charstring element.
^.^|_Destructor_
|`˜UNIVERSAL_CHARSTRING()` |
.6+^.^|_Assignment operators_
|`UNIVERSAL_CHARSTRING& operator= (const UNIVERSAL_CHARSTRING&)`  |Assigns another string.
|`UNIVERSAL_CHARSTRING& operator= (const universal_char&)` |Assigns a single character.
|`UNIVERSAL_CHARSTRING& operator= (const char*)` |Assigns a NUL terminated
single-octet string.
|`UNIVERSAL_CHARSTRING& operator= (const CHARSTRING&)` |Assigns a charstring.
|`UNIVERSAL_CHARSTRING& operator= (const CHARSTRING_ELEMENT&)` |Assigns a single charstring element.
|`UNIVERSAL_CHARSTRING& operator= (const UNIVERSAL_CHARSTRING_ELEMENT&)` |Assigns a single universal charstring element.
.12+^.^|_Comparison operators_
|boolean operator==(const UNIVERSAL_CHARSTRING&) const  |Returns TRUE if the strings are identical or FALSE otherwise.
|boolean operator==(const universal_char&) const  |Compares to a single character.
|boolean operator==(const char*) const |Compares to a NUL terminated printable string.
|boolean operator==(const CHARSTRING&) const |Compares to a charstring.
|boolean operator==(const CHARSTRING_ELEMENT&) const |Compares to a charstring element.
|boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&) const |Compares to a universal charstring element.
|boolean operator!=(const UNIVERSAL_CHARSTRING&) const  |
|boolean operator!= (const universal_char&) const  |
|boolean operator!=(const char*) const  |
|boolean operator!=(const CHARSTRING&) |
|boolean operator!=(const CHARSTRING_ELEMENT&) const |
|boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT&) const |
.6+^.^|_Concatenation operator_
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING&) const  |Concatenates two strings.
|UNIVERSAL_CHARSTRING operator+(const universal_char&) const  |Concatenates a single character.
|UNIVERSAL_CHARSTRING operator+(const char*) const  |Concatenates a NUL terminated single-octet string.
|UNIVERSAL_CHARSTRING operator+(const CHARSTRING&) const |Concatenates a charstring.
|UNIVERSAL_CHARSTRING operator+(const CHARSTRING_ELEMENT&) const |Concatenates a charstring element.
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&) const  |Concatenates a universal charstring element.
.4+^.^|_Index operator_
|UNIVERSAL_CHARSTRING_ELEMENT operator[](int) |Gives access to the given element. Indexing begins from zero. Index overflow causes dynamic test case error.
|UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER&) |
|const UNIVERSAL_CHARSTRING_ELEMENT operator[](int) const |Gives read-only access to the given element.
|const UNIVERSAL_CHARSTRING_ELEMENT operator[](const INTEGER&) const |
.4+^.^|_Rotating operators_
877
|UNIVERSAL_CHARSTRING operator<<=(int) const |{cpp} equivalent of operator < @(rotate left).
Elemer Lelik's avatar
Elemer Lelik committed
878
|UNIVERSAL_CHARSTRING operator<<=(const INTEGER&) const |
879
|UNIVERSAL_CHARSTRING operator>>=(int) const |{cpp} equivalent of operator @ >
Elemer Lelik's avatar
Elemer Lelik committed
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
(rotate right).
|UNIVERSAL_CHARSTRING operator>>=(const INTEGER&) const |
^.^|_Casting operator_
|operator const universal_char*() const |Returns a pointer to the array of characters. There is no terminator character at the end.
.2+^.^|_UTF-8 encoding and decoding_
|void encode_utf8(TTCN_Buffer& buf) const |Appends the UTF-8 representation of the string to the given buffer
|void decode_utf8(int n_octets, const unsigned char *octets_ptr) |
.4+^.^|_Other member functions_
|`int lengthof() const` |Returns the length measured in characters.
|`boolean is_bound() const ` |Returns whether the value is bound.
|`void log() const` |Puts the value into log. See below.
|`void clean_up()` |Deletes the value, setting it to unbound.

|==============================================================================================================================

The comparison and concatenation operators are also available as global functions for that case when the left operand is a single-octet string (`const char*`) or a single character (`const universal_char&`) and the right side is `UNIVERSAL_CHARSTRING` value. Using the value of an unbound `UNIVERSAL_CHARSTRING` variable for anything causes dynamic test case error.

The `UNIVERSAL_CHARSTRING` variable used with the `decode_utf8()` method must be newly constructed (unbound) or `clean_up()` must have been called, otherwise a memory leak will occur.

The logged printout of universal charstring values is compatible with the TTCN–3 notation for such strings. The format to be used depends on the contents of the string. Each character (quadruple) is classified whether it is directly printable or not. The string is fragmented based on this classification. Each fragment consists of either a single non-printable character or a maximal length contiguous sequence of printable characters. The fragments are logged one after another separated by an `&` character (concatenation operator). The printable fragments use the normal charstring notation; the non-printable characters are logged in the TTCN–3 quadruple notation. An empty universal charstring value is represented by a pair of quotation marks (like in case of empty charstring values).

An example printout in the log can be the following. The string consists of two fragments of printable characters and a non-printable quadruple, which stands for Hungarian letter "ű":
[source, subs="+quotes"]
"Character " & char(0, 0, 1, 113) & " is a letter of Hungarian alphabet"

Other operators (global functions):
[source]
----
boolean operator==(const universal_char& left_value,
                     const universal_char& right_value);                 // Equal
boolean operator==(const universal_char& uchar_value,
                     const UNIVERSAL_CHARSTRING& other_value);           // Equal
boolean operator==(const char* string_value,
                     const UNIVERSAL_CHARSTRING& other_value);           // Equal
boolean operator==(const universal_char& uchar_value,
                     const UNIVERSAL_CHARSTRING_ELEMENT& other_value);   // Equal
boolean operator==(const char* string_value,
                     const UNIVERSAL_CHARSTRING_ELEMENT& other_value);   // Equal
boolean operator!=(const universal_char& left_value,
                     const universal_char& right_value);             // Not equal
boolean operator!=(const universal_char& uchar_value,
                     const UNIVERSAL_CHARSTRING& other_value);       // Not equal
boolean operator!=(const char* string_value,
                     const UNIVERSAL_CHARSTRING& other_value);       // Not equal
boolean operator!=(const universal_char& uchar_value,
              const UNIVERSAL_CHARSTRING_ELEMENT& other_value);      // Not equal
boolean operator!=(const char* string_value,
              const UNIVERSAL_CHARSTRING_ELEMENT& other_value);      // Not equal
boolean operator<(const universal_char& left_value,
         const universal_char& right_value& other_value); // Character comparison
UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
             const UNIVERSAL_CHARSTRING& other_value);           // Concatenation
UNIVERSAL_CHARSTRING operator+(const char* string_value,
             const UNIVERSAL_CHARSTRING& other_value);           // Concatenation
UNIVERSAL_CHARSTRING operator+(const universal_char& uchar_value,
             const UNIVERSAL_CHARSTRING_ELEMENT& other_value);   // Concatenation
UNIVERSAL_CHARSTRING operator+(const char* string_value,
             const UNIVERSAL_CHARSTRING_ELEMENT& other_value);   // Concatenation
----

==== `Universal charstring` element

942
The {cpp} class `UNIVERSAL_CHARSTRING_ELEMENT` is the equivalent of the TTCN-3 `universal charstring`’s element type (the result of indexing a `universal charstring` value). The class does not store the actual character, only a reference to the original `UNIVERSAL_CHARSTRING` object, an index value and a bound flag.
Elemer Lelik's avatar
Elemer Lelik committed
943

balaskoa's avatar
Typo    
balaskoa committed
944
NOTE: changing the value of the `UNIVERSAL_CHARSTRING_ELEMENT` (through the assignment operator) changes the referenced character in the original `universal charstring` object.
Elemer Lelik's avatar
Elemer Lelik committed
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031

The class `UNIVERSAL_CHARSTRING_ELEMENT` has the following public member functions:

.Public member functions of the class `UNIVERSAL_CHARSTRING_ELEMENT`

[width="100%",cols=",,",options="",]
|=======================================================================================================================================================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
^.^|_Constructor_
|`UNIVERSAL_CHARSTRING_ELEMENT(boolean par_bound_flag`, `UNIVERSAL_CHARSTRING& par_str_val, int par_uchar_pos)` |Initializes the object with an unbound value or a reference to a character in an existring UNIVERSAL_CHARSTRING object.
.6+^.^|_Assignment operators_
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const universal_char&)` |Sets the referenced character to the given universal character.
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const char*)` |
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const CHARSTRING&)` |
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const CHARSTRING_ELEMENT&)` |
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const UNIVERSAL_CHARSTRING&)` |
|`UNIVERSAL_CHARSTRING_ELEMENT& operator=(const UNIVERSAL_CHARSTRING_ELEMENT&)` |
.12+^.^|_Comparison operators_
|boolean operator==(const universal_char&) const |Comparison with a universal character, a null-terminated string, a charstring, a universal charstring, a charstring element or a universal charstring element (when comparing element types, the value of the referenced characters is compared, not the references and indexes).
|boolean operator==(const char*) const |
|boolean operator==(const CHARSTRING&) const |
|boolean operator==(const CHARSTRING_ELEMENT&) const  |
|boolean operator==(const UNIVERSAL_CHARSTRING&) const |
|boolean operator==(const UNIVERSAL_CHARSTRING_ELEMENT&) const |
|boolean operator!=(const universal_char&) const |
|boolean operator!=(const char*) const |
|boolean operator!=(const CHARSTRING&) const |
|boolean operator!=(const CHARSTRING_ELEMENT&) const  |
|boolean operator!=(const UNIVERSAL_CHARSTRING&) const |
|boolean operator!=(const UNIVERSAL_CHARSTRING_ELEMENT&) const |
.6+^.^|_Concatenation operator_
|CHARSTRING operator+(const universal_char&) const |Concatenates this object with a universal character, a null-terminated string, a charstring, a charstring element, a universal charstring or a universal charstring element.
|CHARSTRING operator+(const char*) const |
|CHARSTRING operator+(const CHARSTRING&) const |
|CHARSTRING operator+(const CHARSTRING_ELEMENT&) const |
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING&) const |
|UNIVERSAL_CHARSTRING operator+(const UNIVERSAL_CHARSTRING_ELEMENT&) const  |
.3+^.^|_Other member functions_
|`const universal_char& get_char() const` |Returns the referenced character.
|`void log() const` |Puts the value into log. Example: “a” or char(0, 0, 1, 113).
|`boolean is_bound() const` |Returns whether the value is bound.
|=======================================================================================================================================================================================================================================================================================================

Using the value of an unbound `UNIVERSAL_CHARSTRING_ELEMENT` variable for anything will cause dynamic test case error.

=== Object Identifier Type

The object identifier type of TTCN–3 (`objid`) is implemented in class OBJID. In the run-time environment the components of object identifier values are represented in NumberForm, that is, in integer values. The values of components are stored in an array with a given length. The type of the components is specified with a `typedef`, `objid_element`. Class `OBJID` has the following member functions.

.Public member functions of the class `OBJID`

[width="100%",cols=",,",options="header",]
|=====================================================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`OBJID()` |Initializes to unbound value.
|`OBJID(int n_components, const objid_element *components_ptr)` |Initializes the number of components to n components and copies all components from an array of integers starting at components_ptr.
|`OBJID(int n_components, ...)` |Initializes the number of components to n_components. The components themselves shall be given as additional integer arguments after each other, starting with the first one.
|OBJID(const OBJID&) |Copy constructor.
^.^|_Destructor_
|`˜OBJID()` |
^.^|_Assignment operator_
|`OBJID& operator=(const OBJID&)` |Assigns the given value and sets the bound flag.
.2+^.^|_Comparison operators_
|boolean operator==(const OBJID&) const |Returns TRUE if the two values are equal and FALSE otherwise.
|boolean operator!=(const OBJID&) const |
.2+^.^|_Indexing operators_
|objid_element& operator[](int i)  |Returns a reference to the _i th_ component.
|const objid_element & operator[](int i) const |Returns a read-only reference to the i th component.
^.^|_Casting operator_
|operator const objid_element *() const  |Returns a pointer to the read-only array of components.
|_Other member functions_
|`int lengthof() const` |Returns the number of components.
|`void log() const` |Puts the value into log in NumberForm. Like this: “objid 0 4 0 ”.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.

|=====================================================================================

NOTE: The constructor with variable number of arguments is useful in situations when the number of components is constant and known at compile time.

Using the value of an unbound `OBJID` variable for anything will cause dynamic test case error.

=== Component References

TTCN–3 variables the types of which are defined as component types are used for storing component references to PTCs. The internal representation of component references are test tool dependent, our test executor handles them as small integer numbers.

1032
All TTCN–3 component types are mapped to the same {cpp} class, which is called COMPONENT, using `typedef` aliases. We also use an ancillary C type called `component`, which is defined as an alias for `int`:
Elemer Lelik's avatar
Elemer Lelik committed
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
[source, subs="+quotes"]
typedef int component;

There are some predefined constants of component references in TTCN–3. These are defined as C preprocessor macros in the following way:

.Predefined component references

[cols=",,",options="header",]
|===================================================
|TTCN–3 constant |Preprocessor symbol |Numeric value
|null |NULL |COMPREF 0
|mtc |MTC |COMPREF 1
|system |SYSTEM |COMPREF 2
|===================================================

The class `COMPONENT` has the following public member functions:

.Public member functions of the class `COMPONENT`

[width="100%",cols=",,",options="",]
|===========================================================================================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`COMPONENT()` |Initializes to unbound value.
|`COMPONENT(component)` |Initializes to a given value.
|`COMPONENT(const COMPONENT&)` |Copy constructor.
^.^|_Destructor_
|`COMPONENT()`|
.2+^.^|_Assignment_ _operators_
|`COMPONENT& operator=(component)`|Assigns the given value
|`COMPONENT& operator=(const COMPONENT&)`|and sets the bound flag.
.4+^.^|_Comparison operators_
|boolean operator==(component) const  |Returns TRUE if equals
|boolean operator==(const COMPONENT&) const |and FALSE otherwise.
|boolean operator!=(component) const |
|boolean operator!=(const COMPONENT&) const |
^.^|_Casting operator_
|operator component() const |Returns the value.
.3+^.^|Other member functions
|`void log() const` |Puts the value into log in decimal form or in symbolic format for special constants. Like 3 or mtc.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.

|===========================================================================================================================

Component references are managed by MC. All new test components are given a unique reference that was never used in the test campaign before (not even in a previous test case). The new numbers are increasing monotonously. The reference of the firstly created component is 3; the next one will be 4, and so on.

Using the value of an unbound component reference for anything will cause dynamic test case error.

Other operators (global functions):
[source]
----
boolean operator==(component component_value,
                     const COMPONENT& other_value); // Equal
boolean operator!=(component component_value,
                     const COMPONENT& other_value); // Not equal
----
[[empty-types]]
=== Empty Types

1093
Empty `record` and `set` types are not real built-in types in TTCN–3, but the {cpp} realization of these types also differs from regular records or sets. The empty types are almost identical to each other, only their names are different. That is why we treat them as predefined types.
Elemer Lelik's avatar
Elemer Lelik committed
1094

1095
Each empty type is defined in a {cpp} class, which is generated by the compiler. Using separate classes enables us to differentiate among them in {cpp} type polymorphism. For example, several empty types can be defined as incoming or outgoing types on the same TTCN–3 port type.
Elemer Lelik's avatar
Elemer Lelik committed
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106

Let us consider the following TTCN–3 type definition as an example:
[source, subs="+quotes"]
type record Dummy {};

The generated class will rely on an enumerated C type null_type, which is defined as follows:
[source, subs="+quotes"]
enum null type {NULL VALUE };

The only possible value stands for the TTCN–3 empty record or array value (that is for "{}"), which is the only possible value of TTCN–3 type `Dummy`. Note that this type and value is also used in the definition of `record` of and `set of` type construct.

1107
The generated {cpp} class `Dummy` will have the following member functions:
Elemer Lelik's avatar
Elemer Lelik committed
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145

.Public member functions of the class `Dummy`

[width="100%",cols=",,",options="header",]
|================================================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`Dummy()` |Initializes to unbound value.
|`Dummy(null type)` |Initializes to the only possible value.
|`Dummy(const Dummy&)` |Copy constructor.
^.^|_Destructor_
|`˜Dummy()` |
.2+^.^|_Assignment operators_
|`Dummy& operator=(null type)` |Assigns the only possible value and sets the bound flag.
|`Dummy& operator=(const Dummy&)` |
.4+^.^|_Comparison operators_
|boolean operator==(Dummy) const  |Returns TRUE if both arguments are bound.
|boolean operator==(const Dummy&) const |
|boolean operator!=(address) const | Returns FALSE if both arguments are bound.
|boolean operator!=(const Dummy&) const |
.3+^.^|_Other member functions_
|`void log() const` |Puts the value, that is, {}, into log.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.

|================================================================================

Setting the only possible value is important, because using the value of an unbound variable for anything will cause dynamic test case error.

Other operators (global functions):
[source]
----
boolean operator==(null_type null_value, const Dummy& other_value);// Equal
boolean operator!=(null_type null_value, const Dummy& other_value);// Not equal
----

== Compound Data Types

1146
The user-defined compound data types are implemented in {cpp} classes. These classes are generated by the compiler according to type definitions. In contrast with the basic types, these classes can be found in the generated code.
Elemer Lelik's avatar
Elemer Lelik committed
1147
1148
1149

=== Record and Set Type Constructs

1150
The TTCN–3 type constructs `record` and `set` are mapped in an identical way to {cpp}. There will be a {cpp} class for each record type in the generated code. This class builds up the record from its fields.footnote:[This section deals with the record and set types that have at least one field. See <<empty-types, Empty Types>> for the {cpp} mapping of empty record and set types.] The fields can be either basic or compound types.
Elemer Lelik's avatar
Elemer Lelik committed
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201

Let us consider the following example type definition. The types `t1` and `t2` can be arbitrary.
[source]
----
type record t3 {
  t1 f1,
  t2 f2
}
----

The generated class `t3` will have the following public member functions:

.Public member functions of the class `t3`

[width="100%",cols=",,",options="",]
|=====================================================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`t3()` |Initializes all fields to unbound value.
|`t3(const t1& par_f1, const t2& par_f2)` |Initializes from given field values. The number of arguments equals to the number of fields.
|`t3(const t3&)` |Copy constructor.
^.^|_Destructor_
|`˜t3()` |
^.^|_Assignment operator_
|`t3& operator=(const t3&)`  |Assigns the given value and setsthe bound flag for each field.
.2+^.^|_Comparison operators_
|boolean operator==(const t3&) const |Returns TRUE if all fields are equal and FALSE otherwise.
|boolean operator!=(const t3&) const |
.2+^.^|_Field access functions_
|t1& f1();                     t2& f2(); |Gives access to the first/second field.
|const t1& f1() const; const t2& f2() const; |The same, but it gives read-only access.
.4+^.^|_Other member functions_
|`int size_of() const` |Returns the size (number of fields).
|`void log() const` |Puts the value into log. Like { f1 := 5, f2 := ”abc”}.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|=====================================================================================

The record value is unbound if one or more fields of it are unbound. Using the value of an unbound variable for anything (even for comparison) will cause dynamic test case error.

==== Optional Fields in Records and Sets

TTCN–3 permits optional fields in record and set type definitions. An optional field does not have to be always present, it can be omitted. But the omission must be explicitly denoted. Let us change our last example to this.
[source]
----
type record t3 {
  t1 f1,
  t2 f2 optional
}
----

1202
The optional fields are implemented using a {cpp} template class called `OPTIONAL` that creates an optional value from any type. In the definition of the generated class `t3` the type `t2` will be replaced by `OPTIONAL<t2>` everywhere and anything else will not be changed.
Elemer Lelik's avatar
Elemer Lelik committed
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255

The instantiated template class `OPTIONAL<t2>` will have the following member functions:

.Table Public member functions of the class `OPTIONAL<t2>`

[width="100%",cols=",,",options="",]
|================================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
.8+^.^|_Constructors_
|`OPTIONAL()` |Initializes to unbound value.
|`OPTIONAL(template_sel init_val)` |Initializes to omit value, if the argument is OMIT VALUE.
|`OPTIONAL(const t2& init_val)`  |Initializes to given value.
|`OPTIONAL(const OPTIONAL& init_val)`  |Copy constructor.
|`template <typename T_tmp> `|Initializes to given value of different (compatible) type.
|`OPTIONAL(const OPTIONAL<T_tmp>&)` |
|`template <typename T_tmp>` |Initializes to given optional value of different (compatible) type.
|`OPTIONAL(const T_tmp&)` |
^.^|_Destructor_
|`˜OPTIONAL()` |
.6+^.^|_Assignment operators_
|`OPTIONAL& operator=(template_sel)` |Assigns omit value, if the right value is OMIT VALUE.
|`OPTIONAL& operator=(const OPTIONAL&)` |Assigns the given optional value.
|`template <typename T_tmp>`|Assigns the given optional value of different (compatible) type.
|`OPTIONAL& operator=(const OPTIONAL<T_tmp>&)`|
|`template <typename T_tmp>` |Assigns the given value of different (compatible) type.
|`OPTIONAL& operator=(const T_tmp&)` |
.7+^.^|_Comparison operators_
|boolean operator==(template_sel) const |Returns TRUE if the value is omit and the right side is OMIT VALUE or FALSE otherwise.
|boolean operator==(const OPTIONAL&) const |Returns TRUE if the two values are equal or FALSE otherwise.
|template <typename T_tmp> |Returns TRUE if the two values of different (compatible) types are equal or FALSE otherwise.
|boolean operator!=(template_sel) const  |
|boolean operator!=(const OPTIONAL&) const |
|template <typename T_tmp> |
|boolean operator!=(const OPTIONAL<T_tmp>&) const |
.2+^.^|_Casting operators_
|operator t2&() |Gives read-write access to the value. If the value was not previously present, sets the bound flag true and the value will be initialized to unbound.
|operator const t2&() const |Gives read-only access to the value. If the value is not present, causes a dynamic test case error.
.2+^.^|_Function call operators_
|t2& operator()() |Gives read-write access to the value. If the value was not previously present, sets the bound flag true and the value will be initialized to unbound.
|const t2& operator()() const |Gives read-only access to the value. If the value is not present, causes a dynamic test case error.
.4+^.^|_Other member functions_
|`boolean ispresent() const` |Returns TRUE if the value is present, FALSE if the value is omit or causes dynamic test case error if the value is unbound.
|`void log() const` |Puts the optional value into log. Either ”omit” or the value of t2.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|================================================================================================================================================================================

In some member functions of the template class `OPTIONAL` the enumerated C type `template_sel` is used. It has many possible values, but in the optional class only `OMIT_VALUE` can be used, which stands for the TTCN–3 omit. Usage of other predefined values of `template_sel` will cause dynamic test case error.

Using the value of an unbound optional field for anything will also cause dynamic test case error.

=== Union Type Construct

1256
The TTCN–3 type construct union is implemented in a {cpp} class for each union type in the generated code. This class may contain any, but exactly one of its fields. The fields can be either basic or compound types or even identical types.
Elemer Lelik's avatar
Elemer Lelik committed
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305

Let us consider the following example type definition. The types `t1` and `t2` can be arbitrary.
[source]
----
type union t3 {
  t1 f1,
  t2 f2
}
----

An ancillary enumerated type is created in the generated class `t3`, which represents the selection:
[source, subs="+quotes"]
enum union_selection_type { UNBOUND_VALUE = 0, ALT_f1 = 1, ALT_f2 = 2 };

The type `t3::union_selection_type` is used to distinguish the fields of the union. The predefined constant values are generated as `t3::ALT_`<field name>.

The generated class `t3` will have the following public member functions:

.Public member functions of the class `t3`

[width="100%",cols=",,",options="header",]
|=========================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
.2+^.^|_Constructors_
|`t3()` |Initializes to unbound value.
|`t3(const t3&)` |Copy constructor.
^.^|_Destructor_
|`˜t3()` |
^.^|_Assignment operator_
|`t3& operator=(const t3&)` |Assigns the given value.
.2+^.^|_Comparison operators_
|boolean operator==(const t3&) const |Returns TRUE if the selections and field values are equal and FALSE otherwise.
|boolean operator!=(const t3&) const |
.4+^.^|_Field access functions_
|const t1& f1() const  |Selects and gives access to the first field. If other field was previously selected, its value will be destroyed.
|t1& f1() |Gives read-only access to the first field. If other field is selected, this function will cause a dynamic test case error. So use get_selection() first.
|t2& f2() |
|const t2& f2() const |
.4+^.^|_Other member functions_
|`union_selection_type get_selection() const` |Returns the current selection. It will return t3::UNBOUND VALUE if the value is unbound, t3::ALT_f1 if the first field was selected, and so on.
|`void log() const` |Puts the value into log. Example: { f1 := 5 } or { f2 := "abc" }.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|=========================================================================================================================================================================

Using the value of an unbound `union` variable for anything will cause dynamic test case error.

==== The anytype

1306
The TTCN-3 anytype is implemented as a {cpp} class named anytype. The class is generated only if an actual anytype access is present in the module. It has the same interface as any other {cpp} class generated for a union, with a few differences:
Elemer Lelik's avatar
Elemer Lelik committed
1307
1308
1309
1310
1311

If a field is a built-in type or the address type, the name used in `union_selection_type` is the name of the runtime class implementing the type (usually the name of the type in all uppercase).

If a field is a user-defined type, the mapping rules in <<mapping-of-names-and-identifiers, Mapping of Names and Identifiers>> above apply.

1312
The names of field accessor functions are prefixed with AT_. This is necessary, because otherwise the accessor function looks like a constructor to {cpp}.
Elemer Lelik's avatar
Elemer Lelik committed
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342

For example, for the following module
[source]
----
module anyuser {
  type record myrec {}

  control {
    var anytype v_at;
  }
}
with {
  extension “anytype integer, myrec, charstring”
}
----

The generated class name will be "anytype". The union_selection_type enumerated type will be:
[source, subs="+quotes"]
enum union_selection_type { UNBOUND_VALUE = 0, ALT_INTEGER = 1, ALT_myrec = 2, ALT_CHARSTRING = 3 };

The field accessor methods will be:
[source]
----
INTEGER&    AT_INTEGER();
myrec&      AT_myrec();
CHARSTRING& AT_CHARSTRING();
----

=== Record of Type Construct

1343
The TTCN–3 type construct `record` of makes a variable length sequence from one given type. This construct is implemented as a {cpp} class.
Elemer Lelik's avatar
Elemer Lelik committed
1344
1345
1346
1347
1348

Let us consider the following example type definition. The type t1 can be arbitrary.
[source, subs=+quotes]
type record of t1 t2;

1349
This definition will be translated to a {cpp} class that will be called t2.
Elemer Lelik's avatar
Elemer Lelik committed
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379

There is an `enum` type called `null_type` defined in the Base Library that has only one possible value. NULL_VALUE stands for the empty `"record of"` value, that is, for {}.

Class `t2` will have the following public member functions:

.Public member functions of the class `t2`

[width="100%",cols=",,",options="",]
|==================================================================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
.3+^.^|_Constructors_
|`t2()` |Initializes to unbound value.
|`t2(null type)` |Initializes to the empty value.
|`t2(const t2&)` |Copy constructor.
^.^|_Destructor_
|`˜t2()` |
.2+^.^|_Assignment operator_
|`t2& operator=(null type)` |Assigns the empty value.
|`t2& operator=(const t2&)` |Assigns the given value.
.4+^.^|_Comparison operators_
|boolean operator==(null type) const  |Returns TRUE if the two values are equal and FALSE otherwise.
|boolean operator==(const t2&) const |
|boolean operator!=(null type) const |
|boolean operator!=(const t2&) const |
.4+^.^|_Index operators_
|t1& operator[](int) |Gives access to the given element. Indexing begins from zero. If this element of the variable was never used before, new (unbound) elements will be allocated up to (and including) this index.
|t1& opetator[](const INTEGER&) |
|const t1& operator[](int) const |Gives read-only access to the given element. Index overflow causes dynamic test case error.
|const t1& opetator[](const INTEGER&) const |
.4+^.^|_Rotating operators_
1380
|t2 operator<<=(int) |{cpp} equivalent of operator <@. (rotate left)
Elemer Lelik's avatar
Elemer Lelik committed
1381
|t2 operator<<=(const INTEGER&) |
1382
|t2 operator>>=(int) |{cpp} equivalent of operator @>. (rotate right)
Elemer Lelik's avatar
Elemer Lelik committed
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
|t2 operator>>=(const INTEGER&) |
^.^|_Concatenation operator_
|t2 operator+(const t2&) const |Concatenates two arrays.
.7+^.^|_Other member functions_
|`int size_of() const` |Returns the number of elements, that is, the largest used index plus one and zero for the empty value.
|`void set_size(int new_size)` |Sets the number of elements to the given value. If the value has fewer elements new (unbound) elements are allocated at the end. The excess elements at the end are erased if the value has more elements than necessary.
|`t2 substr(int index, int returncount) const` |Returns the section of the array specified by the given start index and length.
|`t2 replace(int index, int len, const t2& repl) const` |Returns a copy of the array, where the section indicated by the given start index and length is replaced by the given array.
|`void log() const` |Puts the value into log. Like {1, 2, 3 }.
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|==================================================================================================================================================================================================================

A `record of` value is unbound if no value has been assigned to it or it has at least one unbound element. Using the value of an unbound `record of` variable for anything will cause dynamic test case error.

Starting with the largest index improves performance when filling a `record of value`.

Other operators (global functions):
[source]
----
boolean operator==(null_type null_value, const t2& other_value); // Equal
boolean operator!=(null_type null_value, const t2& other_value); // Not equal
----

==== Pre-generated `record of` and `set of` constructs

1409
The {cpp} classes for the `record of` and `set of` constructs of most predefined TTCN-3 types are pre-generated and part of the TITAN runtime. Only a type alias ({cpp} `typedef`) is generated for instances of these types declared in TTCN-3 and ASN.1 modules. There is a class with regular memory allocation and one with optimized memory allocation pre-generated for each type. These classes are located in the `PreGenRecordOf` namespace.
Elemer Lelik's avatar
Elemer Lelik committed
1410
1411
1412
1413
1414

.Pre-generated classes for `record of`/`set of` predefined types

[width="100%",cols="50%,50%",options="header",]
|====================================================================================================================================
1415
|{cpp} class name |Equivalent type in TTCN-3
Elemer Lelik's avatar
Elemer Lelik committed
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
|`PREGEN\__RECORD__OF__BOOLEAN` |`record of boolean`
|`PREGEN\__RECORD__OF__INTEGER` |`record of integer`
|`PREGEN\__RECORD__OF__FLOAT` |`record of float`
|`PREGEN\__RECORD__OF__BITSTRING` |`record of bitstring`
|`PREGEN\__RECORD__OF__HEXSTRING` |`record of hexstring`
|`PREGEN\__RECORD__OF__OCTETSTRING` |`record of octetstring`
|`PREGEN\__RECORD__OF__CHARSTRING` |`record of charstring`
|`PREGEN\__RECORD__OF\__UNIVERSAL__CHARSTRING` |`record of universal charstring`
|`PREGEN\__RECORD__OF\__BOOLEAN__OPTIMIZED` |`record of boolean with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__INTEGER__OPTIMIZED` |`record of integer with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__FLOAT__OPTIMIZED` |`record of float with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__BITSTRING__OPTIMIZED` |`record of bitstring with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__HEXSTRING__OPTIMIZED` |`record of hexstring with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__OCTETSTRING__OPTIMIZED` |`record of octetstring with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__CHARSTRING__OPTIMIZED` |`record of charstring with { extension "optimize:memalloc" }`
|`PREGEN\__RECORD__OF\__UNIVERSAL__CHARSTRING__OPTIMIZED` |`record of universal charstring with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF__BOOLEAN` |`set of boolean`
|`PREGEN\__SET__OF__INTEGER` |`set of integer`
|`PREGEN\__SET__OF__FLOAT` |`set of float`
|`PREGEN\__SET__OF__BITSTRING` |`set of bitstring`
|`PREGEN\__SET__OF__HEXSTRING` |`set of hexstring`
|`PREGEN\__SET__OF__OCTETSTRING` |`set of octetstring`
|`PREGEN\__SET__OF__CHARSTRING` |`set of charstring`
|`PREGEN\__SET__OF\__UNIVERSAL__CHARSTRING` |`set of universal charstring`
|`PREGEN\__SET__OF\__BOOLEAN__OPTIMIZED` |`set of boolean with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__INTEGER__OPTIMIZED` |`set of integer with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__FLOAT__OPTIMIZED` |`set of float with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__BITSTRING__OPTIMIZED` |`set of bitstring with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__HEXSTRING__OPTIMIZED` |`set of hexstring with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__OCTETSTRING__OPTIMIZED` |`set of octetstring with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__CHARSTRING__OPTIMIZED` |`set of charstring with { extension "optimize:memalloc" }`
|`PREGEN\__SET__OF\__UNIVERSAL__CHARSTRING__OPTIMIZED` |`set OF\ universal charstring with { extension "optimize:memalloc" }`
|====================================================================================================================================

=== `Set of` Type Construct

The `set of` construct of TTCN–3 is implemented similarly to `record of`. The external interface of this class is exactly the same as in case of `record of`. For more details please see the previous section.

In the internal implementation only the equality operator differs. Unlike in `record of`, it considers the unordered property of the `set of` type construct, that is, it returns `TRUE` if it is able to find exactly one pair for each element.

1456
The index is a unique identifier for a `set of` element because the {cpp} class does not reorder the elements when a new element is added or an element is modified. The copy constructor also keeps the original order of elements.
Elemer Lelik's avatar
Elemer Lelik committed
1457
1458
1459

=== Enumerated Types

1460
The TTCN–3 `enumerated` type construct is implemented as a {cpp} class with an embedded enum type.
Elemer Lelik's avatar
Elemer Lelik committed
1461
1462
1463
[source, subs="+quotes"]
type enumerated Day { Monday (1), Tuesday, Wednesday (3) };

1464
The example above will result in the following, very similar C `enum` type definition which is embedded in the {cpp} class `Day`:
Elemer Lelik's avatar
Elemer Lelik committed
1465
1466
1467
1468
1469
1470
1471
[source, subs="+quotes"]

enum enum_type { Monday = 1, Tuesday = 0, Wednesday = 3,
       UNKNOWN_VALUE = 2, UNBOUND_VALUE = 4 };

The automatic assignment of numeric values is done according to the standard. Note that there are two extra enumerated values in C, which stand for the unknown and unbound values. They are used in the conversion functions described below. The compiler assigns the smallest two non-negative integer numbers that are not used by the user-defined enumerated values to the unknown and unbound values.

1472
When using the C `enum` type and its values from user code the names must be prefixed with the {cpp} class name. The `enum` type in the above example can be referenced with `Day::enum_type`, its values can be accessed as `Day::Monday, Day::Tuesday`, and so on.
Elemer Lelik's avatar
Elemer Lelik committed
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527

The class `Day` will have the following public member functions:

.Public member functions of the class `Day`

[width="100%",cols=",,",options="",]
|=========================================================================================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Constructors_
|`Day()` |Initializes to unbound value.
|`Day(int)` |Converts the given numeric value to Day::enum_type and initializes to it.
Only valid values are accepted.
|`Day(enum_type)` |Initializes to a given value.
|`Day(const Day&)`  |Copy constructor.
^.^|_Destructor_
|`˜Day()` |
.3+^.^|_Assignment operator_
|`Day& operator=(int)` |Converts the given numeric value to Day::enum_type and assigns it. Only valid values are accepted.
|`Day& operator=(enum_type)` |Assigns the given value.
|`Day& operator=(const Day&)` |
.12+^.^|_Comparison operators_
|boolean operator==(enum_type) const |Returns TRUE if the two values are equal and FALSE otherwise.
|boolean operator==(const Day&) const |
|boolean operator!=(enum_type) const |
|boolean operator!=(const Day&) const |
|boolean operator<(enum_type) const |
|boolean operator<(const Day&) const |
|boolean operator<=(enum_type) const |
|boolean operator<=(const Day&) const |
|boolean operator>(enum_type) const |
|boolean operator>(const Day&) const |
|boolean operator>=(enum_type) const |
|boolean operator>=(const Day&) const |
^.^|_Casting operator_
|operator enum_type() const |Returns the enum_value.
.5+^.^|_Static conversion functions_
|static const char *enum_to_str(enum_type) |See below.
|static enum_type str_to_enum(const char *)  |
|static boolean is_valid_enum(int) |
|static int enum2int(enum_type); |
|static int enum2int(const Day&); |
.3+^.^|_Non-static conversion functions_
|int as_int() const; |See below
|void from_int(int); |
|void int2enum(int); |
.3+^.^|_Other member functions_
|`void log() const` |Puts the value into log. Like this: Monday
|`boolean is_bound() const` |Returns whether the value is bound.
|`void clean_up()` |Deletes the value, setting it to unbound.
|=========================================================================================================================

The static member function `Day::enum_to_str` converts the given parameter of type `Day::enum_type` to a NULL terminated C character string. It returns the string "<unknown>", if the input is not a valid value of the TTCN–3 enumerated type. The returned string is read-only, it must not be modified.

The function `Day::str_to_enum` does the conversion in the reverse direction. It converts the symbolic enumerated identifier represented by a C character string back to the `Day::enum_type` equivalent. It returns the value `Day::UNKNOWN_VALUE` if the input string is not the equivalent of any of the possible values in the enumerated type. The behavior of this function is undefined if the input parameter does not point to an addressable memory area.

1528
In the above two functions the strings are treated case sensitive and they shall not contain any whitespace or other characters that are not part of the enumerated value. In case of ASN.1 `ENUMERATED` types the strings used by `enum_to_str`, `str_to_enum` and log represent the TTCN–3 view of the enumerated value, that is, the hyphenation characters are mapped to a single underscore character. For example, if an ASN.1 enumerated type has a value with name `my-enum-value` and numeric value 2, the function `enum_to_str` will return the string `"my_enum_value"` if the input parameter equals to 2. Of course, its {cpp} equivalent will be `my_enum_value` with numeric value 2.
Elemer Lelik's avatar
Elemer Lelik committed
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550

Static member function `Day::is_valid_enum` returns the Boolean value `TRUE` if there is a defined enumerated value having numeric value equal to the `int` parameter and `FALSE` otherwise.

The static member function `Day::enum_to_int` converts the given parameter of type Day or `Day::enum_type` to its numeric value. The member function `as_int` does the same thing for the enumerated instance.

The member function `int_to_enum` initializes the enumerated instance with the enumerated value having numeric value equal to the given `int` parameter. A dynamic test case error is displayed if there is no such enumerated value. The member function `from_int` does the same thing.

If a value of type `int` is passed to the constructor or assignment operator the value is accepted only if it is a numerical representation of a valid enumerated value, that is, the function `is_valid_enum` returns `TRUE`. A dynamic test case error occurs otherwise.

To avoid run-time errors at the decoding of invalid messages the Test Port writer should use the constructor or assignment operator in this way:
[source]
----
Day myDayVar;
int myIntVar = buffer[position];
if (Day::is_valid_enum(myIntVar)) myDayVar = myIntVar;
else myDayVar = Day::UNKNOWN_VALUE;
----

Using the value of an unbound enumerated variable for anything will cause dynamic test case error.

=== The `address` Type

1551
The special TTCN–3 data type `address` is represented in {cpp} as if it was a regular data type. The name of the equivalent {cpp} class is `ADDRESS`. If it is an alias to another (either built-in or user-defined) type then a {cpp} `typedef` is used.
Elemer Lelik's avatar
Elemer Lelik committed
1552
1553
1554

== Predefined Functions

1555
Annex C of link:https://www.etsi.org/deliver/etsi_es/201800_201899/20187301/04.05.01_60/es_20187301v040501p.pdf[Methods for Testing and Specification (MTS); The Testing and Test Control Notation version 3. Part 1: Core Language European Telecommunications Standards] and Annex B of link:https://pdfs.semanticscholar.org/33b5/877c85f7fd4f35c7f58c39121358c3652966.pdf[Methods for Testing and Specification (MTS); The Testing and Test Control Notation version 3. Part 7: Using ASN.1 with TTCN–3 European Telecommunications] define a couple of predefined functions. Most of them perform conversion between the built-in types of TTCN–3. In our test executor these functions are implemented in the Base Library in {cpp} language. They are available not only in TTCN–3 , but they can be called directly from Test Ports as well.
Elemer Lelik's avatar
Elemer Lelik committed
1556
1557
1558

The prototypes for these functions can be found in `*$TTCN3_DIR/include/Addfunc.hh*`, but for easier navigation we list them also in the present document.

1559
The majority of these functions have more than one polymorphic version: when appropriate, one of them takes literal (built-in) {cpp} types as arguments instead of the objects of equivalent {cpp} classes. For instance, if the incoming argument is stored in an `int` variable in your {cpp} code, you should not construct a temporary object of class `INTEGER` because passing an `int` is faster and produces smaller binary code. Similarly, the returned type is also literal when it is possible.
Elemer Lelik's avatar
Elemer Lelik committed
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641

=== `Integer` to character

[source]
----
extern CHARSTRING int2char(int value);
extern CHARSTRING int2char(const INTEGER& value);
----
=== Character to `integer`

[source]
----
extern int char2int(char value);
extern int char2int(const char *value);
extern int char2int(const CHARSTRING& value);
----
=== `Integer` to universal character

[source]
----
extern UNIVERSAL_CHARSTRING int2unichar(int value);
extern UNIVERSAL_CHARSTRING int2unichar(const INTEGER& value);
----
=== Universal character to `integer`

[source]
----
extern int unichar2int(const universal_char& value);
extern int unichar2int(const UNIVERSAL_CHARSTRING& value);
----
=== `Bitstring` to `integer`

[source]
----
extern INTEGER bit2int(const BITSTRING& value);
----
=== `Hexstring` to `integer`

[source]
----
extern INTEGER hex2int(const HEXSTRING& value);
----
=== `Octetstring` to `integer`

[source]
----
extern INTEGER oct2int(const OCTETSTRING& value);
----
=== `Charstring` to `integer`

[source]
----
extern INTEGER str2int(const char *value);
extern INTEGER str2int(const CHARSTRING& value);
----
=== `Integer` to `bitstring`

[source]
----
extern BITSTRING int2bit(const INTEGER& value, const INTEGER& length);
----
=== `Integer` to `hexstring`

[source]
----
extern HEXSTRING int2hex(const INTEGER& value, const INTEGER& length);
----
=== `Integer` to `octetstring`

[source]
----
extern OCTETSTRING int2oct(const INTEGER& value, const INTEGER& length);
----
=== `Integer` to `charstring`

[source]
----
extern CHARSTRING int2str(int value);
extern CHARSTRING int2str(const INTEGER& value);
----
=== Length of string Type

1642
This function is built into the equivalent {cpp} classes of all TTCN–3 string types:
Elemer Lelik's avatar
Elemer Lelik committed
1643
1644
1645
1646
1647
1648
[source]
----
int <any_string_type>::lengthof() const;
----
=== Number of elements in a structured type

1649
This function is built into the {cpp} template classes of `record of` and `set of` types:
Elemer Lelik's avatar
Elemer Lelik committed
1650
1651
1652
1653
1654
1655
1656
1657
[source]
----
int <any_record_of_or_set_of_type>::size_of() const;
----
This function is currently not implemented for `record` and `set` types.

=== The `IsPresent` Function

1658
This function is built into the wrapper {cpp} template class `OPTIONAL`:
Elemer Lelik's avatar
Elemer Lelik committed
1659
1660
1661
1662
1663
1664
[source]
----
boolean <any_optional_field>::ispresent() const;
----
=== The `IsChosen` Function

1665
These functions are built into the equivalent {cpp} classes of TTCN–3 union types:
Elemer Lelik's avatar
Elemer Lelik committed
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
[source]
----
boolean <union_type>::ischosen(
<union_type>::union_selection_type checked_selection) const;
----
=== The `regexp` Function

[source]
----
extern CHARSTRING regexp(const CHARSTRING& instr,
const CHARSTRING& expression, const INTEGER& groupno);
----
=== `Bitstring` to `charstring`

[source]
----
extern CHARSTRING bit2str(const BITSTRING& value);
----
=== `Hexstring` to `charstring`

[source]
----
extern CHARSTRING hex2str(const HEXSTRING& value);
----
=== `Octetstring` to character string

[source]
----
extern CHARSTRING oct2str(const OCTETSTRING& value);
----
=== Character string to `octetstring`

[source]
----
extern OCTETSTRING str2oct(const char *value);
extern OCTETSTRING str2oct(const CHARSTRING& value);
----
=== `Bitstring` to `hexstring`

[source]
----
extern HEXSTRING bit2hex(const BITSTRING& value);
----
=== `Hexstring` to `octetstring`

[source]
----
extern OCTETSTRING hex2oct(const HEXSTRING& value);
----
=== `Bitstring` to `octetstring`

[source]
----
extern OCTETSTRING bit2oct(const BITSTRING& value);
----
=== `Hexstring` to `bitstring`

[source]
----
extern BITSTRING hex2bit(const HEXSTRING& value);
----
=== `Octetstring` to `hexstring`

[source]
----
extern HEXSTRING oct2hex(const OCTETSTRING& value);
----
=== `Octetstring` to `bitstring`

[source]
----
extern BITSTRING oct2bit(const OCTETSTRING& value);
----
=== `Integer` to `float`

[source]
----
extern double int2float(int value);
extern double int2float(const INTEGER& value);
----
=== `Float` to `integer`

[source]
----
extern INTEGER float2int(double value);
extern INTEGER float2int(const FLOAT& value);
----
=== The Random Number Generator Function

The implementation is based on functions `srand48` and `drand48` of `libc`.
[source]
----
extern double rnd();
extern double rnd(double seed);
extern double rnd(const FLOAT& seed);
----
=== The Substring Function

Implemented for all string types.
[source]
----
extern BITSTRING substr(const BITSTRING& value, const INTEGER& index,
  const INTEGER& returncount);
extern HEXSTRING substr(const HEXSTRING& value, const INTEGER& index,
  const INTEGER& returncount);
extern OCTETSTRING substr(const OCTETSTRING& value, const INTEGER& index,
  const INTEGER& returncount);
extern CHARSTRING substr(const CHARSTRING& value, const INTEGER& index,
  const INTEGER& returncount);
extern UNIVERSAL_CHARSTRING substr(const UNIVERSAL_CHARSTRING& value,
  const INTEGER& index, const INTEGER& returncount);
----

=== Character string to `float`

[source]
----
extern double str2float(const char *value);
extern double str2float(const CHARSTRING& value);
----
=== The Replace Function

Implemented for all string types.
[source]
----
extern BITSTRING replace(const BITSTRING& value, const INTEGER& index,
  const INTEGER& len, const BITSTRING& repl);
extern HEXSTRING replace(const HEXSTRING& value, const INTEGER& index,
  const INTEGER& len, const HEXSTRING& repl);
extern OCTETSTRING replace(const OCTETSTRING& value, const INTEGER& index,
  const INTEGER& len, const OCTETSTRING& repl);
extern CHARSTRING replace(const CHARSTRING& value, const INTEGER& index,
  const INTEGER& len, const CHARSTRING& repl);
extern UNIVERSAL_CHARSTRING replace(const UNIVERSAL_CHARSTRING& value,
  const INTEGER& index, const INTEGER& len, const UNIVERSAL_CHARSTRING& repl);
----

[[octetstring-to-character-string-0]]
=== Octetstring to character string

[source]
----
extern CHARSTRING oct2char(const OCTETSTRING& value);
----
[[character-string-to-octetstring-0]]
=== Character string to octetstring

[source]
----
extern OCTETSTRING char2oct(const char *value);
extern OCTETSTRING char2oct(const CHARSTRING& value);
----
=== The `Decompose` Function

Not implemented yet.

[[additional-non-standard-functions]]
=== Additional Non-Standard Functions

[source]
----
extern BITSTRING str2bit(const char *value);
extern BITSTRING str2bit(const CHARSTRING& value);
extern HEXSTRING str2hex(const char *value);
extern HEXSTRING str2hex(const CHARSTRING& value);
extern CHARSTRING float2str(double value);
extern CHARSTRING float2str(const FLOAT& value);

template<typename TTCN_TYPE>
CHARSTRING ttcn_to_string(const TTCN_TYPE& ttcn_data)

template<typename TTCN_TYPE>
void string_to_ttcn(const CHARSTRING& ttcn_string, TTCN_TYPE& ttcn_value)

extern UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue);
extern UNIVERSAL_CHARSTRING oct2unichar(const OCTETSTRING& invalue,
  const CHARSTRING& string_encoding);

extern OCTETSTRING unichar2oct(const UNIVERSAL_CHARSTRING& invalue);
extern OCTETSTRING unichar2oct(const UNIVERSAL_CHARSTRING& invalue,
  const CHARSTRING& string_encoding);

extern CHARSTRING get_stringencoding(const OCTETSTRING& encoded__value);
extern OCTETSTRING remove_bom(const OCTETSTRING& encoded__value);

extern CHARSTRING encode_base64(const OCTETSTRING& msg, bool use_linebreaks);
extern CHARSTRING encode_base64(const OCTETSTRING& msg);
extern OCTETSTRING decode_base64(const CHARSTRING& b64);
----

See the section "Additional predefined functions" in the link:https://github.com/eclipse/titan.core/tree/master/usrguide/referenceguide[ Programmer"s Technical Reference] for more details.

[[using-the-signature-classes]]
== Using the Signature Classes

A Test Port has three outgoing and three incoming types of operation that require the usage of signatures. These are `call` (`getcall`), `reply` (`getreply`) and `raise` (`catch`). Because of this, there are three representation formats (classes generated by the compiler) of a signature the Test Port writer should be familiar with. This section describes these classes using an example.

Let us suppose the following signature definition:
[source]
----
signature MyProc(in integer inPar, out float outPar,
	inout bitstring inoutPar)
		return hexstring
		exception(charstring, integer, boolean);
----

The classes generated and needed to write a Test Port using this signature are `MyProc_call`, `MyProc_reply` and `MyProc_exception`. These represent the parameters, the return value and the exception type and value of the signature needed by a call, reply or raise.

For example, if a port uses the signature `MyProc` as an output remote procedure, the Test Port gets the outgoing parameters for a call operation towards the system in an instance of the class `MyProc_call`. In this case the classes `MyProc_reply` and `MyProc_exception` are used for placing an incoming reply or raise operation in the queue of the port (using the functions `incoming_reply` and `incoming_exception` of the port class).

=== The Representation of the Input Parameters

The class `MyProc_call` (using the above example) represents all incoming parameters of the signature `MyProc`. It temporary stores the parameters inPar and inoutPar.

The generated class `MyProc_call` will have the following public member functions:

.Public member functions of the class `MyProc_call`

[cols=",,",options="",]
|==============================================================
2+^.^|*Member functions* |*Notes*
.4+^.^|_Parameter access functions_
|INTEGER& inPar() |Gives access to parameter inPar.
|const INTEGER& inPar() const  |
|BITSTRING& inoutPar() |The same, but it gives read-only access.
|const BITSTRING& inoutPar() const  |
^.^|_Other member functions_
|`void log() const` |Puts the parameters into log.
|==============================================================

The parameters can be accessed via their access functions that have the same names as the parameters (name mapping also applies to these functions).

=== The Output Parameters and Return Value

The output parameters and return value (if defined) are represented by the class `MyProc_reply` that has the following public member functions:

.Public member functions of the class `MyProc_reply`

[cols=",,",options="",]
|=====================================================================
2+^.^|*Member functions* |*Notes*
.2+^.^|_Parameter access functions_
|FLOAT& outPar()const FLOAT& outPar() const |Gives access to parameter outPar.
|BITSTRING& inoutPar() const BITSTRING& inoutPar() const |The same, but it gives read-only access.
.2+^.^|_Access function for return value_
|HEXSTRING& return value() |Gives access to the return value.
|const HEXSTRING& return value() const |
^.^|_Other member functions_
|`void log() const` |Puts the parameters into log.
|=====================================================================

The parameters can be accessed by their access functions, and the return value can be accessed via the function `return_value()`.

=== Representation of Signature Exceptions

The class representing the exceptions of a signature (remote procedure) is similar to the representation of the union data type. Using the above example this class is called `MyProc_exception`. This class is generated only if the signature has at least one exception type.

.Public member functions of the class `MyProc_exception`

[width="100%",cols=",,",options="",]
|===================================================================================================================================================================================================================================
2+^.^|*Member functions* |*Notes*
.2+^.^|_Constructors_
|`MyProc_exception()` |Initializes to unbound value.
|`MyProc_exception(const MyProc_exception&)` |Copy constructor.
^.^|_Destructor_
|`˜MyProc_exception()` |
^.^|_Assignment_ _operator_
|`MyProc_exception& operator=(const MyProc_exception&)` |Assigns the given value.
.4+^.^|_Field access functions_
|CHARSTRING& CHARSTRING_field() |Selects and gives access to the CHARSTRING field. If other field was previously selected, its value will be destroyed.
|const CHARSTRING&CHARSTRING_field() cons |Gives read-only access to the CHARSTRING field. If other field is selected, this function will cause dynamic test case error. So use get selection() first.
|INTEGER& INTEGER_field() const INTEGER& INTEGER_field() const |
|BOOLEAN& BOOLEAN_field()const BOOLEAN& BOOLEAN_field() const  |
.2+^.^|_Other member functions_
|`MyProc_exception::exception_selection_type 	get_selection() const` |Returns the current selection. It will return MyProc exception::UNBOUND VALUE if the exception is unbound, MyProc exception::ALT CHARSTRING if a charstring value is present in the exception, and so on.
|`void log() const` |Puts the contents of the exception into the log.
|===================================================================================================================================================================================================================================

1945
1946
1947
1948
1949
If an exception type is a user-defined type the field name will be constructed from the {cpp} namespace name of the module
that the exception type resides in and the name of the {cpp} class that realizes the exception type.
The two identifiers are glued together using a single underscore character.
Please note that the namespace name is always present in the identifiers, 
even if the exception type is defined in the same module as the signature.
Elemer Lelik's avatar
Elemer Lelik committed
1950

1951
1952
1953
For example, if exception type `My_Record` is defined in module `My_Module`
the respective field access functions will be named as `My\__Module_My__Record_field` and 
the associated enum value will be `MyProc_exception::ALT_My\__Module_My__Record`.
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994

[[object-references]]
== Object references

All function parameters, return values and variables of class type must use the `OBJECT_REF` wrapper class, with the class type as its template parameter (e.g. `MyClass` in TTCN-3 translates to `OBJECT_REF<MyClass>` in {cpp}). This class contains a pointer to the class object itself, and handles its reference counting and deallocation.

Accessing members and methods through `OBJECT_REF` is done through the operator `->` (as if it were a pointer in {cpp}). Methods of `OBJECT_REF` are accessed through the operator `.` (see below).

.Public methods of the template class `OBJECT_REF<T>`, where `T` is a class type
[cols=",,",]
|==================================================
2+^.^|*Member functions* |*Notes*
.5+^.^|_Constructors_
|`OBJECT_REF()` |Initializes to `null` reference.
|`OBJECT_REF(null_type)` |Initializes to `null` reference.
|`OBJECT_REF(T*)` |Initializes to a new object, which needs to be allocated with the {cpp} operator `new`.
|`OBJECT_REF(const OBJECT_REF<T>&)` |Copy constructor.
|`template <typename T2>
  OBJECT_REF(OBJECT_REF<T2>&)` |Copy constructor for a reference of a different class type, referring to an object of type `T` or a subclass of `T`.
^.^|_Destructor_
|`~OBJECT_REF()` |
.3+^.^|_Assignment operators_
|`OBJECT_REF& operator=(null_type)` |Assigns the `null` reference.
|`OBJECT_REF& operator=(const OBJECT_REF<T>&)` |Assigns a reference of `T`.
|`template <typename T2>
  OBJECT_REF& operator=(OBJECT_REF<T2>&)` |Assigns a reference of a different class type, referring to an object of type `T` or a subclass of `T`. 
.4+^.^|_Comparison operators_
|`boolean operator==(null_type) const` | Returns TRUE if the reference is `null`.
|`boolean operator!=(null_type) const` | Returns FALSE if the reference is `null`.
|`boolean operator==(const OBJECT_REF<T>&) const` | Returns TRUE if both this and the parameter refer to the same object.
|`boolean operator!=(const OBJECT_REF<T>&) const` | Returns FALSE if both this and the parameter refer to the same object.
.3+^.^|_Access operators_
|`T* operator*()` |Returns a pointer to the actual object.
|`T* operator->()` |Accesses the object's members and methods.
|`const T* operator->() const` |Accesses the object's constant members and methods.
.4+^.^|_Other methods_
| `void log() const` |Puts the object (or `null`) into the log.
| `boolean is_bound() const` |Returns TRUE if the reference is not `null`.
| `boolean is_value() const` |Returns TRUE if the reference is not `null`.
| `boolean is_present() const` |Returns TRUE if the reference is not `null`.
|==================================================