json_file_add Subroutine

private subroutine json_file_add(me, p, destroy_original)

Add a json_value pointer as the root object to a JSON file.

Note

This is mostly equivalent to:

    f = [[json_file]](p)

But without the finalization calls.

And:

    if (destroy_original) call [[json_file]]%destroy()
    call [[json_file]]%add('$',p)

Type Bound

json_file

Arguments

Type IntentOptional Attributes Name
class(json_file), intent(inout) :: me
type(json_value), intent(in), pointer :: p

pointer to the variable to add

logical(kind=LK), intent(in), optional :: destroy_original

if the file currently contains an associated pointer, it is destroyed. [Default is True]


Calls

proc~~json_file_add~~CallsGraph proc~json_file_add json_file%json_file_add proc~json_file_destroy json_file%json_file_destroy proc~json_file_add->proc~json_file_destroy none~destroy json_core%destroy proc~json_file_destroy->none~destroy proc~destroy_json_core json_core%destroy_json_core none~destroy->proc~destroy_json_core proc~json_value_destroy json_core%json_value_destroy none~destroy->proc~json_value_destroy proc~json_value_destroy->none~destroy proc~destroy_json_data destroy_json_data proc~json_value_destroy->proc~destroy_json_data

Source Code

    subroutine json_file_add(me,p,destroy_original)

    implicit none

    class(json_file),intent(inout)       :: me
    type(json_value),pointer,intent(in)  :: p    !! pointer to the variable to add
    logical(LK),intent(in),optional      :: destroy_original !! if the file currently contains
                                                             !! an associated pointer, it is
                                                             !! destroyed. [Default is True]

    logical(LK) :: destroy   !! if `me%p` is to be destroyed

    if (present(destroy_original)) then
        destroy = destroy_original
    else
        destroy = .true. ! default
    end if

    if (destroy) call me%destroy()

    me%p => p

    end subroutine json_file_add