Skip to main content

iterate

Short summary

This method returns the next object in the iteration and returns an execution state. Example: You have a list: 1 2 3 the first iterate call will return CNM_ReturnTypes.BUSY and object = 1 the second iterate call will return CNM_ReturnTypes.BUSY and object = 2 the third iterate call will return CNM_ReturnTypes.BUSY and object = 3 the forth iterate call will return CNM_ReturnTypes.SUCCESS and object = NULL

Return: SingleExecutionState.SUCCESS: Iteration finished, no new elements, returned NULL object SingleExecutionState.ERROR: error during iteration SingleExecutionState.ABORT: iteration aborted SingleExecutionState.BUSY: returned an element and iteration in progress SingleExecutionState.IDLE: ready for iteration

Parameters

NameTypeCommentKind
executeBOOL-input
objectCNM_AbstractObject.IObject-output

Code

Declaration

METHOD iterate : CNM_ReturnTypes.SingleExecutionState
VAR_INPUT
execute : BOOL;
END_VAR
VAR_OUTPUT
object :CNM_AbstractObject.IObject;
END_VAR
VAR
tmp : POINTER TO CNM_AbstractObject.Object;
END_VAR
VAR_INST
cycleManager :CNM_CycleManager.SimpleCycleManager;
lastExecute :BOOL;
lastChangeVersion :__XWORD;
END_VAR
VAR CONSTANT
INIT :DINT := CNM_ReturnTypes.DefaultSteps.STEP.INIT;
ITERATING :DINT := INIT + 1;
ERROR :DINT := CNM_ReturnTypes.DefaultSteps.STEP.ERROR;
SUCCESS :DINT := CNM_ReturnTypes.DefaultSteps.STEP.SUCCESS;
NULL: __XWORD := 0;
END_VAR

Implementation

iterate := CNM_ReturnTypes.SingleExecutionState.ERROR;
RETURN (NOT THIS^.isObjectValid(THIS^.tree));
cycleManager(execute := execute);
CASE cycleManager.step.current OF
INIT:
cycleManager.configuration.sequence.requireSuccessStep := FALSE;
lastChangeVersion := THIS^.changes;
THIS^.nodeList.clear();
THIS^.currentNode := THIS^.getStartNode();
IF THIS^.isObjectValid(THIS^.currentNode) THEN
THIS^.processStartNode(THIS^.currentNode);
THIS^.currentObject := THIS^.currentNode.object;
ELSE
THIS^.currentObject := 0;
END_IF

cycleManager.proceedWith(
step := SEL(
THIS^.hasNext(),
SUCCESS,
ITERATING
)
);
ITERATING:
IF lastChangeVersion <> THIS^.changes THEN
iterate := CNM_ReturnTypes.SingleExecutionState.ERROR;
cycleManager.proceedWith(ERROR);
RETURN;
END_IF
IF(THIS^.hasNext()) AND_THEN THIS^.getNextTreeNode(node => THIS^.currentNode) THEN
THIS^.currentObject := THIS^.currentNode.object;
THIS^.processNode(THIS^.currentNode);
ELSE
cycleManager.proceedWith(SUCCESS);
THIS^.currentObject := NULL;
END_IF
END_CASE

iterate := cycleManager.state;
object := THIS^.currentObject;