// September 2015 // Levee Patroller / Dijk Patrouille // This source file is (c) by Deltares. This source file is open source but only available to select users. Do not redistribute without written permission of Stichting Deltares, Delft, The Netherlands. // This header has been automatically generated. //============================================================================= // Small hashtable-class used by the MenuActionCenter subclasses // // A simple hashtable with no remove functionality; multiple values can // be assigned for each key (MAXIMUM 10!!); when retrieving for a certain key having // multiple values, a random one is returned (this is useful for defining // more loose and natural dialogues). // ------------------------------------------------------------ // Created by Maarten Wesselius // © 2006, GeoDelft // // Date Id Modification // 2007-04-13 wsl extended to allow for multiple values per key // 2007-04-13 wsl removed getKey and setValue because they are not used //============================================================================= class QAStringHashTable extends Object; struct ValueArray { var string valuelist[10]; var int count; }; var array keys; var array values; //============================================================================= // Date Id Modification // 2007-04-13 wsl adapted to multiple value-situation. // // If a single value has been defined for this key, returns it. In case of // multiple values, a random value from the list is returned. //============================================================================= function string getValue(string key) { local int i; local int rnd; for(i = 0; i < keys.length; i++) { if(keys[i] == key) { rnd = Rand(values[i].count); return values[i].valuelist[rnd]; } } return ""; } //============================================================================= // Date Id Modification // 2007-04-13 wsl adapted to multiple value-situation. // // This function adds a new key-value pair if the key is new. If values already // existed for this key, the value is added to the list of values. However, // if there are already max (10) values in this list, nothing is added. //============================================================================= function add(string key, string val) { local int i; if(Len(getValue(key)) > 0) { // already value(s) for this key; add this value i = 0; while(i < keys.length && key != keys[i]) { i++; } if(values[i].count < 10) { values[i].valuelist[values[i].count] = val; values[i].count++; } } else { // key doesn't exist yet; make new key and new value keys.insert(0,1); keys[0] = key; values.insert(0,1); values[0].valuelist[0] = val; values[0].count = 1; } } function string toString() { local string ans; local int i, k; ans = "QAStringHashTable:"; for(i = 0; i < keys.length; i++) { ans = ans @ "["$i$"] = " $ keys[i] @ "-"; if(values[i].count > 1) { for(k = 0; k < values[i].count; k++) { ans = ans @ values[i].valuelist[k] $ ", "; } } else { ans = ans @ values[i].valuelist[0]; } ans = ans $ "||"; } return ans; }