List and Dictionaries
In XenoGuard, lists and dictionaries are two central data structures that cover various application areas:
- Lists in XenoGuard are used for storing strings in a sequential order. Each element has a specific index by which it can be referenced. Typical actions include adding, deleting, and modifying list elements, as well as completely listing the contents. Lists are suitable for storing a sequence of tasks, sequential data inputs like log entries, or other ordered information.
- Dictionaries in XenoGuard store data in key-value pairs, where both keys and values are of the string type. This allows for fast data retrieval by specifying the key. Just like with lists, you can add, modify, or delete elements, as well as display the entire content. Dictionaries are particularly suitable for configuration data, where specific values need to be retrieved via a unique key, or for database-like queries where an association between key and value is required.
Both structures are useful in XenoGuard because they enable efficient handling and manipulation of data, thereby facilitating automation and data processing. Both mechanisms will be introduced in the following sections.
Lists
XenoGuard provides a total of 12 actions for processing lists. You can find the corresponding group named List in the main Programming group:
The following table explains each action:
Action | Description |
---|---|
Create | This action initializes a new, empty list. |
Add | Adds a new entry (string value) at the end of the list. |
Add From | Enables the addition of entries from a parameter list. |
Set At Index | Changes the value of an entry at a specific index within the list. |
Get | Retrieves the value of an entry at a specific index. |
Contains | Checks if a specific value is present. |
Count | Returns the number of entries in the list. |
Iterate | Iterates through all list entries and lists them. |
Remove | Removes a specific value from the list. |
Remove At | Removes the entry at a specific index. |
Remove Match | Removes entries that meet a specific criterion or pattern. |
Clear | Removes all entries from the list and resets it. |
With the Create action, new lists can be created. Similar to identifiers, lists can either be placed in a local or global context. When placed in the global context, the lists and their elements are accessible to all scripts. The following example reads electronic components from a text file, adds them to a list, and then checks if the component Resistor is included in it. If there's a match, a message box is displayed.
Dictionaries
In XenoGuard, dictionaries allow the storage of data as key-value pairs, where both are of the string type. They are particularly suitable for configuration data and database-like queries, where a quick association between key and value is required. XenoGuard supports a total of 10 actions:
The following table explains each action:
Action | Description |
---|---|
Create | This action initializes a new, empty dictionary. |
Add | Adds a new key-value pair to the dictionary. |
Get | Determines the value associated with a specific key in the dictionary. |
Get At | Retrieves the value at a specific position within the dictionary. |
Contains | Checks if a certain key exists in the dictionary. |
Count | Returns the number of key-value pairs stored in the dictionary. |
Iterate | Iterates all dictionary elements and lists the results. |
Remove | Removes a specific key-value pair from the dictionary. |
Remove At | Deletes the key-value pair at a specific position in the dictionary. |
Clear | Removes all key-value pairs from the dictionary. |
The following example processes an inventory list of electronic components, consisting of serial numbers, descriptions, and quantities. After reading the file, the entries are transferred into a dictionary, with the serial number serving as the key to avoid duplicates. Finally, the script iterates through all the dictionary entries.