Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(bidir_node), | intent(inout) | :: | this | |||
class(bidir_node), | intent(in), | pointer | :: | new_prev | The node which will now be previous in the chain. |
|
logical, | intent(in), | optional | :: | deallocate_old | Whether to deallocate (rather than just nullify) any existing
previous nodes in the chain. Defaults to |
Sets the pointer to the previous node in the chain. If this node
already points to a previous one, the pointer will, by default, be
nullified. This may result in a memory leak. Optionally, by
setting deallocate_old=.true.
, the previous 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 previous
node. The new previous node will not automatically be set to have
this one as the next, with the same rules applied to deallocation.
subroutine set_prev(this, new_prev, deallocate_old)
!* Author: Chris MacMackin
! Date: February 2016
!
! Sets the pointer to the previous node in the chain. If this node
! already points to a previous one, the pointer will, by default, be
! nullified. This may result in a memory leak. Optionally, by
! setting `deallocate_old=.true.`, the previous 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 previous
! node. The new previous node will not automatically be set to have
! this one as the next, with the same rules applied to deallocation.
!
class(bidir_node), intent(inout) :: this
class(bidir_node), pointer, intent(in) :: new_prev
!! The node which will now be previous in the chain.
logical, optional, intent(in) :: deallocate_old
!! Whether to deallocate (rather than just nullify) any existing
!! previous nodes in the chain. Defaults to `.false.`.
call this%unset_prev(deallocate_old)
this%prev => new_prev
end subroutine set_prev