Sentinel while-loop on nodes returning the key/content pair (for dictionary looping).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dictionary), | intent(in) | :: | self | The dictionary. |
||
class(*), | intent(out), | optional | allocatable | :: | key | The key. |
class(*), | intent(out), | optional | pointer | :: | content | The content. |
Sentinel flag to contine the loop.
function loop(self, key, content) result(again)
!---------------------------------------------------------------------------------------------------------------------------------
!< Sentinel while-loop on nodes returning the key/content pair (for dictionary looping).
!---------------------------------------------------------------------------------------------------------------------------------
class(dictionary), intent(in) :: self !< The dictionary.
class(*), allocatable, intent(out), optional :: key !< The key.
class(*), pointer, intent(out), optional :: content !< The content.
logical :: again !< Sentinel flag to contine the loop.
type(dictionary_node), pointer, save :: p=>null() !< Pointer to current node.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
again = .false.
if (present(content)) content => null()
if (self%nodes_number>0) then
if (.not.associated(p)) then
p => self%head
if (present(key).and.p%has_key()) allocate(key, source=p%key)
if (present(content)) content => p%get_pointer()
again = .true.
elseif (associated(p%next)) then
p => p%next
if (present(key).and.p%has_key()) allocate(key, source=p%key)
if (present(content)) content => p%get_pointer()
again = .true.
else
p => null()
again = .false.
endif
endif
!---------------------------------------------------------------------------------------------------------------------------------
endfunction loop