Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(linked_node), | intent(inout) | :: | this | |||
class(linked_node), | intent(in), | pointer | :: | new_next | The node which will now be next in the chain. |
|
logical, | intent(in), | optional | :: | deallocate_old | Whether to deallocate (rather than just nullify) any existing
subsequent nodes in the chain. Defaults to |
Sets the node which this one points to (i.e. sets the next node in
the chain). If this node already points to another one, the
pointer will, by default, be nullified. This may result in a
memory leak. Optionally, by setting deallocate_old=.true.
, the
next node (and all nodes it points to) can be deallocated. This
may result in a segfault if another part of the program tries to
access the former next node.
subroutine set_next(this, new_next, deallocate_old)
!* Author: Chris MacMackin
! Date: February 2016
!
! Sets the node which this one points to (i.e. sets the next node in
! the chain). If this node already points to another one, the
! pointer will, by default, be nullified. This may result in a
! memory leak. Optionally, by setting `deallocate_old=.true.`, the
! next node (and all nodes it points to) can be deallocated. This
! may result in a segfault if another part of the program tries to
! access the former next node.
!
class(linked_node), intent(inout) :: this
class(linked_node), pointer, intent(in) :: new_next
!! The node which will now be next in the chain.
logical, optional, intent(in) :: deallocate_old
!! Whether to deallocate (rather than just nullify) any existing
!! subsequent nodes in the chain. Defaults to `.false.`.
call this%unset_next(deallocate_old)
this%next => new_next
end subroutine set_next