json_value_is_child_of Function

private function json_value_is_child_of(json, p1, p2) result(is_child_of)

Returns True if p2 is a descendant of p1 (i.e, a child, or a child of child, etc.)

Type Bound

json_core

Arguments

Type IntentOptional Attributes Name
class(json_core), intent(inout) :: json
type(json_value), pointer :: p1
type(json_value), pointer :: p2

Return Value logical(kind=LK)


Calls

proc~~json_value_is_child_of~~CallsGraph proc~json_value_is_child_of json_core%json_value_is_child_of proc~json_traverse json_core%json_traverse proc~json_value_is_child_of->proc~json_traverse none~throw_exception json_core%throw_exception proc~json_traverse->none~throw_exception proc~json_throw_exception json_core%json_throw_exception none~throw_exception->proc~json_throw_exception

Called by

proc~~json_value_is_child_of~~CalledByGraph proc~json_value_is_child_of json_core%json_value_is_child_of proc~json_value_swap json_core%json_value_swap proc~json_value_swap->proc~json_value_is_child_of

Source Code

    function json_value_is_child_of(json,p1,p2) result(is_child_of)

    implicit none

    class(json_core),intent(inout) :: json
    type(json_value),pointer       :: p1
    type(json_value),pointer       :: p2
    logical(LK)                    :: is_child_of

    is_child_of = .false.

    if (json%exception_thrown) return

    if (associated(p1) .and. associated(p2)) then
        if (associated(p1%children)) then
            call json%traverse(p1%children,is_child_of_callback)
        end if
    end if

    contains

    subroutine is_child_of_callback(json,p,finished)
    !! Traverse until `p` is `p2`.
    implicit none

    class(json_core),intent(inout)      :: json
    type(json_value),pointer,intent(in) :: p
    logical(LK),intent(out)             :: finished

    is_child_of = associated(p,p2)
    finished = is_child_of  ! stop searching if found

    end subroutine is_child_of_callback

    end function json_value_is_child_of