Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(inout), | 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. |
Remove a json_value (and all its children) from a linked-list structure, preserving the rest of the structure.
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
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(json_value), | public, | pointer | :: | parent | |||
type(json_value), | public, | pointer | :: | previous | |||
type(json_value), | public, | pointer | :: | next | |||
logical(kind=LK), | public | :: | destroy_it |
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