Check if the key is present in the dictionary.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dictionary), | intent(in) | :: | self | The dictionary. |
||
class(*), | intent(in) | :: | key | The key. |
Check result.
function has_key(self, key)
!---------------------------------------------------------------------------------------------------------------------------------
!< Check if the key is present in the dictionary.
!---------------------------------------------------------------------------------------------------------------------------------
class(dictionary), intent(in) :: self !< The dictionary.
class(*), intent(in) :: key !< The key.
logical :: has_key !< Check result.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
has_key = .false.
call self%traverse_iterator(iterator=key_iterator_search)
!---------------------------------------------------------------------------------------------------------------------------------
contains
subroutine key_iterator_search(node, done)
!-------------------------------------------------------------------------------------------------------------------------------
!< Iterator procedure for searching a key.
!-------------------------------------------------------------------------------------------------------------------------------
type(dictionary_node), pointer, intent(in) :: node !< Actual node pointer in the dictionary.
logical, intent(out) :: done !< Flag to set to true to stop traversing.
!-------------------------------------------------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------------------------------------------------
has_key = .false.
if (node%has_key()) has_key = node%key==key
done = has_key
!-------------------------------------------------------------------------------------------------------------------------------
endsubroutine key_iterator_search
endfunction has_key