Search code examples
ibm-doors

How can I count all elements in a DXL skip list


I am trying to count all elements within a Skip list without having to know the type of the element contained within it.

like this:

Module mod = current()
Skip skip = create()

put(skip, 1, "test")
put(skip, 2, mod)

print count(skip) // Returns integer

Solution

  • As far as I know, DOORS does not support this natively. To create this functionality I took advantage of an odd loop behavior where the object in a loop doesn't get assigned until you actually use it:

    int count(Skip skip)
    {
        if(null skip)
            return 0
    
        int i = 0
    
        // Doesn't get assigned unless you do something like obj = obj within the loop
        string obj = null 
    
        for obj in skip do
        {
            i++
        }
    
        return i
    }