parser_obj_AddEntry Subroutine

private pure subroutine parser_obj_AddEntry(this, entry)

Resizes entries array to add a new entry.

Type Bound

parser_obj

Arguments

Type IntentOptional Attributes Name
class(parser_obj), intent(inout) :: this

Parser object

type(entry_obj), intent(in) :: entry

New entrysize


Called by

proc~~parser_obj_addentry~~CalledByGraph proc~parser_obj_addentry parser_obj%parser_obj_AddEntry proc~parser_obj_parseline parser_obj%parser_obj_ParseLine proc~parser_obj_parseline->proc~parser_obj_addentry proc~parser_obj_parsefile parser_obj%parser_obj_ParseFile proc~parser_obj_parsefile->proc~parser_obj_parseline program~main main program~main->proc~parser_obj_parsefile

Source Code

  pure subroutine parser_obj_AddEntry(this,entry)
    !> Resizes entries array to add a new entry.
    implicit none
    class(parser_obj), intent(inout) :: this                                   !! Parser object
    type(entry_obj),   intent(in)    :: entry                                  !! New entrysize
    ! Work variables
    type(entry_obj),  &
         allocatable :: my_entries(:)
    integer          :: size_old

    ! Resize array and add a new entry
    if (.not.allocated(this%entries)) then
      allocate(this%entries(1))
      this%entries(1)=entry
    else
      ! Get old size
      size_old = size(this%entries)

      ! Allocate temporary array
      allocate(my_entries(size_old+1))

      ! Copy values to temporary variable
      my_entries(1:size_old)=this%entries(1:size_old)

      ! Add new entry
      my_entries(size_old+1)=entry

      ! Move the allocation from the
      ! temporary array to the final one
      call move_alloc(my_entries,this%entries)
    end if

    return
  end subroutine parser_obj_AddEntry