next up previous contents index
Next: Zoidlist Overloads Up: Operator Overloading Previous: Array Overloads   Contents   Index

Handle Overloads

Handles can be used in conditional and logical expressions using the and (& ), or (| ), and not (! ) operators. If the handle is non-empty, it is ``true'', otherwise it is ``false''. This can be used as a far more efficient loop termination test than a call to HandleContent.

The relational operators have been overloaded for handles. The behavior for handles is the same as for scalars, with the handle index being used in the comparison. This is not expected to be useful, except perhaps for file descriptor handles.

The + operator is overloaded to perform concatenation, equivalent to a call to the HandleCat function. The syntax is

[h1 =] h2 + h3

This applies only to handles that contain a list of data items. Both h2 and h3 must contain lists of the same type of data. The list in h3 is copied and pasted on the end of h2. If a left hand side is given, it will be assigned the h2 handle value and be equivalent to h2. Most of the time, this is not needed.

The increment operator + + is overloaded to perform iteration, equivalent to a call to HandleNext or similar functions. The postfix and prefix forms are equivalent. The return value is simply a copy of the handle, so again use in an assignment is unlikely to be needed often.

Without overloading, code to iterate over a list handle would appear as

h = func_returning_list_handle()
while (HandleContent(h) != 0)
    (do something)
    HandleNext(h)
done

Making use of overloading, the same loop could take the following form:

h = func_returning_list_handle()
while (h)
    (do something)
    h++
done


next up previous contents index
Next: Zoidlist Overloads Up: Operator Overloading Previous: Array Overloads   Contents   Index
Stephen R. Whiteley 2022-05-28