getNewDoublyLinkedElement
Short summary
Method to create new Instance of DoublyLinkedElements and automatically link with other ellements. This will affect/change the next and previouse elements !
Return: SingleExecutionResult.SUCCESS: allocation succesful, output element contains new list element instance
SingleExecutionResult.ERROR: error during allocation, output element is NULL
- Return type: CNM_ReturnTypes.SingleExecutionResult
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| object | CNM_AbstractObject.IObject | the dataobject to be contained inside the element | input |
| previousElement | CNM_CollectionInterfaces.IDoublyLinkedElement | the previous element to link to | input |
| nextElement | CNM_CollectionInterfaces.IDoublyLinkedElement | the next element to link to | input |
| linkElements | BOOL | a flag if the link to next and previous should be created | input |
| element | CNM_CollectionInterfaces.IDoublyLinkedElement | the created array linked list container element | output |
Code
Declaration
METHOD getNewDoublyLinkedElement :CNM_ReturnTypes.SingleExecutionResult
VAR_INPUT
(*the dataobject to be contained inside the element*)
object :CNM_AbstractObject.IObject;
(*the previous element to link to*)
previousElement :CNM_CollectionInterfaces.IDoublyLinkedElement;
(*the next element to link to*)
nextElement :CNM_CollectionInterfaces.IDoublyLinkedElement;
(*a flag if the link to next and previous should be created*)
linkElements :BOOL := TRUE;
END_VAR
VAR_OUTPUT
(* the created array linked list container element *)
element :CNM_CollectionInterfaces.IDoublyLinkedElement;
END_VAR
VAR
newElement :POINTER TO DoublyLinkedElement;
END_VAR
Implementation
getNewDoublyLinkedElement := CNM_ReturnTypes.SingleExecutionResult.ERROR;
newElement := __NEW(
DoublyLinkedElement(
content := object,
previous := previousElement,
next := nextElement
)
);
IF (newElement <> 0) THEN
IF (linkElements) THEN
IF (THIS^.isObjectValid(previousElement)) THEN
previousElement.next := newElement^;
END_IF
IF (THIS^.isObjectValid(nextElement)) THEN
nextElement.previous := newElement^;
END_IF
END_IF
element := newElement^;
getNewDoublyLinkedElement := CNM_ReturnTypes.SingleExecutionResult.SUCCESS;
END_IF