Newer
Older
/**
* @author ETSI
* @version $URL$
* $Id$
* @desc A collection of functions for abstract data types which may be
* useful in the implementation of any TTCN-3 test suite.
* @remark End users should be aware that any changes made to the in
* definitions this module may be overwritten in future releases.
* End users are encouraged to contact the distributers of this
* module regarding their modifications or additions so that future
* updates will include your changes.
* @copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
*
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
106
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
*/
module LibCommon_AbstractData {
import from LibCommon_BasicTypesAndValues { type UInt } ;
group stringStack {
type record StringStack {
UInt stackSize,
StringItems stringItems
}
type record of charstring StringItems;
/**
* @desc Constant which can be used to initialize a
* string stack. A string stack can be intialized by
* assigning this value in the variable declariation.
* An alternative is to call the initlialization function.
* @see LibCommon_AbstractData.f_initStringStack
* @remark Note that an initlialized stack stack is not
* necessarily the same as an empty string stack.
* An empty tring stack as 0 zero elements but may
* have a non empty list of (empty) items.
*/
const StringStack c_initStringStack := { 0, {} }
/**
* @desc The invocation of this function will initialize
* a string stack to an empty string stack.
* An alternative is to initlialize a stack using a
* constant value.
* @see LibCommon_AbstractData.c_initStringStack
* @param p_stack String stack to be initialized.
*/
function f_initStringStack ( inout StringStack p_stack ) {
p_stack := c_initStringStack
}
/**
* @desc This function checks if a string stack is empty.
* @param p_stack String stack to be checked.
* @return true if empty, false if not empty
*/
function f_isStringStackEmpty ( inout StringStack p_stack )
return boolean {
if ( p_stack.stackSize == 0 ) {return true}
else {return false}
}
/**
* @desc This function checks if a given string is on the
* string stack.
* @param p_stack String stack where the string item
* is to be looked for.
* @param p_item String to be checked for.
* @return true if found, false if not found
*/
function f_isItemOnStringStack ( inout StringStack p_stack,
in charstring p_item )
return boolean {
var integer i;
for (i := 0; i < p_stack.stackSize; i := i+1 ) {
if ( p_stack.stringItems[i] == p_item ) {
return true;
}
}
return false;
}
/**
* @desc This function checks if a given string is on the
* string stack.
* @param p_stack String stack where the string item
* is to be looked for.
* @param p_item String item on top of the stack.
* @return false if stack is empty, true otherwise
*/
function f_peekStringStackTop ( inout StringStack p_stack,
out charstring p_item)
return boolean {
if (p_stack.stackSize == 0) {
p_item := "f_peekTopStringStack: String stack is empty!";
return false;
}
p_item := valueof(p_stack.stringItems[p_stack.stackSize-1]);
return true;
}
/**
* @desc This function puts a string to the top of a
* string stack.
* @param p_stack String stack to which the string item
* is to be added.
* @param p_item String to be added.
*/
function f_pushStringStack ( inout StringStack p_stack,
in charstring p_item ) {
p_stack.stringItems[p_stack.stackSize] := p_item;
p_stack.stackSize := p_stack.stackSize + 1;
}
/**
* @desc This function removes the string from the top of a
* string stack. If the stack is empty nothing is done
* @param p_stack String stack from which the top string item
* is to be removed.
*/
function f_popStringStack ( inout StringStack p_stack ) {
if ( p_stack.stackSize > 0 ) {
p_stack.stackSize := p_stack.stackSize-1;
// "delete" top stack item to be safe
// Note: due to record of index the "old top" is size-1!
p_stack.stringItems[p_stack.stackSize] := "";
}
}
} // end group stringStack
} // end module LibCommon_AbstractData