vec_string_push_back Subroutine

private pure subroutine vec_string_push_back(self, value, err)

Append one element. ERROR_ALLOC if storage cannot be grown, in which case the vector is unchanged.

Type Bound

vector_string_t

Arguments

Type IntentOptional Attributes Name
class(vector_string_t), intent(inout) :: self
type(string_type), intent(in) :: value
type(error_t), intent(inout), optional :: err

Calls

proc~~vec_string_push_back~~CallsGraph proc~vec_string_push_back vector_string_t%vec_string_push_back proc~error_raise error_raise proc~vec_string_push_back->proc~error_raise proc~vec_string_capacity vector_string_t%vec_string_capacity proc~vec_string_push_back->proc~vec_string_capacity proc~vec_string_grow vec_string_grow proc~vec_string_push_back->proc~vec_string_grow proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~vec_string_grow->proc~error_raise proc~vec_string_grow->proc~vec_string_capacity

Source Code

   pure subroutine vec_string_push_back(self, value, err)
      !! Append one element. `ERROR_ALLOC` if storage cannot be grown, in which
      !! case the vector is unchanged.
      class(vector_string_t), intent(inout) :: self
      type(string_type), intent(in) :: value
      type(error_t), intent(inout), optional :: err

      ! Checked before adding, not after: `n_items + 1` at the maximum wraps
      ! negative, and every downstream test would then read as "plenty of
      ! room" while the append walked off the end of the array.
      if (self%n_items >= PIC_VECTOR_MAX_CAPACITY) then
         call error_raise(err, ERROR_ALLOC, &
                          "vector_string_t: already holds PIC_VECTOR_MAX_CAPACITY elements.")
         return
      end if

      call vec_string_grow(self, self%n_items + 1, err)
      if (self%n_items + 1 > vec_string_capacity(self)) return

      self%n_items = self%n_items + 1
      self%items(self%n_items) = value
   end subroutine vec_string_push_back