3 04 2014
Presence checking functions
A mayor difference between TTCN-3 and other languages are partial initialized variables. If you set a variable in Java or C# to null it isn’t initialized at all. In TTCN-3 you have to use omit instead of null, but this will initialize the variable partially.
There are a few functions to check in which state a variable is and in this post I’ll show you all the possible results.
In TTCN-3 you can use ispresent, isbound and isvalue. Unfortunately there is no isnull or isomit or even a iswildcard. We have to write by our own, but this will be another post.
ispresent returns true if the variable or template provide has a concrete value or a pattern which stands for a concrete value. You’ll have a look at the table below to understand what that means :D.
isbound returns true not matter what value is set. This means it only returns false if you never touched the variable. There is no way to “unbound” a variable after it is set.
isvalue returns true if you set a real value. Every pattern, omit and null will result in a false.
Assignment | ispresent | isbound | isvalue |
---|---|---|---|
[ttcn3 inline=”true”]var charstring v_test01[/ttcn3] | false | false | false |
[ttcn3 inline=”true”]var charstring v_test02 := null[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var charstring v_test03 := “”[/ttcn3] | true | true | true |
[ttcn3 inline=”true”]var template charstring v_test11[/ttcn3] | false | false | false |
[ttcn3 inline=”true”]var template charstring v_test12 := omit[/ttcn3] | false | true | false |
[ttcn3 inline=”true”]var template charstring v_test13 := null[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template charstring v_test14 := *[/ttcn3] | false | true | false |
[ttcn3 inline=”true”]var template charstring v_test15 := ?[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template charstring v_test16 := “”[/ttcn3] | true | true | true |
[ttcn3 inline=”true”]var template charstring v_test17 := pattern “*”[/ttcn3] | false | true | false |
[ttcn3 inline=”true”]var template (omit) charstring v_test21[/ttcn3] | false | false | false |
[ttcn3 inline=”true”]var template (omit) charstring v_test22 := omit[/ttcn3] | false | true | false |
[ttcn3 inline=”true”]var template (omit) charstring v_test23 := null[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template (omit) charstring v_test := *[/ttcn3] | |||
[ttcn3 inline=”true”]var template (omit) charstring v_test := ?[/ttcn3] | |||
[ttcn3 inline=”true”]var template (omit) charstring v_test26 := “”[/ttcn3] | true | true | true |
[ttcn3 inline=”true”]var template (omit) charstring v_test := pattern “*”[/ttcn3] | |||
[ttcn3 inline=”true”]var template (value) charstring v_test31[/ttcn3] | false | false | false |
[ttcn3 inline=”true”]var template (value) charstring v_test := omit[/ttcn3] | |||
[ttcn3 inline=”true”]var template (value) charstring v_test33 := null[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template (value) charstring v_test := *[/ttcn3] | |||
[ttcn3 inline=”true”]var template (value) charstring v_test := ?[/ttcn3] | |||
[ttcn3 inline=”true”]var template (value) charstring v_test36 := “”[/ttcn3] | true | true | true |
[ttcn3 inline=”true”]var template (value) charstring v_test := pattern “*”[/ttcn3] | |||
[ttcn3 inline=”true”]var template (present) charstring v_test41[/ttcn3] | false | false | false |
[ttcn3 inline=”true”]var template (present) charstring v_test := omit[/ttcn3] | |||
[ttcn3 inline=”true”]var template (present) charstring v_test43 := null[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template (present) charstring v_test := *[/ttcn3] | |||
[ttcn3 inline=”true”]var template (present) charstring v_test45 := ?[/ttcn3] | true | true | false |
[ttcn3 inline=”true”]var template (present) charstring v_test46 := “”[/ttcn3] | true | true | true |
[ttcn3 inline=”true”]var template (present) charstring v_test47 := pattern “*”[/ttcn3] | false | true | false |
The light red line are not valid in TTCN-3 and therefor have no value.
Variable v_test17 and v_test47 are marked yellow for ispresent, because of a wrong handling in TTWorkbench which will return true instead of false.
As you can see, there is now way to distinguish null from ? or omit from *.
So if you want to use an optional parameter to get a pattern, you have no way to tell if the value is set by the user or your default-value.
For that, you will need external functions.
Basic datatypes in TTCN-3 Limitation of Path.GetTempFileName