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)

Arguments

Type IntentOptional AttributesName
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]


Contents

Source Code


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%core%destroy(me%p)

    me%p => p

    end subroutine json_file_add