Teledyne LeCroy SAS_SATA Protocol Suite Verification Script Engine Reference Manual User Manual

Page 34

Advertising
background image


34

Example 2

# Example of map having mixed types of keys - both integer and string.

set MyMap = Map(
[
[0, 1, 2, 3],
[1, 3, 4, 5],
[2, 6, 7, 8],
["JoJo", 4, 8, 9],
["Papa", 14, 18, 19]
]
);

# Keys in the map object are : 0, 1, 2, "JoJo", "PaPa"

set MyMap = Map( );

# empty map


Example: Setting and getting values to or from map object

MyMap["JoJo"] = 12;

# Set pair: key : "JoJo", value : 12.

entry = MyMap["JoJo"];

# Get value at key : "JoJo".

MyMap[7] = [7, 8, 9, 10];

# Set pair: key : 7, value : [7, 8, 9, 10].

entry = MyMap[7];

# Get value at key : 7.



Remarks

Maps can use the operators sizeof(), first(), more(), and next()

.

# Iterate through all elements of the map.

for( item = first(MyMap); more(MyMap); item = next(MyMap) )
{
ReportText("---------------------------------------------");

if( IsString( item[0] ) )
ReportText( FormatEx( "Item[0] = %s", item[0] ) );
else
ReportText( FormatEx( "Item0] = %d", item[0] ) );
}


Maps can use the functions IsNull(), IsInt(), IsString(), IsList(), IsArray(), and IsMap().
These functions determine a type of script object inside a script.





Advertising