Skip to main content

createNewIterator

Short summary

This method returns a NEW Iterator instance which can iterate the collection. These iterators can be used parallel independend of each other on the same collection.

Warning: The returned Iterator was created using the __NEW operator and must be destructed to avoid memory leaks!

Parameters

NameTypeCommentKind
iteratorCNM_CollectionInterfaces.IIteratorThe new created iterator or null if allocation failsoutput

Code

Declaration

METHOD createNewIterator : CNM_CollectionInterfaces.CNM_ReturnTypes.SingleExecutionResult
VAR_OUTPUT
(*The new created iterator or null if allocation fails *)
iterator : CNM_CollectionInterfaces.IIterator;
END_VAR
VAR
newIterator :POINTER TO InorderBBSTIterator;
END_VAR

Implementation

newIterator := __NEW(InorderBBSTIterator(tree := THIS^));
IF (newIterator = 0) THEN
createNewIterator := CNM_ReturnTypes.SingleExecutionResult.ERROR;
RETURN;
END_IF
createNewIterator := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
__QUERYINTERFACE(newIterator^, iterator);