Skip to main content

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

Parameters

NameTypeCommentKind
objectCNM_AbstractObject.IObjectthe dataobject to be contained inside the elementinput
previousElementCNM_CollectionInterfaces.IDoublyLinkedElementthe previous element to link toinput
nextElementCNM_CollectionInterfaces.IDoublyLinkedElementthe next element to link toinput
linkElementsBOOLa flag if the link to next and previous should be createdinput
elementCNM_CollectionInterfaces.IDoublyLinkedElementthe created array linked list container elementoutput

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