sp_reference_counter_m.f90 Source File


This file depends on

sourcefile~~sp_reference_counter_m.f90~~EfferentGraph sourcefile~sp_reference_counter_m.f90 sp_reference_counter_m.f90 sourcefile~sp_resource_m.f90 sp_resource_m.f90 sourcefile~sp_reference_counter_m.f90->sourcefile~sp_resource_m.f90

Files dependent on this one

sourcefile~~sp_reference_counter_m.f90~~AfferentGraph sourcefile~sp_reference_counter_m.f90 sp_reference_counter_m.f90 sourcefile~sp_smart_pointer_m.f90 sp_smart_pointer_m.f90 sourcefile~sp_smart_pointer_m.f90->sourcefile~sp_reference_counter_m.f90 sourcefile~sp_reference_counter_s.f90 sp_reference_counter_s.f90 sourcefile~sp_reference_counter_s.f90->sourcefile~sp_reference_counter_m.f90 sourcefile~smart_pointer_m.f90 smart_pointer_m.f90 sourcefile~smart_pointer_m.f90->sourcefile~sp_smart_pointer_m.f90 sourcefile~sp_smart_pointer_s.f90 sp_smart_pointer_s.F90 sourcefile~sp_smart_pointer_s.f90->sourcefile~sp_smart_pointer_m.f90

Contents


Source Code

module sp_reference_counter_m
  use sp_resource_m, only : sp_resource_t
  implicit none

  private
  public :: sp_reference_counter_t

  type sp_reference_counter_t
    private
    integer, pointer :: count_ => null()
    class(sp_resource_t), pointer :: object_ => null()
  contains
    procedure :: reference_count
    procedure, non_overridable :: grab
    procedure, non_overridable :: release
    procedure :: assign_sp_reference_counter
    generic :: assignment(=) => assign_sp_reference_counter
    final :: finalize
  end type

  interface sp_reference_counter_t

    module function construct(object) result(sp_reference_counter)
      implicit none
      class(sp_resource_t), intent(in) :: object
      type(sp_reference_counter_t) sp_reference_counter
     end function

  end interface

  interface

    pure module function reference_count(self) result(counter)
      implicit none
      class(sp_reference_counter_t), intent(in) :: self
      integer counter
    end function

    module subroutine grab(self)
      implicit none
      class(sp_reference_counter_t), intent(inout) :: self
    end subroutine

    module subroutine release(self)
      implicit none
      class (sp_reference_counter_t), intent(inout) :: self
    end subroutine

    module subroutine assign_sp_reference_counter(lhs, rhs)
      implicit none
      class(sp_reference_counter_t), intent(inout) :: lhs
      class(sp_reference_counter_t), intent(in) :: rhs
    end subroutine

  end interface

contains

  subroutine finalize(self)
    type(sp_reference_counter_t), intent(inout) :: self
    if (associated(self%count_)) call self%release
  end subroutine

end module sp_reference_counter_m