Skip to content

Commit

Permalink
added destroy_pointer option to json_file load
Browse files Browse the repository at this point in the history
Fixes #571
  • Loading branch information
jacobwilliams committed Jun 11, 2024
1 parent 08fe9c3 commit 5f4690e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ end subroutine json_file_move_pointer
! end program main
!```

subroutine json_file_load(me, filename, unit)
subroutine json_file_load(me, filename, unit, destroy_pointer)

implicit none

Expand All @@ -860,8 +860,14 @@ subroutine json_file_load(me, filename, unit)
integer(IK),intent(in),optional :: unit !! the unit number to use
!! (if not present, a newunit
!! is used)
logical(LK),intent(in),optional :: destroy_pointer !! destroy the pointer before
!! loading (default is True)

call me%destroy()
if (present(destroy_pointer)) then
if (destroy_pointer) call me%destroy()
else ! by default it is destroyed
call me%destroy()
end if
call me%core%load(file=filename, p=me%p, unit=unit)

end subroutine json_file_load
Expand All @@ -881,14 +887,20 @@ end subroutine json_file_load
! call f%deserialize('{ "name": "Leonidas" }')
!```

subroutine json_file_load_from_string(me, str)
subroutine json_file_load_from_string(me, str, destroy_pointer)

implicit none

class(json_file),intent(inout) :: me
character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
logical(LK),intent(in),optional :: destroy_pointer !! destroy the pointer before
!! loading (default is True)

call me%destroy()
if (present(destroy_pointer)) then
if (destroy_pointer) call me%destroy()
else ! by default it is destroyed
call me%destroy()
end if
call me%core%deserialize(me%p, str)

end subroutine json_file_load_from_string
Expand Down

0 comments on commit 5f4690e

Please sign in to comment.