json_value_remove Subroutine

private subroutine json_value_remove(me, destroy)

Arguments

Type IntentOptional AttributesName
type(json_value), , pointer:: me
logical(kind=LK), intent(in), optional :: destroy

If destroy is not present, it is also destroyed. If destroy is present and true, it is destroyed. If destroy is present and false, it is not destroyed.

Description

Remove a json_value (and all its children) from a linked-list structure, preserving the rest of the structure.

Examples

To extract an object from one JSON structure, and add it to another:

     type(json_value),pointer :: json1,json2,p
     logical :: found
     !create and populate json1 and json2
     call json_get(json1,'name',p,found)  ! get pointer to name element of json1
     call json_remove(p,destroy=.false.)  ! remove it from json1 (don't destroy)
     call json_add(json2,p)               ! add it to json2

To remove an object from a JSON structure (and destroy it):

     type(json_value),pointer :: json1,p
     logical :: found
     !create and populate json1
     call json_get(json1,'name',p,found)  ! get pointer to name element of json1
     call json_remove(p)                  ! remove and destroy it

History

  • Jacob Williams : 12/28/2014 : added destroy optional argument.

Calls

proc~~json_value_remove~~CallsGraph proc~json_value_remove json_value_remove proc~json_value_destroy json_value_destroy proc~json_value_remove->proc~json_value_destroy proc~json_value_destroy->proc~json_value_destroy proc~destroy_json_data destroy_json_data proc~json_value_destroy->proc~destroy_json_data
Help

Called By

proc~~json_value_remove~~CalledByGraph proc~json_value_remove json_value_remove interface~json_remove json_remove interface~json_remove->proc~json_value_remove proc~test_1 test_1 proc~test_1->interface~json_remove proc~json_value_remove_if_present json_value_remove_if_present proc~json_value_remove_if_present->interface~json_remove proc~test_7 test_7 proc~test_7->interface~json_remove program~jf_test_1 jf_test_1 program~jf_test_1->proc~test_1 proc~wrap_json_value_remove_if_present wrap_json_value_remove_if_present proc~wrap_json_value_remove_if_present->proc~json_value_remove_if_present interface~json_remove_if_present json_remove_if_present interface~json_remove_if_present->proc~json_value_remove_if_present proc~test_10 test_10 proc~test_10->interface~json_remove_if_present program~jf_test_10 jf_test_10 program~jf_test_10->proc~test_10 program~jf_test_7 jf_test_7 program~jf_test_7->proc~test_7
Help

Variables

TypeVisibility AttributesNameInitial
type(json_value), public, pointer:: parent
type(json_value), public, pointer:: previous
type(json_value), public, pointer:: next
logical(kind=LK), public :: destroy_it

Source Code

    subroutine json_value_remove(me,destroy)

    implicit none

    type(json_value),pointer        :: me
    logical(LK),intent(in),optional :: destroy  !! If destroy is not present, it is also destroyed.
                                                !! If destroy is present and true, it is destroyed.
                                                !! If destroy is present and false, it is not destroyed.

    type(json_value),pointer :: parent,previous,next
    logical(LK) :: destroy_it

    if (associated(me)) then

        !optional input argument:
        if (present(destroy)) then
            destroy_it = destroy
        else
            destroy_it = .true.
        end if

        if (associated(me%parent)) then

            parent => me%parent

            if (associated(me%next)) then

                !there are later items in the list:

                next => me%next
                nullify(me%next)

                if (associated(me%previous)) then
                    !there are earlier items in the list
                    previous => me%previous
                    previous%next => next
                    next%previous => previous
                else
                    !this is the first item in the list
                    parent%children => next
                    nullify(next%previous)
                end if

            else

                if (associated(me%previous)) then
                    !there are earlier items in the list:
                    previous => me%previous
                    nullify(previous%next)
                    parent%tail => previous
                else
                    !this is the only item in the list:
                    nullify(parent%children)
                    nullify(parent%tail)
                end if

            end if

            parent%n_children = parent%n_children - 1

        end if

        if (destroy_it) call json_value_destroy(me)

    end if

    end subroutine json_value_remove