Thank you for your interesting question and feedback on the documentation section of ADOxx. We are continously updating and enhancing the documentation pages and appreciate community feedback.
With respect to the map "concept" in ADOxx, please find below a detailled summary of the functionality provided by this data structure
1. Create a new empty map using AdoScript
1SETL mMap: (map())
2CC "AdoScript" INFOBOX ("This is the empty map: " + STR mMap)
A key and a related value are separated by a colon (":"), multiple key-value pairs are separated by comma (","), the set of pairs is enclosed in curly parentheses ("{" and "}").#
Important remark: As the colon character (":") is used for defining maps, a key (if of type string) must not contain such a character. If this is not respected, ADOxx will display an error message. Minding the colon character is especially relevant, if not fixed, but dynamic keys are used (e.g. object names).
2. Create/Initialize a map with key/value paris
1SETL mMap: ({ 1780: "Sim", 1920: "Sala", 2007: "Bim" })
2CC "AdoScript" INFOBOX ("This is the initial map: " + STR mMap)
3. Get the map length using m.length or LEN (m)
Length (size) of a map. m has to be of type map. The result is number of elements of m. Alternatively, LEN m can be used
1SETL nMapSize: (mMap.length)
2CC "AdoScript" INFOBOX ("The map has " + STR nMapSize + " entries.")
4. Check on empty map using m.empty
Returns 1 (true) if the map is empty and 0 (false) otherwise.
1SETL bIsEmpty: (mMap.empty)
2CC "AdoScript" INFOBOX ("The map is empty? " + STR bIsEmpty)
5. Remove map item by key using merase(m, k)
1SETL dummy: (merase (mMap, 1780))
2CC "AdoScript" INFOBOX ("After removal the map look like this: " + STR mMap)
The return of merase is the value of the deleted entry
6. Add item to map using subscription
1SETL mMap[2014]:"Bam"
2CC "AdoScript" INFOBOX ("Including the new item, the map look like this: " + STR mMap)
7. Retrieve value by key
Subscription to a map using SUB or []
m SUB k or m, where m has to be of type map, k of type string, integer, real, measure or time. The result is the element of m with key k. If the key is not contained in the map, the result is of type undefined.
Value elements of a map, and so the result of the subscription, may be of any type. The type of two different value elements of one map needs not to be the same. Use type() if you are not sure about a value element's type.
1SETL value: (mMap SUB 2014)
2CC "AdoScript" INFOBOX ("The value for key 2014: " + value)
8. Application of above concepts to realize a keyset iterator (assuming integer keys)
1SETL sMap: (STR mMap)
2SETL sMap: (replall(sMap, "{", ""))
3SETL sMap: (replall(sMap, "}", ""))
4SETL nTokenCount: (tokcnt (sMap, ","))
5SETL aKeySet: (array(nTokenCount))FOR nCount from:0 to: (nTokenCount-1) by:1 {
6 SETL aKeySet: (VAL (copy (token (sMap, nCount, ","), 0, search (token (sMap, nCount, ","), ":", 0))).trim())
7}
8CC "AdoScript" INFOBOX ("The keyset of the array looks like this: " + STR aKeySet)
9# Iterate through map and return all values
10FOR nCount from:0 to: (aKeySet.length-1) by:1 {
11 SETL nKey: (aKeySet)
12 SETL sValue: (mMap)
13 CC "AdoScript" INFOBOX ("The current key is: " + STR nKey + "\nFor this key the value is: " + sValue)
14}
Please be aware that the above approach assumes integer keys and uses the ADOxx array concept to store the keyset. The functionality can be globally added to your implementation by adding an AdoScript FUNCTION
In addition to the above functionality, additional functionality is planned for an upcoming ADOxx platform release.