Skip to main content

instantInsertCollection

Short summary

This method inserts all elements of a collection into the tree This takes only one cycle.

Return: SingleExecutionResult.SUCCESS: operation successful SingleExecutionResult.ERROR: out of memory SingleExecutionResult.ABORTED: collection to insert wasn't valid (NULL) or the tree itself was passed

Parameters

NameTypeCommentKind
collectionCNM_CollectionInterfaces.ICollectionThe collection that should be insertedinput

Code

Declaration

METHOD INTERNAL instantInsertCollection : CNM_ReturnTypes.SingleExecutionResult
VAR_INPUT
(*The collection that should be inserted*)
collection : CNM_CollectionInterfaces.ICollection;
END_VAR
VAR
insertIterator :CNM_CollectionInterfaces.IIterator;
insertObject :CNM_AbstractObject.IObject;
insertedObjects :POINTER TO CNM_AbstractObject.IObject;
index :LINT := 0;
iteratorState :CNM_ReturnTypes.SingleExecutionState;
insertWasError :BOOL := FALSE;
END_VAR
VAR CONSTANT
NULL :__XWORD := 0;
END_VAR

Implementation

instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.ABORTED;
RETURN( THIS^.isObjectNull(collection) OR_ELSE THIS^.isEqual(collection));
IF collection.isEmpty THEN
instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
RETURN;
END_IF

insertedObjects := __NEW(__XWORD, collection.size);
IF insertedObjects = NULL THEN
instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.ERROR;
RETURN;
END_IF

IF (collection.createNewIterator(iterator => insertIterator)
<> CNM_ReturnTypes.SingleExecutionResult.SUCCESS)
THEN
IF insertIterator <> 0 THEN
insertIterator.destruct();
END_IF
__DELETE(insertedObjects);
instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.ERROR;
END_IF
instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
insertIterator.iterate(execute := FALSE);
WHILE (
(iteratorstate := insertIterator.iterate(execute := TRUE, object => insertObject))
= CNM_ReturnTypes.SingleExecutionState.BUSY
) DO
CASE THIS^.insert(insertObject) OF
CNM_ReturnTypes.SingleExecutionResult.SUCCESS:
insertedObjects[index] := insertObject;
index := index +1;
CNM_ReturnTypes.SingleExecutionResult.ERROR:
insertWasError := TRUE;
EXIT;
END_CASE
END_WHILE

IF insertWasError OR_ELSE (iteratorState <> CNM_ReturnTypes.SingleExecutionState.SUCCESS) THEN
REPEAT
THIS^.remove(insertedObjects[index]);
index := index - 1;
UNTIL
(index < 0)
END_REPEAT
instantInsertCollection := CNM_ReturnTypes.SingleExecutionResult.ERROR;
END_IF

__DELETE(insertedObjects);
insertIterator.destruct();