Traverse dictionary from head to tail calling the iterator procedure.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dictionary), | intent(in) | :: | self | The dictionary. |
||
procedure(key_iterator_interface) | :: | iterator | The (key) iterator procedure to call for each node. |
subroutine traverse(self, iterator)
!---------------------------------------------------------------------------------------------------------------------------------
!< Traverse dictionary from head to tail calling the iterator procedure.
!---------------------------------------------------------------------------------------------------------------------------------
class(dictionary), intent(in) :: self !< The dictionary.
procedure(key_iterator_interface) :: iterator !< The (key) iterator procedure to call for each node.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
call self%traverse_iterator(key_iterator_wrapper)
!---------------------------------------------------------------------------------------------------------------------------------
contains
subroutine key_iterator_wrapper(node, done)
!-------------------------------------------------------------------------------------------------------------------------------
!< Wrapper for calling the user-specified key_iterator procedure.
!-------------------------------------------------------------------------------------------------------------------------------
type(dictionary_node), pointer, intent(in) :: node !< The dictionary node.
logical, intent(out) :: done !< Flag to set to true to stop traversing.
!-------------------------------------------------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------------------------------------------------
if (node%has_key()) call iterator(key=node%key, content=node%get_pointer(), done=done)
!-------------------------------------------------------------------------------------------------------------------------------
endsubroutine key_iterator_wrapper
endsubroutine traverse